00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Catalog_Block_Product_List_Upsell extends Mage_Catalog_Block_Product_Abstract
00036 {
00037 protected $_columnCount = 4;
00038
00039 protected $_items;
00040
00041 protected $_itemCollection;
00042
00043 protected $_itemLimits = array();
00044
00045 protected function _prepareData()
00046 {
00047 $product = Mage::registry('product');
00048
00049 $this->_itemCollection = $product->getUpSellProductCollection()
00050 ->addAttributeToSort('position', 'asc')
00051 ->addStoreFilter()
00052 ;
00053 Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
00054 Mage::getSingleton('checkout/session')->getQuoteId()
00055 );
00056 $this->_addProductAttributesAndPrices($this->_itemCollection);
00057
00058
00059 Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
00060
00061 if ($this->getItemLimit('upsell') > 0) {
00062 $this->_itemCollection->setPageSize($this->getItemLimit('upsell'));
00063 }
00064
00065 $this->_itemCollection->load();
00066
00067
00068
00069
00070 Mage::dispatchEvent('catalog_product_upsell', array(
00071 'product' => $product,
00072 'collection' => $this->_itemCollection,
00073 'limit' => $this->getItemLimit()
00074 ));
00075
00076 foreach ($this->_itemCollection as $product) {
00077 $product->setDoNotUseCategoryId(true);
00078 }
00079
00080 return $this;
00081 }
00082
00083 protected function _beforeToHtml()
00084 {
00085 $this->_prepareData();
00086 return parent::_beforeToHtml();
00087 }
00088
00089 public function getItemCollection()
00090 {
00091 return $this->_itemCollection;
00092 }
00093
00094 public function getItems()
00095 {
00096 if (is_null($this->_items)) {
00097 $this->_items = $this->getItemCollection()->getItems();
00098 }
00099 return $this->_items;
00100 }
00101
00102 public function getRowCount()
00103 {
00104 return ceil(count($this->getItemCollection()->getItems())/$this->getColumnCount());
00105 }
00106
00107 public function setColumnCount($columns)
00108 {
00109 if (intval($columns) > 0) {
00110 $this->_columnCount = intval($columns);
00111 }
00112 return $this;
00113 }
00114
00115 public function getColumnCount()
00116 {
00117 return $this->_columnCount;
00118 }
00119
00120 public function resetItemsIterator()
00121 {
00122 $this->getItems();
00123 reset($this->_items);
00124 }
00125
00126 public function getIterableItem()
00127 {
00128 $item = current($this->_items);
00129 next($this->_items);
00130 return $item;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 public function setItemLimit($type, $limit)
00142 {
00143 if (intval($limit) > 0) {
00144 $this->_itemLimits[$type] = intval($limit);
00145 }
00146 return $this;
00147 }
00148
00149 public function getItemLimit($type = '')
00150 {
00151 if ($type == '') {
00152 return $this->_itemLimits;
00153 }
00154 if (isset($this->_itemLimits[$type])) {
00155 return $this->_itemLimits[$type];
00156 }
00157 else {
00158 return 0;
00159 }
00160 }
00161 }