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_Config extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: 38: 39: 40: 41:
42: protected $_entityTypeId;
43:
44: 45: 46: 47: 48:
49: protected $_storeId = null;
50:
51: 52: 53: 54:
55: protected function _construct()
56: {
57: $this->_init('eav/attribute', 'attribute_id');
58: }
59:
60: 61: 62: 63: 64: 65:
66: public function setStoreId($storeId)
67: {
68: $this->_storeId = (int)$storeId;
69: return $this;
70: }
71:
72: 73: 74: 75: 76: 77:
78: public function getStoreId()
79: {
80: if ($this->_storeId === null) {
81: return Mage::app()->getStore()->getId();
82: }
83: return $this->_storeId;
84: }
85:
86: 87: 88: 89: 90:
91: public function getEntityTypeId()
92: {
93: if ($this->_entityTypeId === null) {
94: $this->_entityTypeId = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId();
95: }
96: return $this->_entityTypeId;
97: }
98:
99: 100: 101: 102: 103:
104: public function getAttributesUsedInListing()
105: {
106: $adapter = $this->_getReadAdapter();
107: $storeLabelExpr = $adapter->getCheckSql('al.value IS NOT NULL', 'al.value', 'main_table.frontend_label');
108:
109: $select = $adapter->select()
110: ->from(array('main_table' => $this->getTable('eav/attribute')))
111: ->join(
112: array('additional_table' => $this->getTable('catalog/eav_attribute')),
113: 'main_table.attribute_id = additional_table.attribute_id'
114: )
115: ->joinLeft(
116: array('al' => $this->getTable('eav/attribute_label')),
117: 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$this->getStoreId(),
118: array('store_label' => $storeLabelExpr)
119: )
120: ->where('main_table.entity_type_id = ?', (int)$this->getEntityTypeId())
121: ->where('additional_table.used_in_product_listing = ?', 1);
122:
123: return $adapter->fetchAll($select);
124: }
125:
126: 127: 128: 129: 130:
131: public function getAttributesUsedForSortBy()
132: {
133: $adapter = $this->_getReadAdapter();
134: $storeLabelExpr = $adapter->getCheckSql('al.value IS NULL', 'main_table.frontend_label','al.value');
135: $select = $adapter->select()
136: ->from(array('main_table' => $this->getTable('eav/attribute')))
137: ->join(
138: array('additional_table' => $this->getTable('catalog/eav_attribute')),
139: 'main_table.attribute_id = additional_table.attribute_id',
140: array()
141: )
142: ->joinLeft(
143: array('al' => $this->getTable('eav/attribute_label')),
144: 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$this->getStoreId(),
145: array('store_label' => $storeLabelExpr)
146: )
147: ->where('main_table.entity_type_id = ?', (int)$this->getEntityTypeId())
148: ->where('additional_table.used_for_sort_by = ?', 1);
149:
150: return $adapter->fetchAll($select);
151: }
152: }
153: