public function addAction() { try { $formKey = $this->getRequest()->getParam('form_key', null); if (Mage::getSingleton('core/session')->getFormKey() != $formKey) { $errorMessage = $this->__('Please enable cookies in your web browser to continue.'); $this->getResponse()->setBody(Zend_Json::encode(array('cookieError' => $errorMessage))); return; } if (Mage::getStoreConfig('advancedcompare/limits/enable_compare_limits')) { $itemCollection = Mage::getResourceModel('catalog/product_compare_item_collection')->useProductItem(true)->setStoreId(Mage::app()->getStore()->getId()); if (Mage::getSingleton('customer/session')->isLoggedIn()) { $itemCollection->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()); } elseif ($this->_customerId) { $itemCollection->setCustomerId($this->_customerId); } else { $itemCollection->setVisitorId(Mage::getSingleton('log/visitor')->getId()); } Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($itemCollection); if (count($itemCollection) >= Mage::getStoreConfig('advancedcompare/limits/compare_limits')) { $this->_limitMessage = Mage::helper("advancedcompare")->__("You have reached a maximal amount (%s) of products to compare simultaneously", Mage::getStoreConfig('advancedcompare/limits/compare_limits')); return $this->_redirectReferer(); } } return parent::addAction(); } catch (Exception $e) { $this->getResponse()->setBody(Zend_Json::encode(array('unknown_error' => $e->getMessage()))); return; } }
/** * override Add product to copare list action */ public function addAction() { if ($this->getRequest()->getParam('callback')) { $ajaxData = array(); $productId = (int) $this->getRequest()->getParam('product'); if ($productId && (Mage::getSingleton('log/visitor')->getId() || Mage::getSingleton('customer/session')->isLoggedIn())) { $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId); if ($product->getId()) { Mage::getSingleton('catalog/product_compare_list')->addProduct($product); Mage::dispatchEvent('catalog_product_compare_add_product', array('product' => $product)); } 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'; if (Mage::getStoreConfig('ajaxcartsuper/ajaxcartsuper_config/show_confirm')) { $pimage = Mage::helper('catalog/image')->init($product, 'small_image')->resize(80); $ajaxData['product_info'] = Mage::helper('ajaxcartsuper/data')->productHtml($product->getName(), $product->getProductUrl(), $pimage); } $this->getResponse()->setBody($this->getRequest()->getParam('callback') . '(' . Mage::helper('core')->jsonEncode($ajaxData) . ')'); return; } else { parent::addAction(); } }
public function addAction() { if ($this->_isEnabled()) { if (!$this->_validateFormKey()) { $this->_redirectReferer(); return; } $productId = (int) $this->getRequest()->getParam('product'); if ($productId && (Mage::getSingleton('log/visitor')->getId() || Mage::getSingleton('customer/session')->isLoggedIn())) { $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId); if ($product->getId()) { Mage::getSingleton('catalog/product_compare_list')->addProduct($product); Mage::dispatchEvent('catalog_product_compare_add_product', array('product' => $product)); } Mage::helper('catalog/product_compare')->calculate(); } $message = $this->__('The product %s has been added to comparison list.', $product->getName()); $this->setResponse($message); return; } else { parent::addAction(); } }