Public Member Functions | |
indexAction () | |
addAction () | |
removeAction () | |
clearAction () | |
Protected Attributes | |
$_cookieCheckActions = array('add') |
Definition at line 35 of file CompareController.php.
addAction | ( | ) |
Add item to compare list
Definition at line 68 of file CompareController.php.
00069 { 00070 if ($productId = (int) $this->getRequest()->getParam('product')) { 00071 $product = Mage::getModel('catalog/product') 00072 ->setStoreId(Mage::app()->getStore()->getId()) 00073 ->load($productId); 00074 00075 if ($product->getId()/* && !$product->isSuper()*/) { 00076 Mage::getSingleton('catalog/product_compare_list')->addProduct($product); 00077 Mage::getSingleton('catalog/session')->addSuccess( 00078 $this->__('Product %s successfully added to compare list', $product->getName()) 00079 ); 00080 Mage::dispatchEvent('catalog_product_compare_add_product', array('product'=>$product)); 00081 } 00082 00083 Mage::helper('catalog/product_compare')->calculate(); 00084 } 00085 00086 $this->_redirectReferer(); 00087 }
clearAction | ( | ) |
Definition at line 122 of file CompareController.php.
00123 { 00124 $items = Mage::getResourceModel('catalog/product_compare_item_collection') 00125 //->useProductItem(true) 00126 //->setStoreId(Mage::app()->getStore()->getId()) 00127 ; 00128 00129 if (Mage::getSingleton('customer/session')->isLoggedIn()) { 00130 $items->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()); 00131 } 00132 else { 00133 $items->setVisitorId(Mage::getSingleton('log/visitor')->getId()); 00134 } 00135 00136 $session = Mage::getSingleton('catalog/session'); 00137 /* @var $session Mage_Catalog_Model_Session */ 00138 00139 try { 00140 $items->clear(); 00141 $session->addSuccess($this->__('Compare list successfully cleared')); 00142 Mage::helper('catalog/product_compare')->calculate(); 00143 } 00144 catch (Mage_Core_Exception $e) { 00145 $session->addError($e->getMessage()); 00146 } 00147 catch (Exception $e) { 00148 $session->addException($e, $this->__('There was an error while cleared compare list')); 00149 } 00150 00151 $this->_redirectReferer(); 00152 }
indexAction | ( | ) |
Definition at line 44 of file CompareController.php.
00045 { 00046 $items = $this->getRequest()->getParam('items'); 00047 00048 if ($beforeUrl = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) { 00049 Mage::getSingleton('catalog/session') 00050 ->setBeforeCompareUrl(Mage::helper('core')->urlDecode($beforeUrl)); 00051 } 00052 00053 if ($items) { 00054 $items = explode(',', $items); 00055 $list = Mage::getSingleton('catalog/product_compare_list'); 00056 $list->addProducts($items); 00057 $this->_redirect('*/*/*'); 00058 return; 00059 } 00060 00061 $this->loadLayout(); 00062 $this->renderLayout(); 00063 }
removeAction | ( | ) |
Remove item from compare list
Definition at line 92 of file CompareController.php.
00093 { 00094 if ($productId = (int) $this->getRequest()->getParam('product')) { 00095 $product = Mage::getModel('catalog/product') 00096 ->setStoreId(Mage::app()->getStore()->getId()) 00097 ->load($productId); 00098 00099 if($product->getId()) { 00100 $item = Mage::getModel('catalog/product_compare_item'); 00101 if(Mage::getSingleton('customer/session')->isLoggedIn()) { 00102 $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer()); 00103 } else { 00104 $item->addVisitorId(Mage::getSingleton('log/visitor')->getId()); 00105 } 00106 00107 $item->loadByProduct($product); 00108 00109 if($item->getId()) { 00110 $item->delete(); 00111 Mage::getSingleton('catalog/session')->addSuccess( 00112 $this->__('Product %s successfully removed from compare list', $product->getName()) 00113 ); 00114 Mage::dispatchEvent('catalog_product_compare_remove_product', array('product'=>$item)); 00115 Mage::helper('catalog/product_compare')->calculate(); 00116 } 00117 } 00118 } 00119 $this->_redirectReferer(); 00120 }
$_cookieCheckActions = array('add') [protected] |
Reimplemented from Mage_Core_Controller_Varien_Action.
Definition at line 42 of file CompareController.php.