00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat
00036 extends Mage_Core_Model_Mysql4_Abstract
00037 {
00038
00039
00040
00041
00042
00043 protected $_storeId;
00044
00045
00046
00047
00048
00049 protected function _construct()
00050 {
00051 $this->_init('catalog/product_flat', 'entity_id');
00052 $this->_storeId = Mage::app()->getStore()->getId();
00053 }
00054
00055
00056
00057
00058
00059
00060
00061 public function setStoreId($store)
00062 {
00063 $this->_storeId = Mage::app()->getStore($store)->getId();
00064 return $this;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 public function getFlatTableName($store = null)
00074 {
00075 if (!is_numeric($store)) {
00076 $store = Mage::app()->getStore($store)->getId();
00077 }
00078 return $this->getTable('catalog/product_flat') . '_' . $store;
00079 }
00080
00081
00082
00083
00084
00085
00086 public function getTypeId()
00087 {
00088 return Mage::getSingleton('catalog/config')
00089 ->getEntityType('catalog_product')
00090 ->getEntityTypeId();
00091 }
00092
00093
00094
00095
00096
00097
00098
00099 public function getAttributeForSelect($attributeCode)
00100 {
00101 $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName());
00102 if (!isset($describe[$attributeCode])) {
00103 return null;
00104 }
00105 $columns = array($attributeCode => $attributeCode);
00106
00107 if (isset($describe[$attributeCode . '_value'])) {
00108 $columns[$attributeCode . '_value'] = $attributeCode . '_value';
00109 }
00110
00111 return $columns;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120 public function getAttributeSortColumn($attributeCode)
00121 {
00122 $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName());
00123 if (!isset($describe[$attributeCode])) {
00124 return null;
00125 }
00126 if (isset($describe[$attributeCode . '_value'])) {
00127 return $attributeCode . '_value';
00128 }
00129 return $attributeCode;
00130 }
00131
00132
00133
00134
00135
00136
00137 public function getAllTableColumns()
00138 {
00139 $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName());
00140 return array_keys($describe);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150 public function isAttributeStatic($attribute)
00151 {
00152 $attributeCode = null;
00153 if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Interface) {
00154 $attributeCode = $attribute->getAttributeCode();
00155 }
00156 elseif (is_string($attribute)) {
00157 $attributeCode = $attribute;
00158 }
00159 elseif (is_numeric($attribute)) {
00160 $attributeCode = $this->getAttribute($attribute)
00161 ->getAttributeCode();
00162 }
00163
00164 if ($attributeCode) {
00165 $columns = $this->getAllTableColumns();
00166 if (in_array($attributeCode, $columns)) {
00167 return true;
00168 }
00169 }
00170
00171 return false;
00172 }
00173
00174
00175
00176
00177
00178
00179 public function getEntityIdField()
00180 {
00181 return $this->getIdFieldName();
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191 public function getAttribute($attribute)
00192 {
00193 return Mage::getSingleton('catalog/config')
00194 ->getAttribute('catalog_product', $attribute);
00195 }
00196 }