/** * Extend preDispatch * * @return Mage_Core_Controller_Front_Action|void */ public function preDispatch() { parent::preDispatch(); if (!$this->_skipAuthentication && !Mage::getSingleton('customer/session')->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); if (!Mage::getSingleton('customer/session')->getBeforeWishlistUrl()) { Mage::getSingleton('customer/session')->setBeforeWishlistUrl($this->_getRefererUrl()); } Mage::getSingleton('customer/session')->setBeforeWishlistRequest($this->getRequest()->getParams()); } if (!Mage::getStoreConfigFlag('wishlist/general/active')) { $this->norouteAction(); return; } }
/** * Display customer wishlist */ public function indexAction() { /* @var $helper Enterprise_Wishlist_Helper_Data */ $helper = Mage::helper('enterprise_wishlist'); if (!$helper->isMultipleEnabled()) { $wishlistId = $this->getRequest()->getParam('wishlist_id'); if ($wishlistId && $wishlistId != $helper->getDefaultWishlist()->getId()) { $this->_redirectUrl($helper->getListUrl()); } } parent::indexAction(); }
/** * Add wishlist item to shopping cart and remove from wishlist * * If Product has required options - item removed from wishlist and redirect * to product view page with message about needed defined required options */ public function cartAction() { if ($this->getRequest()->getParam('callback')) { $ajaxData = array(); $itemId = (int) $this->getRequest()->getParam('item'); /* @var $item Mage_Wishlist_Model_Item */ $item = Mage::getModel('wishlist/item')->load($itemId); if (!$item->getId()) { $ajaxData['status'] = 0; $ajaxData['url_wislist'] = Mage::getBaseUrl() . 'wishlist/index/configure/id/' . $itemId; $ajaxData['message'] = $this->__('This product no existed in wishlist'); $this->getResponse()->setBody($this->getRequest()->getParam('callback') . '(' . Mage::helper('core')->jsonEncode($ajaxData) . ')'); return; exit; } $wishlist = $this->_getWishlist($item->getWishlistId()); if (!$wishlist) { return $this->_redirect('*/*'); } // Set qty $qty = $this->getRequest()->getParam('qty'); if (is_array($qty)) { if (isset($qty[$itemId])) { $qty = $qty[$itemId]; } else { $qty = 1; } } $qty = $this->_processLocalizedQty($qty); if ($qty) { $item->setQty($qty); } /* @var $session Mage_Wishlist_Model_Session */ $session = Mage::getSingleton('wishlist/session'); $cart = Mage::getSingleton('checkout/cart'); $redirectUrl = Mage::getUrl('*/*'); try { $options = Mage::getModel('wishlist/item_option')->getCollection()->addItemFilter(array($itemId)); $item->setOptions($options->getOptionsByItem($itemId)); $buyRequest = Mage::helper('catalog/product')->addParamsToBuyRequest($this->getRequest()->getParams(), array('current_config' => $item->getBuyRequest())); $item->mergeBuyRequest($buyRequest); $item->addToCart($cart, true); $cart->save()->getQuote()->collectTotals(); $wishlist->save(); Mage::helper('wishlist')->calculate(); if (Mage::helper('checkout/cart')->getShouldRedirectToCart()) { $redirectUrl = Mage::helper('checkout/cart')->getCartUrl(); } else { if ($this->_getRefererUrl()) { $redirectUrl = $this->_getRefererUrl(); } } Mage::helper('wishlist')->calculate(); } catch (Mage_Core_Exception $e) { if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SALABLE) { //$session->addError(Mage::helper('wishlist')->__('This product(s) is currently out of stock')); } else { if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) { // Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); $redirectUrl = Mage::getUrl('*/*/configure/', array('id' => $item->getId())); } else { Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); $redirectUrl = Mage::getUrl('*/*/configure/', array('id' => $item->getId())); } } $ajaxData['status'] = 0; $ajaxData['url_wislist'] = $redirectUrl; $ajaxData['message'] = $this->__('Please chose product options'); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($ajaxData)); return; exit; } catch (Exception $e) { // $session->addException($e, Mage::helper('wishlist')->__('Cannot add item to shopping cart')); $ajaxData['status'] = 0; $ajaxData['url_wislist'] = $redirectUrl; $ajaxData['message'] = Mage::helper('wishlist')->__('Cannot add item to shopping cart'); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($ajaxData)); return; exit; } Mage::helper('wishlist')->calculate(); $this->loadLayout(); $sidebarWishlist = ""; if ($this->getLayout()->getBlock('wishlist_sidebar')) { $sidebarWishlist = $this->getLayout()->getBlock('wishlist_sidebar')->toHtml(); } $toplink = ""; if ($this->getLayout()->getBlock('top.links')) { $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); } $sidebarCart = ""; if ($this->getLayout()->getBlock('cart_sidebar')) { $sidebarCart = $this->getLayout()->getBlock('cart_sidebar')->toHtml(); } $mini_cart = ""; if ($this->getLayout()->getBlock('cart_sidebar_mini')) { $mini_cart = $this->getLayout()->getBlock('cart_sidebar_mini')->toHtml(); } $ajaxData['status'] = 1; $ajaxData['wishlist_sidebar'] = $sidebarWishlist; $ajaxData['top_link'] = $toplink; $ajaxData['type_sidebar'] = 'wishlist'; $ajaxData['sidebar_cart'] = $sidebarCart; $ajaxData['mini_cart'] = $mini_cart; // $product = Mage::getModel('catalog/product')->load($item->getProductId()); // $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) . ')'); } else { parent::cartAction(); } }
/** * Remove item */ public function removeAction() { $response = array(); $id = (int) $this->getRequest()->getParam('product'); if ($id) { $customer = Mage::getSingleton('customer/session')->getCustomer(); $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true); $wishlist = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('wishlist_id', $wishlist->getId())->addFieldToFilter('product_id', $id); $item = $wishlist->getFirstItem(); if (!$item->getId()) { $response['error'] = 'No product available'; return $this->_echoJson($response); } if (!$wishlist) { $response['error'] = 'No wishlist available'; return $this->_echoJson($response); } } else { return parent::removeAction(); } try { $item->delete(); $wishlist->save(); } catch (Mage_Core_Exception $e) { $response['error'] = $this->__('An error occurred while deleting the item from wishlist: %s', $e->getMessage()); return $this->_echoJson($response); } catch (Exception $e) { $response['error'] = $this->__('An error occurred while deleting the item from wishlist.'); return $this->_echoJson($response); } Mage::helper('wishlist')->calculate(); $response['status'] = 'removed'; $response['message'] = $this->__('Product was been removed from your wishlist.'); return $this->_echoJson($response); }
public function updateItemOptionsAction() { if (!Mage::helper('multiplewishlist')->isEnabled()) { return parent::updateItemOptionsAction(); } $session = Mage::getSingleton('customer/session'); $wishlist = $this->_getWishlist(); if (!$wishlist) { $this->_redirect('*/'); return; } $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 { $id = (int) $this->getRequest()->getParam('id'); $buyRequest = new Varien_Object($this->getRequest()->getParams()); /* BELVG START */ $item_old = Mage::getModel('multiplewishlist/item')->checkItemExists($wishlist->getId(), $wishlist->getItem($id)->getId()); /* BELVG END */ $wishlist->updateItem($id, $buyRequest)->save(); Mage::helper('wishlist')->calculate(); Mage::dispatchEvent('wishlist_update_item', array('wishlist' => $wishlist, 'product' => $product, 'item' => $wishlist->getItem($id))); Mage::helper('wishlist')->calculate(); /* BELVG START */ if ($item_old) { $tab = Mage::getModel('multiplewishlist/tab')->checkTabExistsById($wishlist->getId(), $item_old->getWishlistTabId()); if ($tab->getId()) { Mage::getModel('core/session')->setWishlistActiveTabId($tab->getId()); $item = Mage::getResourceModel('wishlist/item_collection')->addWishlistFilter($wishlist)->addStoreFilter($wishlist->getSharedStoreIds())->setVisibilityFilter()->addFieldToFilter('product_id', $product->getId())->getFirstItem(); Mage::getModel('multiplewishlist/item')->getItem($wishlist, $tab, $item); } if ($item_old) { $item_old->delete(); } } /* BELVG END */ $message = $this->__('%1$s has been updated in your wishlist.', $product->getName()); $session->addSuccess($message); } catch (Mage_Core_Exception $e) { $session->addError($e->getMessage()); } catch (Exception $e) { $session->addError($this->__('An error occurred while updating wishlist.')); Mage::logException($e); } $this->_redirect('*/*'); }
/** * Add wishlist item to shopping cart and remove from wishlist * * If Product has required options - item removed from wishlist and redirect * to product view page with message about needed defined required options */ public function cartAction() { $params = $this->getRequest()->getParams(); if (isset($params['isAjax']) && $params['isAjax'] == 1) { $response = array(); if (!$this->_validateFormKey()) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Some fields in form are required.'); } $itemId = (int) $this->getRequest()->getParam('item'); /* @var $item Mage_Wishlist_Model_Item */ $item = Mage::getModel('wishlist/item')->load($itemId); if (!$item->getId()) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Unable to find Product ID'); } $wishlist = $this->_getWishlist($item->getWishlistId()); if (!$wishlist) { $response['status'] = 'ERROR'; $response['message'] = $this->__('Empty wishlist'); } // Set qty $qty = $this->getRequest()->getParam('qty'); if (is_array($qty)) { if (isset($qty[$itemId])) { $qty = $qty[$itemId]; } else { $qty = 1; } } $qty = $this->_processLocalizedQty($qty); if ($qty) { $item->setQty($qty); } /* @var $session Mage_Wishlist_Model_Session */ $session = Mage::getSingleton('wishlist/session'); $cart = Mage::getSingleton('checkout/cart'); $redirectUrl = Mage::getUrl('*/*'); try { $options = Mage::getModel('wishlist/item_option')->getCollection()->addItemFilter(array($itemId)); $item->setOptions($options->getOptionsByItem($itemId)); $buyRequest = Mage::helper('catalog/product')->addParamsToBuyRequest($this->getRequest()->getParams(), array('current_config' => $item->getBuyRequest())); $item->mergeBuyRequest($buyRequest); if ($item->addToCart($cart, true)) { $cart->save()->getQuote()->collectTotals(); } $wishlist->save(); Mage::helper('wishlist')->calculate(); if (Mage::helper('checkout/cart')->getShouldRedirectToCart()) { $redirectUrl = Mage::helper('checkout/cart')->getCartUrl(); } else { if ($this->_getRefererUrl()) { $redirectUrl = $this->_getRefererUrl(); } } Mage::helper('wishlist')->calculate(); $product = $item->getProduct(); $message = Mage::app()->getLayout()->createBlock("page/html")->assign("product", $product)->setTemplate('venustheme/tempcp/cart_success.phtml')->toHtml(); $response['status'] = 'SUCCESS'; $response['message'] = $message; } catch (Mage_Core_Exception $e) { if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SALABLE) { $response['status'] = 'ERROR'; $response['message'] = $this->__('This product(s) is currently out of stock'); } else { if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) { Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); $redirectUrl = Mage::getUrl('*/*/configure/', array('id' => $item->getId())); $response['status'] = 'ERROR'; $response['message'] = $e->getMessage(); } else { Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); $redirectUrl = Mage::getUrl('*/*/configure/', array('id' => $item->getId())); $response['status'] = 'ERROR'; $response['message'] = $e->getMessage(); } } } catch (Exception $e) { Mage::logException($e); $session->addException($e, $this->__('Cannot add item to shopping cart')); $response['status'] = 'ERROR'; $response['message'] = $this->__('Cannot add item to shopping cart'); } Mage::helper('wishlist')->calculate(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } else { return parent::cartAction(); } }