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_Bundle_Block_Catalog_Product_List_Partof extends Mage_Catalog_Block_Product_Abstract
00036 {
00037 protected $_columnCount = 4;
00038 protected $_items;
00039 protected $_itemCollection;
00040 protected $_product = null;
00041
00042 protected function _prepareData()
00043 {
00044 $collection = Mage::getModel('catalog/product')->getResourceCollection()
00045 ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
00046 ->addAttributeToSort('position', 'asc')
00047 ->addStoreFilter()
00048 ->addMinimalPrice()
00049
00050 ->joinTable('bundle/option', 'parent_id=entity_id', array('option_id' => 'option_id'))
00051 ->joinTable('bundle/selection', 'option_id=option_id', array('product_id' => 'product_id'), '{{table}}.product_id='.$this->getProduct()->getId());
00052
00053 $ids = Mage::getSingleton('checkout/cart')->getProductIds();
00054
00055 if (count($ids)) {
00056 $collection->addIdFilter(Mage::getSingleton('checkout/cart')->getProductIds(), true);
00057 }
00058
00059 Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
00060 Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
00061 $collection->getSelect()->group('entity_id');
00062
00063 $collection->load();
00064 $this->_itemCollection = $collection;
00065
00066 return $this;
00067 }
00068
00069 protected function _beforeToHtml()
00070 {
00071 $this->_prepareData();
00072 return parent::_beforeToHtml();
00073 }
00074
00075 public function getItemCollection()
00076 {
00077 return $this->_itemCollection;
00078 }
00079
00080 public function getItems() {
00081 if (is_null($this->_items)) {
00082 $this->_items = $this->getItemCollection()->getItems();
00083 }
00084 return $this->_items;
00085 }
00086
00087 public function getRowCount()
00088 {
00089 return ceil($this->getItemCollection()->getSize()/$this->getColumnCount());
00090 }
00091
00092 public function setColumnCount($columns)
00093 {
00094 if (intval($columns) > 0) {
00095 $this->_columnCount = intval($columns);
00096 }
00097 return $this;
00098 }
00099
00100 public function getColumnCount()
00101 {
00102 return $this->_columnCount;
00103 }
00104
00105 public function resetItemsIterator()
00106 {
00107 $this->getItems();
00108 reset($this->_items);
00109 }
00110
00111 public function getIterableItem()
00112 {
00113 $item = current($this->_items);
00114 next($this->_items);
00115 return $item;
00116 }
00117
00118
00119
00120
00121
00122
00123 public function getProduct()
00124 {
00125 if (!$this->_product) {
00126 $this->_product = Mage::registry('product');
00127 }
00128 return $this->_product;
00129 }
00130 }