Example #1
0
 /**
  * override Remove item from compare list
  */
 public function removeAction()
 {
     if ($this->getRequest()->getParam('callback')) {
         $ajaxData = array();
         if ($productId = (int) $this->getRequest()->getParam('product')) {
             $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId);
             if ($product->getId()) {
                 /** @var $item Mage_Catalog_Model_Product_Compare_Item */
                 $item = Mage::getModel('catalog/product_compare_item');
                 if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                     $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer());
                 } elseif ($this->_customerId) {
                     $item->addCustomerData(Mage::getModel('customer/customer')->load($this->_customerId));
                 } else {
                     $item->addVisitorId(Mage::getSingleton('log/visitor')->getId());
                 }
                 $item->loadByProduct($product);
                 if ($item->getId()) {
                     $item->delete();
                     Mage::dispatchEvent('catalog_product_compare_remove_product', array('product' => $item));
                     Mage::helper('catalog/product_compare')->calculate();
                 }
             }
         }
         $this->loadLayout();
         $sidebarCompare = "";
         if ($this->getLayout()->getBlock('catalog.compare.sidebar')) {
             $sidebarCompare = $this->getLayout()->getBlock('catalog.compare.sidebar')->toHtml();
         }
         $ajaxData['status'] = 1;
         $ajaxData['sidebar_compare'] = $sidebarCompare;
         $ajaxData['type_sidebar'] = 'compare';
         $this->getResponse()->setBody($this->getRequest()->getParam('callback') . '(' . Mage::helper('core')->jsonEncode($ajaxData) . ')');
         return;
     } else {
         parent::removeAction();
     }
 }
 public function preDispatch()
 {
     parent::preDispatch();
     $this->getRequest()->setRouteName('catalog');
 }
 protected function _redirectReferer($defaultUrl = null)
 {
     if ($this->getRequest()->getModuleName() == "advancedcompare" & in_array($this->getRequest()->getActionName(), array("silentadd", "silentremove", "silentclear"))) {
         $this->redrawsidebarAction();
     } else {
         parent::_redirectReferer($defaultUrl);
     }
 }
 public function clearAction()
 {
     if ($this->_isEnabled()) {
         $message = '';
         $items = Mage::getResourceModel('catalog/product_compare_item_collection');
         if (Mage::getSingleton('customer/session')->isLoggedIn()) {
             $items->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
         } elseif ($this->_customerId) {
             $items->setCustomerId($this->_customerId);
         } else {
             $items->setVisitorId(Mage::getSingleton('log/visitor')->getId());
         }
         try {
             $items->clear();
             $message = 'The comparison list was cleared.';
             Mage::helper('catalog/product_compare')->calculate();
         } catch (Mage_Core_Exception $e) {
             $message = $e->getMessage();
         } catch (Exception $e) {
             $message = $this->__('An error occurred while clearing comparison list.');
         }
         $this->setResponse($message);
     } else {
         parent::clearAction();
     }
 }