/** * Add item to wishlist * Create new wishlist if wishlist params (name, visibility) are provided */ public function addAction() { $customerId = $this->_getSession()->getCustomerId(); $name = $this->getRequest()->getParam('name'); $visibility = $this->getRequest()->getParam('visibility', 0) === 'on' ? 1 : 0; if ($name !== null) { try { $wishlist = $this->_editWishlist($customerId, $name, $visibility); $this->_getSession()->addSuccess(Mage::helper('enterprise_wishlist')->__('Wishlist "%s" was successfully saved', Mage::helper('core')->escapeHtml($wishlist->getName()))); $this->getRequest()->setParam('wishlist_id', $wishlist->getId()); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addException($e, Mage::helper('enterprise_wishlist')->__('Error happened during wishlist creation')); } } parent::addAction(); }
/** * ovveride Adding new item */ public function addAction() { //Mage::log(Mage::getSingleton('customer/session')->isLoggedIn(), null,'wishlist.log'); if ($this->getRequest()->getParam('callback')) { $wishlist = $this->_getWishlist(); if (!$wishlist) { return $this->norouteAction(); } $session = Mage::getSingleton('customer/session'); $productId = (int) $this->getRequest()->getParam('product'); if (!$productId) { $this->_redirect('*/'); return; } $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { $session->addError($this->__('Cannot specify product.')); $this->_redirect('*/'); return; } try { $requestParams = $this->getRequest()->getParams(); if ($session->getBeforeWishlistRequest()) { $requestParams = $session->getBeforeWishlistRequest(); $session->unsBeforeWishlistRequest(); } $buyRequest = new Varien_Object($requestParams); $result = $wishlist->addNewItem($product, $buyRequest); if (is_string($result)) { Mage::throwException($result); } $wishlist->save(); Mage::dispatchEvent('wishlist_add_product', array('wishlist' => $wishlist, 'product' => $product, 'item' => $result)); $referer = $session->getBeforeWishlistUrl(); if ($referer) { $session->setBeforeWishlistUrl(null); } else { $referer = $this->_getRefererUrl(); } /** * Set referer to avoid referring to the compare popup window */ $session->setAddActionReferer($referer); Mage::helper('wishlist')->calculate(); $message = $this->__('%1$s has been added to your wishlist. Click <a href="%2$s">here</a> to continue shopping.', $product->getName(), Mage::helper('core')->escapeUrl($referer)); //$session->addSuccess($message); } catch (Mage_Core_Exception $e) { $session->addError($this->__('An error occurred while adding item to wishlist: %s', $e->getMessage())); } catch (Exception $e) { $session->addError($this->__('An error occurred while adding item to wishlist.')); } $this->loadLayout(); $sidebarWishlist = ""; if ($this->getLayout()->getBlock('wishlist_sidebar')) { $sidebarWishlist = $this->getLayout()->getBlock('wishlist_sidebar')->toHtml(); } if ($this->getLayout()->getBlock('top.links')) { $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); } $ajaxData['status'] = 1; $ajaxData['wishlist_sidebar'] = $sidebarWishlist; $ajaxData['type_sidebar'] = 'wishlist'; $ajaxData['top_link'] = $toplink; if (Mage::getStoreConfig('ajaxcartsuper/ajaxcartsuper_config/show_confirm')) { $pimage = Mage::helper('catalog/image')->init($product, 'small_image')->resize(55); $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(); } }