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: * Tier Price indexer
30: *
31: * @method Mage_CatalogIndex_Model_Resource_Indexer_Price _getResource()
32: * @method Mage_CatalogIndex_Model_Resource_Indexer_Price getResource()
33: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setEntityId(int $value)
34: * @method int getCustomerGroupId()
35: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setCustomerGroupId(int $value)
36: * @method int getWebsiteId()
37: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setWebsiteId(int $value)
38: * @method int getTaxClassId()
39: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setTaxClassId(int $value)
40: * @method float getPrice()
41: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setPrice(float $value)
42: * @method float getFinalPrice()
43: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setFinalPrice(float $value)
44: * @method float getMinPrice()
45: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setMinPrice(float $value)
46: * @method float getMaxPrice()
47: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setMaxPrice(float $value)
48: * @method float getTierPrice()
49: * @method Mage_CatalogIndex_Model_Indexer_Tierprice setTierPrice(float $value)
50: *
51: * @category Mage
52: * @package Mage_CatalogIndex
53: * @author Magento Core Team <core@magentocommerce.com>
54: */
55: class Mage_CatalogIndex_Model_Indexer_Tierprice extends Mage_CatalogIndex_Model_Indexer_Abstract
56: {
57: protected $_processChildren = false;
58:
59: protected function _construct()
60: {
61: $this->_init('catalogindex/indexer_price');
62: $this->_currencyModel = Mage::getModel('directory/currency');
63: $this->_customerGroups = Mage::getModel('customer/group')->getCollection();
64:
65: return parent::_construct();
66: }
67:
68: public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null)
69: {
70: $data = array();
71:
72: $data['store_id'] = $attribute->getStoreId();
73: $data['entity_id'] = $object->getId();
74: $data['attribute_id'] = $attribute->getId();
75:
76: $result = array();
77: $values = $object->getData($attribute->getAttributeCode());
78:
79: if (!is_array($values)) {
80: return $result;
81: }
82:
83: foreach ($values as $row) {
84: if (isset($row['delete']) && $row['delete']) {
85: continue;
86: }
87:
88: $data['qty'] = $row['price_qty'];
89: $data['value'] = $row['price'];
90: if ($row['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL) {
91: foreach ($this->_customerGroups as $group) {
92: $data['customer_group_id'] = $group->getId();
93: $result[] = $data;
94: }
95: } else {
96: $data['customer_group_id'] = $row['cust_group'];
97: $result[] = $data;
98: }
99:
100: }
101:
102: return $result;
103: }
104:
105: protected function _isAttributeIndexable(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
106: {
107: if ($attribute->getAttributeCode() != 'tier_price') {
108: return false;
109: }
110:
111: return true;
112: }
113:
114: protected function _getIndexableAttributeConditions()
115: {
116: $conditions = array();
117: $conditions['attribute_code'] = 'tier_price';
118:
119: return $conditions;
120: }
121: }
122: