Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Wishlist_Block_Abstract
  • Mage_Wishlist_Block_Customer_Sharing
  • Mage_Wishlist_Block_Customer_Sidebar
  • Mage_Wishlist_Block_Customer_Wishlist
  • Mage_Wishlist_Block_Customer_Wishlist_Button
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Cart
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Comment
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Image
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Column_Remove
  • Mage_Wishlist_Block_Customer_Wishlist_Item_Options
  • Mage_Wishlist_Block_Customer_Wishlist_Items
  • Mage_Wishlist_Block_Item_Configure
  • Mage_Wishlist_Block_Links
  • Mage_Wishlist_Block_Render_Item_Price
  • Mage_Wishlist_Block_Share_Email_Items
  • Mage_Wishlist_Block_Share_Email_Rss
  • Mage_Wishlist_Block_Share_Wishlist
  • Mage_Wishlist_Controller_Abstract
  • Mage_Wishlist_Helper_Data
  • Mage_Wishlist_IndexController
  • Mage_Wishlist_Model_Config
  • Mage_Wishlist_Model_Config_Source_Summary
  • Mage_Wishlist_Model_Item
  • Mage_Wishlist_Model_Item_Option
  • Mage_Wishlist_Model_Mysql4_Item
  • Mage_Wishlist_Model_Mysql4_Item_Collection
  • Mage_Wishlist_Model_Mysql4_Item_Option
  • Mage_Wishlist_Model_Mysql4_Item_Option_Collection
  • Mage_Wishlist_Model_Mysql4_Product_Collection
  • Mage_Wishlist_Model_Mysql4_Wishlist
  • Mage_Wishlist_Model_Mysql4_Wishlist_Collection
  • Mage_Wishlist_Model_Observer
  • Mage_Wishlist_Model_Resource_Item
  • Mage_Wishlist_Model_Resource_Item_Collection
  • Mage_Wishlist_Model_Resource_Item_Option
  • Mage_Wishlist_Model_Resource_Item_Option_Collection
  • Mage_Wishlist_Model_Resource_Wishlist
  • Mage_Wishlist_Model_Resource_Wishlist_Collection
  • Mage_Wishlist_Model_Session
  • Mage_Wishlist_Model_Wishlist
  • Mage_Wishlist_SharedController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Wishlist
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Wishlist Abstract Front Controller Action
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Wishlist
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: abstract class Mage_Wishlist_Controller_Abstract extends Mage_Core_Controller_Front_Action
 36: {
 37:     /**
 38:      * Filter to convert localized values to internal ones
 39:      * @var Zend_Filter_LocalizedToNormalized
 40:      */
 41:     protected $_localFilter = null;
 42: 
 43:     /**
 44:      * Processes localized qty (entered by user at frontend) into internal php format
 45:      *
 46:      * @param string $qty
 47:      * @return float|int|null
 48:      */
 49:     protected function _processLocalizedQty($qty)
 50:     {
 51:         if (!$this->_localFilter) {
 52:             $this->_localFilter = new Zend_Filter_LocalizedToNormalized(
 53:                 array('locale' => Mage::app()->getLocale()->getLocaleCode())
 54:             );
 55:         }
 56:         $qty = $this->_localFilter->filter((float)$qty);
 57:         if ($qty < 0) {
 58:             $qty = null;
 59:         }
 60:         return $qty;
 61:     }
 62: 
 63:     /**
 64:      * Retrieve current wishlist instance
 65:      *
 66:      * @return Mage_Wishlist_Model_Wishlist|false
 67:      */
 68:     abstract protected function _getWishlist();
 69: 
 70:     /**
 71:      * Add all items from wishlist to shopping cart
 72:      *
 73:      */
 74:     public function allcartAction()
 75:     {
 76:         $wishlist   = $this->_getWishlist();
 77:         if (!$wishlist) {
 78:             $this->_forward('noRoute');
 79:             return ;
 80:         }
 81:         $isOwner    = $wishlist->isOwner(Mage::getSingleton('customer/session')->getCustomerId());
 82: 
 83:         $messages   = array();
 84:         $addedItems = array();
 85:         $notSalable = array();
 86:         $hasOptions = array();
 87: 
 88:         $cart       = Mage::getSingleton('checkout/cart');
 89:         $collection = $wishlist->getItemCollection()
 90:                 ->setVisibilityFilter();
 91: 
 92:         $qtys = $this->getRequest()->getParam('qty');
 93:         foreach ($collection as $item) {
 94:             /** @var Mage_Wishlist_Model_Item */
 95:             try {
 96:                 $disableAddToCart = $item->getProduct()->getDisableAddToCart();
 97:                 $item->unsProduct();
 98: 
 99:                 // Set qty
100:                 if (isset($qtys[$item->getId()])) {
101:                     $qty = $this->_processLocalizedQty($qtys[$item->getId()]);
102:                     if ($qty) {
103:                         $item->setQty($qty);
104:                     }
105:                 }
106:                 $item->getProduct()->setDisableAddToCart($disableAddToCart);
107:                 // Add to cart
108:                 if ($item->addToCart($cart, $isOwner)) {
109:                     $addedItems[] = $item->getProduct();
110:                 }
111: 
112:             } catch (Mage_Core_Exception $e) {
113:                 if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SALABLE) {
114:                     $notSalable[] = $item;
115:                 } else if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
116:                     $hasOptions[] = $item;
117:                 } else {
118:                     $messages[] = $this->__('%s for "%s".', trim($e->getMessage(), '.'), $item->getProduct()->getName());
119:                 }
120:             } catch (Exception $e) {
121:                 Mage::logException($e);
122:                 $messages[] = Mage::helper('wishlist')->__('Cannot add the item to shopping cart.');
123:             }
124:         }
125: 
126:         if ($isOwner) {
127:             $indexUrl = Mage::helper('wishlist')->getListUrl($wishlist->getId());
128:         } else {
129:             $indexUrl = Mage::getUrl('wishlist/shared', array('code' => $wishlist->getSharingCode()));
130:         }
131:         if (Mage::helper('checkout/cart')->getShouldRedirectToCart()) {
132:             $redirectUrl = Mage::helper('checkout/cart')->getCartUrl();
133:         } else if ($this->_getRefererUrl()) {
134:             $redirectUrl = $this->_getRefererUrl();
135:         } else {
136:             $redirectUrl = $indexUrl;
137:         }
138: 
139:         if ($notSalable) {
140:             $products = array();
141:             foreach ($notSalable as $item) {
142:                 $products[] = '"' . $item->getProduct()->getName() . '"';
143:             }
144:             $messages[] = Mage::helper('wishlist')->__('Unable to add the following product(s) to shopping cart: %s.', join(', ', $products));
145:         }
146: 
147:         if ($hasOptions) {
148:             $products = array();
149:             foreach ($hasOptions as $item) {
150:                 $products[] = '"' . $item->getProduct()->getName() . '"';
151:             }
152:             $messages[] = Mage::helper('wishlist')->__('Product(s) %s have required options. Each of them can be added to cart separately only.', join(', ', $products));
153:         }
154: 
155:         if ($messages) {
156:             $isMessageSole = (count($messages) == 1);
157:             if ($isMessageSole && count($hasOptions) == 1) {
158:                 $item = $hasOptions[0];
159:                 if ($isOwner) {
160:                     $item->delete();
161:                 }
162:                 $redirectUrl = $item->getProductUrl();
163:             } else {
164:                 $wishlistSession = Mage::getSingleton('wishlist/session');
165:                 foreach ($messages as $message) {
166:                     $wishlistSession->addError($message);
167:                 }
168:                 $redirectUrl = $indexUrl;
169:             }
170:         }
171: 
172:         if ($addedItems) {
173:             // save wishlist model for setting date of last update
174:             try {
175:                 $wishlist->save();
176:             }
177:             catch (Exception $e) {
178:                 Mage::getSingleton('wishlist/session')->addError($this->__('Cannot update wishlist'));
179:                 $redirectUrl = $indexUrl;
180:             }
181: 
182:             $products = array();
183:             foreach ($addedItems as $product) {
184:                 $products[] = '"' . $product->getName() . '"';
185:             }
186: 
187:             Mage::getSingleton('checkout/session')->addSuccess(
188:                 Mage::helper('wishlist')->__('%d product(s) have been added to shopping cart: %s.', count($addedItems), join(', ', $products))
189:             );
190:         }
191:         // save cart and collect totals
192:         $cart->save()->getQuote()->collectTotals();
193: 
194:         Mage::helper('wishlist')->calculate();
195: 
196:         $this->_redirectUrl($redirectUrl);
197:     }
198: }
199: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0