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_Eav_Decimal
36: extends Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract
37: {
38: 39: 40: 41:
42: protected function _construct()
43: {
44: $this->_init('catalog/product_index_eav_decimal', 'entity_id');
45: }
46:
47: 48: 49: 50: 51: 52: 53:
54: protected function _prepareIndex($entityIds = null, $attributeId = null)
55: {
56: $write = $this->_getWriteAdapter();
57: $idxTable = $this->getIdxTable();
58:
59: if (is_null($attributeId)) {
60: $attrIds = $this->_getIndexableAttributes();
61: } else {
62: $attrIds = array($attributeId);
63: }
64:
65: if (!$attrIds) {
66: return $this;
67: }
68:
69: $productValueExpression = $write->getCheckSql('pds.value_id > 0', 'pds.value', 'pdd.value');
70: $select = $write->select()
71: ->from(
72: array('pdd' => $this->getValueTable('catalog/product', 'decimal')),
73: array('entity_id', 'attribute_id'))
74: ->join(
75: array('cs' => $this->getTable('core/store')),
76: '',
77: array('store_id'))
78: ->joinLeft(
79: array('pds' => $this->getValueTable('catalog/product', 'decimal')),
80: 'pds.entity_id = pdd.entity_id AND pds.attribute_id = pdd.attribute_id'
81: . ' AND pds.store_id=cs.store_id',
82: array('value' => $productValueExpression))
83: ->where('pdd.store_id=?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID)
84: ->where('cs.store_id!=?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID)
85: ->where('pdd.attribute_id IN(?)', $attrIds)
86: ->where("{$productValueExpression} IS NOT NULL");
87:
88: $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
89: $this->_addAttributeToSelect($select, 'status', 'pdd.entity_id', 'cs.store_id', $statusCond);
90:
91: if (!is_null($entityIds)) {
92: $select->where('pdd.entity_id IN(?)', $entityIds);
93: }
94:
95: 96: 97:
98: Mage::dispatchEvent('prepare_catalog_product_index_select', array(
99: 'select' => $select,
100: 'entity_field' => new Zend_Db_Expr('pdd.entity_id'),
101: 'website_field' => new Zend_Db_Expr('cs.website_id'),
102: 'store_field' => new Zend_Db_Expr('cs.store_id')
103: ));
104:
105: $query = $select->insertFromSelect($idxTable);
106: $write->query($query);
107:
108: return $this;
109: }
110:
111: 112: 113: 114: 115:
116: protected function _getIndexableAttributes()
117: {
118: $adapter = $this->_getReadAdapter();
119: $select = $adapter->select()
120: ->from(array('ca' => $this->getTable('catalog/eav_attribute')), 'attribute_id')
121: ->join(
122: array('ea' => $this->getTable('eav/attribute')),
123: 'ca.attribute_id = ea.attribute_id',
124: array())
125: ->where('ea.attribute_code != ?', 'price')
126: ->where($this->_getIndexableAttributesCondition())
127: ->where('ea.backend_type=?', 'decimal');
128:
129: return $adapter->fetchCol($select);
130: }
131:
132: 133: 134: 135: 136: 137:
138: public function getIdxTable($table = null)
139: {
140: if ($this->useIdxTable()) {
141: return $this->getTable('catalog/product_eav_decimal_indexer_idx');
142: }
143: return $this->getTable('catalog/product_eav_decimal_indexer_tmp');
144: }
145: }
146: