Public Member Functions | |
getItems () | |
getItemCount () | |
getQuote () | |
Protected Member Functions | |
_getCartProductIds () | |
_getLastAddedProductId () | |
_getCollection () | |
Protected Attributes | |
$_maxItemCount = 4 |
Definition at line 34 of file Crosssell.php.
_getCartProductIds | ( | ) | [protected] |
Get ids of products that are in cart
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
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
Definition at line 122 of file Crosssell.php.
00123 { 00124 return Mage::getSingleton('checkout/session')->getLastAddedProductId(true); 00125 }
getItemCount | ( | ) |
Count items
Definition at line 92 of file Crosssell.php.
00093 { 00094 return count($this->getItems()); 00095 }
getItems | ( | ) |
Get crosssell items
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
Definition at line 132 of file Crosssell.php.
00133 { 00134 return Mage::getSingleton('checkout/session')->getQuote(); 00135 }
$_maxItemCount = 4 [protected] |
Definition at line 41 of file Crosssell.php.