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_CatalogIndex
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: /**
29: * Catalog indexer price processor
30: *
31: * @method Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice _getResource()
32: * @method Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice getResource()
33: * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setEntityId(int $value)
34: * @method int getCustomerGroupId()
35: * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setCustomerGroupId(int $value)
36: * @method float getQty()
37: * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setQty(float $value)
38: * @method float getValue()
39: * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setValue(float $value)
40: * @method int getTaxClassId()
41: * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setTaxClassId(int $value)
42: * @method int getWebsiteId()
43: * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setWebsiteId(int $value)
44: *
45: * @category Mage
46: * @package Mage_CatalogIndex
47: * @author Magento Core Team <core@magentocommerce.com>
48: */
49: class Mage_CatalogIndex_Model_Indexer_Minimalprice extends Mage_CatalogIndex_Model_Indexer_Abstract
50: {
51: protected $_customerGroups = array();
52: protected $_runOnce = true;
53: protected $_processChildren = false;
54:
55: protected function _construct()
56: {
57: $this->_init('catalogindex/indexer_minimalprice');
58: $this->_currencyModel = Mage::getModel('directory/currency');
59: $this->_customerGroups = Mage::getModel('customer/group')->getCollection();
60:
61: return parent::_construct();
62: }
63:
64: public function getTierPriceAttribute()
65: {
66: $data = $this->getData('tier_price_attribute');
67: if (is_null($data)) {
68: $data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price');
69: $this->setData('tier_price_attribute', $data);
70: }
71: return $data;
72: }
73:
74: public function getPriceAttribute()
75: {
76: $data = $this->getData('price_attribute');
77: if (is_null($data)) {
78: $data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'price');
79: $this->setData('price_attribute', $data);
80: }
81: return $data;
82: }
83:
84: public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null)
85: {
86: $searchEntityId = $object->getId();
87: $priceAttributeId = $this->getTierPriceAttribute()->getId();
88: if ($object->isGrouped()) {
89: $priceAttributeId = $this->getPriceAttribute()->getId();
90: $associated = $object->getTypeInstance(true)->getAssociatedProducts($object);
91: $searchEntityId = array();
92:
93: foreach ($associated as $product) {
94: $searchEntityId[] = $product->getId();
95: }
96: }
97:
98: if (!count($searchEntityId)) {
99: return false;
100: }
101:
102: $result = array();
103: $data = array();
104:
105: $data['store_id'] = $object->getStoreId();
106: $data['entity_id'] = $object->getId();
107:
108: $search['store_id'] = $object->getStoreId();
109: $search['entity_id'] = $searchEntityId;
110: $search['attribute_id'] = $priceAttributeId;
111:
112: foreach ($this->_customerGroups as $group) {
113: $search['customer_group_id'] = $group->getId();
114: $data['customer_group_id'] = $group->getId();
115:
116: $value = $this->_getResource()->getMinimalValue($search);
117: if (is_null($value))
118: continue;
119: $data['value'] = $value;
120: $result[] = $data;
121: }
122:
123: return $result;
124: }
125:
126: public function isAttributeIdUsed()
127: {
128: return false;
129: }
130:
131: protected function _isAttributeIndexable(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
132: {
133: if ($attribute->getAttributeCode() != 'minimal_price')
134: return false;
135:
136: return true;
137: }
138: }
139: