1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped
36: extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default
37: {
38: 39: 40: 41: 42:
43: public function reindexAll()
44: {
45: $this->useIdxTable(true);
46: $this->beginTransaction();
47: try {
48: $this->_prepareGroupedProductPriceData();
49: $this->commit();
50: } catch (Exception $e) {
51: $this->rollBack();
52: throw $e;
53: }
54: return $this;
55: }
56:
57: 58: 59: 60: 61: 62:
63: public function reindexEntity($entityIds)
64: {
65: $this->_prepareGroupedProductPriceData($entityIds);
66:
67: return $this;
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: protected function _prepareGroupedProductPriceData($entityIds = null)
78: {
79: $write = $this->_getWriteAdapter();
80: $table = $this->getIdxTable();
81:
82: $select = $write->select()
83: ->from(array('e' => $this->getTable('catalog/product')), 'entity_id')
84: ->joinLeft(
85: array('l' => $this->getTable('catalog/product_link')),
86: 'e.entity_id = l.product_id AND l.link_type_id=' . Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED,
87: array())
88: ->join(
89: array('cg' => $this->getTable('customer/customer_group')),
90: '',
91: array('customer_group_id'));
92: $this->_addWebsiteJoinToSelect($select, true);
93: $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id');
94: $minCheckSql = $write->getCheckSql('le.required_options = 0', 'i.min_price', 0);
95: $maxCheckSql = $write->getCheckSql('le.required_options = 0', 'i.max_price', 0);
96: $select->columns('website_id', 'cw')
97: ->joinLeft(
98: array('le' => $this->getTable('catalog/product')),
99: 'le.entity_id = l.linked_product_id',
100: array())
101: ->joinLeft(
102: array('i' => $table),
103: 'i.entity_id = l.linked_product_id AND i.website_id = cw.website_id'
104: . ' AND i.customer_group_id = cg.customer_group_id',
105: array(
106: 'tax_class_id' => $this->_getReadAdapter()
107: ->getCheckSql('MIN(i.tax_class_id) IS NULL', '0', 'MIN(i.tax_class_id)'),
108: 'price' => new Zend_Db_Expr('NULL'),
109: 'final_price' => new Zend_Db_Expr('NULL'),
110: 'min_price' => new Zend_Db_Expr('MIN(' . $minCheckSql . ')'),
111: 'max_price' => new Zend_Db_Expr('MAX(' . $maxCheckSql . ')'),
112: 'tier_price' => new Zend_Db_Expr('NULL'),
113: 'group_price' => new Zend_Db_Expr('NULL'),
114: ))
115: ->group(array('e.entity_id', 'cg.customer_group_id', 'cw.website_id'))
116: ->where('e.type_id=?', $this->getTypeId());
117:
118: if (!is_null($entityIds)) {
119: $select->where('l.product_id IN(?)', $entityIds);
120: }
121:
122: 123: 124:
125: Mage::dispatchEvent('catalog_product_prepare_index_select', array(
126: 'select' => $select,
127: 'entity_field' => new Zend_Db_Expr('e.entity_id'),
128: 'website_field' => new Zend_Db_Expr('cw.website_id'),
129: 'store_field' => new Zend_Db_Expr('cs.store_id')
130: ));
131:
132: $query = $select->insertFromSelect($table);
133: $write->query($query);
134:
135: return $this;
136: }
137: }
138: