Mage_Wishlist_Model_Observer Class Reference

Inheritance diagram for Mage_Wishlist_Model_Observer:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 processCartUpdateBefore ($observer)
 processAddToCart ($observer)

Protected Member Functions

 _getWishlist ($customerId)


Detailed Description

Shopping cart operation observer

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Observer.php.


Member Function Documentation

_getWishlist ( customerId  )  [protected]

Get customer wishlist model instance

Parameters:
int $customerId
Returns:
Mage_Wishlist_Model_Wishlist || false

Definition at line 40 of file Observer.php.

00041     {
00042         if (!$customerId) {
00043             return false;
00044         }
00045         return Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
00046     }

processAddToCart ( observer  ) 

Definition at line 87 of file Observer.php.

00088     {
00089         $request = $observer->getRequest();
00090         $sharedWishlist = Mage::getSingleton('checkout/session')->getSharedWishlist();
00091         $messages = Mage::getSingleton('checkout/session')->getWishlistPendingMessages();
00092         $urls = Mage::getSingleton('checkout/session')->getWishlistPendingUrls();
00093         $wishlistIds = Mage::getSingleton('checkout/session')->getWishlistIds();
00094         $singleWishlistId = Mage::getSingleton('checkout/session')->getSingleWishlistId();
00095 
00096         if ($singleWishlistId) {
00097             $wishlistIds = array($singleWishlistId);
00098         }
00099 
00100         if (count($wishlistIds) && $request->getParam('wishlist_next')){
00101             $wishlistId = array_shift($wishlistIds);
00102 
00103             if (Mage::getSingleton('customer/session')->isLoggedIn()) {
00104                 $wishlist = Mage::getModel('wishlist/wishlist')
00105                         ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer(), true);
00106             } else if ($sharedWishlist) {
00107                 $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($sharedWishlist);
00108             } else {
00109                 return;
00110             }
00111 
00112 
00113             $wishlist->getItemCollection()->load();
00114 
00115             foreach($wishlist->getItemCollection() as $wishlistItem){
00116                 if ($wishlistItem->getId() == $wishlistId)
00117                     $wishlistItem->delete();
00118             }
00119             Mage::getSingleton('checkout/session')->setWishlistIds($wishlistIds);
00120             Mage::getSingleton('checkout/session')->setSingleWishlistId(null);
00121         }
00122 
00123         if ($request->getParam('wishlist_next') && count($urls)) {
00124             $url = array_shift($urls);
00125             $message = array_shift($messages);
00126 
00127             Mage::getSingleton('checkout/session')->setWishlistPendingUrls($urls);
00128             Mage::getSingleton('checkout/session')->setWishlistPendingMessages($messages);
00129 
00130             Mage::getSingleton('checkout/session')->addError($message);
00131 
00132             $observer->getResponse()->setRedirect($url);
00133             Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
00134         }
00135     }

processCartUpdateBefore ( observer  ) 

Check move quote item to wishlist request

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_Wishlist_Model_Observer

Collect product ids marked for move to wishlist

Definition at line 54 of file Observer.php.

00055     {
00056         $cart = $observer->getEvent()->getCart();
00057         $data = $observer->getEvent()->getInfo();
00058         $productIds = array();
00059 
00060         $wishlist = $this->_getWishlist($cart->getQuote()->getCustomerId());
00061         if (!$wishlist) {
00062             return $this;
00063         }
00064 
00065         /**
00066          * Collect product ids marked for move to wishlist
00067          */
00068         foreach ($data as $itemId => $itemInfo) {
00069             if (!empty($itemInfo['wishlist'])) {
00070                 if ($item = $cart->getQuote()->getItemById($itemId)) {
00071                     $productId = $item->getProductId();
00072                     $productIds[] = $productId;
00073                     $cart->getQuote()->removeItem($itemId);
00074                 }
00075             }
00076         }
00077 
00078         if (!empty($productIds)) {
00079             foreach ($productIds as $productId) {
00080                 $wishlist->addNewItem($productId);
00081             }
00082             $wishlist->save();
00083         }
00084         return $this;
00085     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:57 2009 for Magento by  doxygen 1.5.8