public function removeAction() { if ($this->_isEnabled()) { 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(); } } } $message = $this->__('The product %s has been removed from comparison list.', $product->getName()); $this->setResponse($message); return; } else { parent::removeAction(); } }
/** * 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(); } }