Mage_Checkout_Block_Cart_Crosssell Class Reference

Inheritance diagram for Mage_Checkout_Block_Cart_Crosssell:

Mage_Catalog_Block_Product_Abstract Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 getItems ()
 getItemCount ()
 getQuote ()

Protected Member Functions

 _getCartProductIds ()
 _getLastAddedProductId ()
 _getCollection ()

Protected Attributes

 $_maxItemCount = 4


Detailed Description

Definition at line 34 of file Crosssell.php.


Member Function Documentation

_getCartProductIds (  )  [protected]

Get ids of products that are in cart

Returns:
array

Definition at line 102 of file Crosssell.php.

00103     {
00104         $ids = $this->getData('_cart_product_ids');
00105         if (is_null($ids)) {
00106             $ids = array();
00107             foreach ($this->getQuote()->getAllItems() as $item) {
00108                 if ($product = $item->getProduct()) {
00109                     $ids[] = $product->getId();
00110                 }
00111             }
00112             $this->setData('_cart_product_ids', $ids);
00113         }
00114         return $ids;
00115     }

_getCollection (  )  [protected]

Get crosssell products collection

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection

Definition at line 142 of file Crosssell.php.

00143     {
00144         $collection = Mage::getModel('catalog/product_link')->useCrossSellLinks()
00145             ->getProductCollection()
00146             ->setStoreId(Mage::app()->getStore()->getId())
00147             ->addStoreFilter()
00148             ->setPageSize($this->_maxItemCount);
00149         $this->_addProductAttributesAndPrices($collection);
00150 
00151         Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
00152         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
00153         Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
00154 
00155         return $collection;
00156     }

_getLastAddedProductId (  )  [protected]

Get last product ID that was added to cart and remove this information from session

Returns:
int

Definition at line 122 of file Crosssell.php.

00123     {
00124         return Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
00125     }

getItemCount (  ) 

Count items

Returns:
int

Definition at line 92 of file Crosssell.php.

00093     {
00094         return count($this->getItems());
00095     }

getItems (  ) 

Get crosssell items

Returns:
array

Definition at line 48 of file Crosssell.php.

00049     {
00050         $items = $this->getData('items');
00051         if (is_null($items)) {
00052             $items = array();
00053             if ($ninProductIds = $this->_getCartProductIds()) {
00054                 if ($lastAdded = (int) $this->_getLastAddedProductId()) {
00055                     $collection = $this->_getCollection()
00056                         ->addProductFilter($lastAdded);
00057                     if (!empty($ninProductIds)) {
00058                         $collection->addExcludeProductFilter($ninProductIds);
00059                     }
00060                     $collection->load();
00061 
00062                     foreach ($collection as $item) {
00063                         $ninProductIds[] = $item->getId();
00064                         $items[] = $item;
00065                     }
00066                 }
00067 
00068                 if (count($items)<$this->_maxItemCount) {
00069                     $collection = $this->_getCollection()
00070                         ->addProductFilter($this->_getCartProductIds())
00071                         ->addExcludeProductFilter($ninProductIds)
00072                         ->setPageSize($this->_maxItemCount-count($items))
00073                         ->setGroupBy()
00074                         ->setRandomOrder()
00075                         ->load();
00076                     foreach ($collection as $item) {
00077                         $items[] = $item;
00078                     }
00079                 }
00080             }
00081 
00082             $this->setData('items', $items);
00083         }
00084         return $items;
00085     }

getQuote (  ) 

Get quote instance

Returns:
Mage_Sales_Model_Quote

Definition at line 132 of file Crosssell.php.

00133     {
00134         return Mage::getSingleton('checkout/session')->getQuote();
00135     }


Member Data Documentation

$_maxItemCount = 4 [protected]

Definition at line 41 of file Crosssell.php.


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

Generated on Sat Jul 4 17:23:49 2009 for Magento by  doxygen 1.5.8