1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Bundle
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Catalog product related items block
29: *
30: * @category Mage
31: * @package Mage_Bundle
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Bundle_Block_Catalog_Product_List_Partof extends Mage_Catalog_Block_Product_Abstract
36: {
37: protected $_columnCount = 4;
38: protected $_items;
39: protected $_itemCollection;
40: protected $_product = null;
41:
42: protected function _prepareData()
43: {
44: $collection = Mage::getModel('catalog/product')->getResourceCollection()
45: ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
46: ->addAttributeToSort('position', 'asc')
47: ->addStoreFilter()
48: ->addMinimalPrice()
49:
50: ->joinTable('bundle/option', 'parent_id=entity_id', array('option_id' => 'option_id'))
51: ->joinTable('bundle/selection', 'option_id=option_id', array('product_id' => 'product_id'), '{{table}}.product_id='.$this->getProduct()->getId());
52:
53: $ids = Mage::getSingleton('checkout/cart')->getProductIds();
54:
55: if (count($ids)) {
56: $collection->addIdFilter(Mage::getSingleton('checkout/cart')->getProductIds(), true);
57: }
58:
59: Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
60: Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
61: $collection->getSelect()->group('entity_id');
62:
63: $collection->load();
64: $this->_itemCollection = $collection;
65:
66: return $this;
67: }
68:
69: protected function _beforeToHtml()
70: {
71: $this->_prepareData();
72: return parent::_beforeToHtml();
73: }
74:
75: public function getItemCollection()
76: {
77: return $this->_itemCollection;
78: }
79:
80: public function getItems() {
81: if (is_null($this->_items)) {
82: $this->_items = $this->getItemCollection()->getItems();
83: }
84: return $this->_items;
85: }
86:
87: public function getRowCount()
88: {
89: return ceil($this->getItemCollection()->getSize()/$this->getColumnCount());
90: }
91:
92: public function setColumnCount($columns)
93: {
94: if (intval($columns) > 0) {
95: $this->_columnCount = intval($columns);
96: }
97: return $this;
98: }
99:
100: public function getColumnCount()
101: {
102: return $this->_columnCount;
103: }
104:
105: public function resetItemsIterator()
106: {
107: $this->getItems();
108: reset($this->_items);
109: }
110:
111: public function getIterableItem()
112: {
113: $item = current($this->_items);
114: next($this->_items);
115: return $item;
116: }
117:
118: /**
119: * Get current product from registry
120: *
121: * @return Mage_Catalog_Model_Product
122: */
123: public function getProduct()
124: {
125: if (!$this->_product) {
126: $this->_product = Mage::registry('product');
127: }
128: return $this->_product;
129: }
130: }
131: