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:  * Shopping cart operation observer
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Wishlist_Model_Observer extends Mage_Core_Model_Abstract
 33: {
 34:     /**
 35:      * Get customer wishlist model instance
 36:      *
 37:      * @param   int $customerId
 38:      * @return  Mage_Wishlist_Model_Wishlist || false
 39:      */
 40:     protected function _getWishlist($customerId)
 41:     {
 42:         if (!$customerId) {
 43:             return false;
 44:         }
 45:         return Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
 46:     }
 47: 
 48:     /**
 49:      * Check move quote item to wishlist request
 50:      *
 51:      * @param   Varien_Event_Observer $observer
 52:      * @return  Mage_Wishlist_Model_Observer
 53:      */
 54:     public function processCartUpdateBefore($observer)
 55:     {
 56:         $cart = $observer->getEvent()->getCart();
 57:         $data = $observer->getEvent()->getInfo();
 58:         $productIds = array();
 59: 
 60:         $wishlist = $this->_getWishlist($cart->getQuote()->getCustomerId());
 61:         if (!$wishlist) {
 62:             return $this;
 63:         }
 64: 
 65:         /**
 66:          * Collect product ids marked for move to wishlist
 67:          */
 68:         foreach ($data as $itemId => $itemInfo) {
 69:             if (!empty($itemInfo['wishlist'])) {
 70:                 if ($item = $cart->getQuote()->getItemById($itemId)) {
 71:                     $productId  = $item->getProductId();
 72:                     $buyRequest = $item->getBuyRequest();
 73: 
 74:                     if (isset($itemInfo['qty']) && is_numeric($itemInfo['qty'])) {
 75:                         $buyRequest->setQty($itemInfo['qty']);
 76:                     }
 77:                     $wishlist->addNewItem($productId, $buyRequest);
 78: 
 79:                     $productIds[] = $productId;
 80:                     $cart->getQuote()->removeItem($itemId);
 81:                 }
 82:             }
 83:         }
 84: 
 85:         if (!empty($productIds)) {
 86:             $wishlist->save();
 87:             Mage::helper('wishlist')->calculate();
 88:         }
 89:         return $this;
 90:     }
 91: 
 92:     public function processAddToCart($observer)
 93:     {
 94:         $request = $observer->getEvent()->getRequest();
 95:         $sharedWishlist = Mage::getSingleton('checkout/session')->getSharedWishlist();
 96:         $messages = Mage::getSingleton('checkout/session')->getWishlistPendingMessages();
 97:         $urls = Mage::getSingleton('checkout/session')->getWishlistPendingUrls();
 98:         $wishlistIds = Mage::getSingleton('checkout/session')->getWishlistIds();
 99:         $singleWishlistId = Mage::getSingleton('checkout/session')->getSingleWishlistId();
100: 
101:         if ($singleWishlistId) {
102:             $wishlistIds = array($singleWishlistId);
103:         }
104: 
105:         if (count($wishlistIds) && $request->getParam('wishlist_next')){
106:             $wishlistId = array_shift($wishlistIds);
107: 
108:             if (Mage::getSingleton('customer/session')->isLoggedIn()) {
109:                 $wishlist = Mage::getModel('wishlist/wishlist')
110:                         ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer(), true);
111:             } else if ($sharedWishlist) {
112:                 $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($sharedWishlist);
113:             } else {
114:                 return;
115:             }
116: 
117: 
118:             $wishlist->getItemCollection()->load();
119: 
120:             foreach($wishlist->getItemCollection() as $wishlistItem){
121:                 if ($wishlistItem->getId() == $wishlistId)
122:                     $wishlistItem->delete();
123:             }
124:             Mage::getSingleton('checkout/session')->setWishlistIds($wishlistIds);
125:             Mage::getSingleton('checkout/session')->setSingleWishlistId(null);
126:         }
127: 
128:         if ($request->getParam('wishlist_next') && count($urls)) {
129:             $url = array_shift($urls);
130:             $message = array_shift($messages);
131: 
132:             Mage::getSingleton('checkout/session')->setWishlistPendingUrls($urls);
133:             Mage::getSingleton('checkout/session')->setWishlistPendingMessages($messages);
134: 
135:             Mage::getSingleton('checkout/session')->addError($message);
136: 
137:             $observer->getEvent()->getResponse()->setRedirect($url);
138:             Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
139:         }
140:     }
141: 
142:     /**
143:      * Customer login processing
144:      *
145:      * @param Varien_Event_Observer $observer
146:      * @return Mage_Wishlist_Model_Observer
147:      */
148:     public function customerLogin(Varien_Event_Observer $observer)
149:     {
150:         Mage::helper('wishlist')->calculate();
151: 
152:         return $this;
153:     }
154: 
155:     /**
156:      * Customer logout processing
157:      *
158:      * @param Varien_Event_Observer $observer
159:      * @return Mage_Wishlist_Model_Observer
160:      */
161:     public function customerLogout(Varien_Event_Observer $observer)
162:     {
163:         Mage::getSingleton('customer/session')->setWishlistItemCount(0);
164: 
165:         return $this;
166:     }
167: 
168: }
169: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0