Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Catalog_Model_Entity_Product_Attribute_Design_Options_Container
  • Mage_Catalog_Model_Product_Attribute_Source_Inputtype
  • Mage_Eav_Block_Adminhtml_Attribute_Edit_Js
  • Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract
  • Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
  • Mage_Eav_Helper_Data
  • Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype
  • Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype_Validator
  • Mage_Eav_Model_Attribute
  • Mage_Eav_Model_Attribute_Data
  • Mage_Eav_Model_Attribute_Data_Abstract
  • Mage_Eav_Model_Attribute_Data_Boolean
  • Mage_Eav_Model_Attribute_Data_Date
  • Mage_Eav_Model_Attribute_Data_File
  • Mage_Eav_Model_Attribute_Data_Hidden
  • Mage_Eav_Model_Attribute_Data_Image
  • Mage_Eav_Model_Attribute_Data_Multiline
  • Mage_Eav_Model_Attribute_Data_Multiselect
  • Mage_Eav_Model_Attribute_Data_Select
  • Mage_Eav_Model_Attribute_Data_Text
  • Mage_Eav_Model_Attribute_Data_Textarea
  • Mage_Eav_Model_Config
  • Mage_Eav_Model_Convert_Adapter_Entity
  • Mage_Eav_Model_Convert_Adapter_Grid
  • Mage_Eav_Model_Convert_Parser_Abstract
  • Mage_Eav_Model_Entity
  • Mage_Eav_Model_Entity_Abstract
  • Mage_Eav_Model_Entity_Attribute
  • Mage_Eav_Model_Entity_Attribute_Abstract
  • Mage_Eav_Model_Entity_Attribute_Backend_Abstract
  • Mage_Eav_Model_Entity_Attribute_Backend_Array
  • Mage_Eav_Model_Entity_Attribute_Backend_Datetime
  • Mage_Eav_Model_Entity_Attribute_Backend_Default
  • Mage_Eav_Model_Entity_Attribute_Backend_Increment
  • Mage_Eav_Model_Entity_Attribute_Backend_Serialized
  • Mage_Eav_Model_Entity_Attribute_Backend_Store
  • Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
  • Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated
  • Mage_Eav_Model_Entity_Attribute_Frontend_Abstract
  • Mage_Eav_Model_Entity_Attribute_Frontend_Datetime
  • Mage_Eav_Model_Entity_Attribute_Frontend_Default
  • Mage_Eav_Model_Entity_Attribute_Group
  • Mage_Eav_Model_Entity_Attribute_Option
  • Mage_Eav_Model_Entity_Attribute_Set
  • Mage_Eav_Model_Entity_Attribute_Source_Abstract
  • Mage_Eav_Model_Entity_Attribute_Source_Boolean
  • Mage_Eav_Model_Entity_Attribute_Source_Config
  • Mage_Eav_Model_Entity_Attribute_Source_Store
  • Mage_Eav_Model_Entity_Attribute_Source_Table
  • Mage_Eav_Model_Entity_Collection
  • Mage_Eav_Model_Entity_Collection_Abstract
  • Mage_Eav_Model_Entity_Increment_Abstract
  • Mage_Eav_Model_Entity_Increment_Alphanum
  • Mage_Eav_Model_Entity_Increment_Numeric
  • Mage_Eav_Model_Entity_Setup
  • Mage_Eav_Model_Entity_Store
  • Mage_Eav_Model_Entity_Type
  • Mage_Eav_Model_Form
  • Mage_Eav_Model_Form_Element
  • Mage_Eav_Model_Form_Fieldset
  • Mage_Eav_Model_Form_Type
  • Mage_Eav_Model_Mysql4_Config
  • Mage_Eav_Model_Mysql4_Entity_Attribute
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Group
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Option
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Option_Collection
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Set
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection
  • Mage_Eav_Model_Mysql4_Entity_Store
  • Mage_Eav_Model_Mysql4_Entity_Type
  • Mage_Eav_Model_Mysql4_Entity_Type_Collection
  • Mage_Eav_Model_Mysql4_Form_Element
  • Mage_Eav_Model_Mysql4_Form_Element_Collection
  • Mage_Eav_Model_Mysql4_Form_Fieldset
  • Mage_Eav_Model_Mysql4_Form_Fieldset_Collection
  • Mage_Eav_Model_Mysql4_Form_Type
  • Mage_Eav_Model_Mysql4_Form_Type_Collection
  • Mage_Eav_Model_Resource_Attribute
  • Mage_Eav_Model_Resource_Attribute_Collection
  • Mage_Eav_Model_Resource_Config
  • Mage_Eav_Model_Resource_Entity_Attribute
  • Mage_Eav_Model_Resource_Entity_Attribute_Collection
  • Mage_Eav_Model_Resource_Entity_Attribute_Group
  • Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection
  • Mage_Eav_Model_Resource_Entity_Attribute_Option
  • Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection
  • Mage_Eav_Model_Resource_Entity_Attribute_Set
  • Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection
  • Mage_Eav_Model_Resource_Entity_Store
  • Mage_Eav_Model_Resource_Entity_Type
  • Mage_Eav_Model_Resource_Entity_Type_Collection
  • Mage_Eav_Model_Resource_Form_Attribute
  • Mage_Eav_Model_Resource_Form_Attribute_Collection
  • Mage_Eav_Model_Resource_Form_Element
  • Mage_Eav_Model_Resource_Form_Element_Collection
  • Mage_Eav_Model_Resource_Form_Fieldset
  • Mage_Eav_Model_Resource_Form_Fieldset_Collection
  • Mage_Eav_Model_Resource_Form_Type
  • Mage_Eav_Model_Resource_Form_Type_Collection
  • Mage_Eav_Model_Resource_Helper_Mysql4

Interfaces

  • Mage_Eav_Model_Entity_Attribute_Backend_Interface
  • Mage_Eav_Model_Entity_Attribute_Frontend_Interface
  • Mage_Eav_Model_Entity_Attribute_Interface
  • Mage_Eav_Model_Entity_Attribute_Source_Interface
  • Mage_Eav_Model_Entity_Increment_Interface
  • Mage_Eav_Model_Entity_Interface

Exceptions

  • Mage_Eav_Exception
  • Mage_Eav_Model_Entity_Attribute_Exception
  • Overview
  • Package
  • Class
  • Tree
  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_Eav
 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:  * EAV attribute resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Eav
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Eav_Model_Resource_Entity_Attribute extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Eav Entity attributes cache
 39:      *
 40:      * @var array
 41:      */
 42:     protected static $_entityAttributes     = array();
 43: 
 44:     /**
 45:      * Define main table
 46:      *
 47:      */
 48:     protected function _construct()
 49:     {
 50:         $this->_init('eav/attribute', 'attribute_id');
 51:     }
 52: 
 53:     /**
 54:      * Initialize unique fields
 55:      *
 56:      * @return Mage_Eav_Model_Resource_Entity_Attribute
 57:      */
 58:     protected function _initUniqueFields()
 59:     {
 60:         $this->_uniqueFields = array(array(
 61:             'field' => array('attribute_code', 'entity_type_id'),
 62:             'title' => Mage::helper('eav')->__('Attribute with the same code')
 63:         ));
 64:         return $this;
 65:     }
 66: 
 67:     /**
 68:      * Load all entity type attributes
 69:      *
 70:      * @param int $entityTypeId
 71:      * @return Mage_Eav_Model_Resource_Entity_Attribute
 72:      */
 73:     protected function _loadTypeAttributes($entityTypeId)
 74:     {
 75:         if (!isset(self::$_entityAttributes[$entityTypeId])) {
 76:             $adapter = $this->_getReadAdapter();
 77:             $bind    = array(':entity_type_id' => $entityTypeId);
 78:             $select  = $adapter->select()
 79:                 ->from($this->getMainTable())
 80:                 ->where('entity_type_id = :entity_type_id');
 81: 
 82:             $data    = $adapter->fetchAll($select, $bind);
 83:             foreach ($data as $row) {
 84:                 self::$_entityAttributes[$entityTypeId][$row['attribute_code']] = $row;
 85:             }
 86:         }
 87: 
 88:         return $this;
 89:     }
 90: 
 91:     /**
 92:      * Load attribute data by attribute code
 93:      *
 94:      * @param Mage_Eav_Model_Entity_Attribute $object
 95:      * @param int $entityTypeId
 96:      * @param string $code
 97:      * @return boolean
 98:      */
 99:     public function loadByCode(Mage_Core_Model_Abstract $object, $entityTypeId, $code)
100:     {
101:         $bind   = array(':entity_type_id' => $entityTypeId);
102:         $select = $this->_getLoadSelect('attribute_code', $code, $object)
103:             ->where('entity_type_id = :entity_type_id');
104:         $data = $this->_getReadAdapter()->fetchRow($select, $bind);
105: 
106:         if ($data) {
107:             $object->setData($data);
108:             $this->_afterLoad($object);
109:             return true;
110:         }
111:         return false;
112:     }
113: 
114:     /**
115:      * Retrieve Max Sort order for attribute in group
116:      *
117:      * @param Mage_Core_Model_Abstract $object
118:      * @return int
119:      */
120:     private function _getMaxSortOrder(Mage_Core_Model_Abstract $object)
121:     {
122:         if (intval($object->getAttributeGroupId()) > 0) {
123:             $adapter = $this->_getReadAdapter();
124:             $bind = array(
125:                 ':attribute_set_id'   => $object->getAttributeSetId(),
126:                 ':attribute_group_id' => $object->getAttributeGroupId()
127:             );
128:             $select = $adapter->select()
129:                 ->from($this->getTable('eav/entity_attribute'), new Zend_Db_Expr("MAX(sort_order)"))
130:                 ->where('attribute_set_id = :attribute_set_id')
131:                 ->where('attribute_group_id = :attribute_group_id');
132: 
133:             return $adapter->fetchOne($select, $bind);
134:         }
135: 
136:         return 0;
137:     }
138: 
139:     /**
140:      * Delete entity
141:      *
142:      * @param Mage_Core_Model_Abstract $object
143:      * @return Mage_Eav_Model_Resource_Entity_Attribute
144:      */
145:     public function deleteEntity(Mage_Core_Model_Abstract $object)
146:     {
147:         if (!$object->getEntityAttributeId()) {
148:             return $this;
149:         }
150: 
151:         $this->_getWriteAdapter()->delete($this->getTable('eav/entity_attribute'), array(
152:             'entity_attribute_id = ?' => $object->getEntityAttributeId()
153:         ));
154: 
155:         return $this;
156:     }
157: 
158:     /**
159:      * Validate attribute data before save
160:      *
161:      * @param Mage_Eav_Model_Entity_Attribute $object
162:      * @return Mage_Eav_Model_Resource_Entity_Attribute
163:      */
164:     protected function _beforeSave(Mage_Core_Model_Abstract $object)
165:     {
166:         $frontendLabel = $object->getFrontendLabel();
167:         if (is_array($frontendLabel)) {
168:             if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') {
169:                 Mage::throwException(Mage::helper('eav')->__('Frontend label is not defined'));
170:             }
171:             $object->setFrontendLabel($frontendLabel[0])
172:                    ->setStoreLabels($frontendLabel);
173:         }
174: 
175:         /**
176:          * @todo need use default source model of entity type !!!
177:          */
178:         if (!$object->getId()) {
179:             if ($object->getFrontendInput() == 'select') {
180:                 $object->setSourceModel('eav/entity_attribute_source_table');
181:             }
182:         }
183: 
184:         return parent::_beforeSave($object);
185:     }
186: 
187:     /**
188:      * Save additional attribute data after save attribute
189:      *
190:      * @param Mage_Eav_Model_Entity_Attribute $object
191:      * @return Mage_Eav_Model_Resource_Entity_Attribute
192:      */
193:     protected function _afterSave(Mage_Core_Model_Abstract $object)
194:     {
195:         $this->_saveStoreLabels($object)
196:              ->_saveAdditionalAttributeData($object)
197:              ->saveInSetIncluding($object)
198:              ->_saveOption($object);
199: 
200:         return parent::_afterSave($object);
201:     }
202: 
203:     /**
204:      * Save store labels
205:      *
206:      * @param Mage_Eav_Model_Entity_Attribute $object
207:      * @return Mage_Eav_Model_Resource_Entity_Attribute
208:      */
209:     protected function _saveStoreLabels(Mage_Core_Model_Abstract $object)
210:     {
211:         $storeLabels = $object->getStoreLabels();
212:         if (is_array($storeLabels)) {
213:             $adapter = $this->_getWriteAdapter();
214:             if ($object->getId()) {
215:                 $condition = array('attribute_id =?' => $object->getId());
216:                 $adapter->delete($this->getTable('eav/attribute_label'), $condition);
217:             }
218:             foreach ($storeLabels as $storeId => $label) {
219:                 if ($storeId == 0 || !strlen($label)) {
220:                     continue;
221:                 }
222:                 $bind = array (
223:                     'attribute_id' => $object->getId(),
224:                     'store_id'     => $storeId,
225:                     'value'        => $label
226:                 );
227:                 $adapter->insert($this->getTable('eav/attribute_label'), $bind);
228:             }
229:         }
230: 
231:         return $this;
232:     }
233: 
234:     /**
235:      * Save additional data of attribute
236:      *
237:      * @param Mage_Eav_Model_Entity_Attribute $object
238:      * @return Mage_Eav_Model_Resource_Entity_Attribute
239:      */
240:     protected function _saveAdditionalAttributeData(Mage_Core_Model_Abstract $object)
241:     {
242:         $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId());
243:         if ($additionalTable) {
244:             $adapter    = $this->_getWriteAdapter();
245:             $data       = $this->_prepareDataForTable($object, $this->getTable($additionalTable));
246:             $bind       = array(':attribute_id' => $object->getId());
247:             $select     = $adapter->select()
248:                 ->from($this->getTable($additionalTable), array('attribute_id'))
249:                 ->where('attribute_id = :attribute_id');
250:             $result     = $adapter->fetchOne($select, $bind);
251:             if ($result) {
252:                 $where  = array('attribute_id = ?' => $object->getId());
253:                 $adapter->update($this->getTable($additionalTable), $data, $where);
254:             } else {
255:                 $adapter->insert($this->getTable($additionalTable), $data);
256:             }
257:         }
258: 
259:         return $this;
260:     }
261: 
262:     /**
263:      * Save in set including
264:      *
265:      * @param Mage_Core_Model_Abstract $object
266:      * @return Mage_Eav_Model_Resource_Entity_Attribute
267:      */
268:     public function saveInSetIncluding(Mage_Core_Model_Abstract $object)
269:     {
270:         $attributeId = (int) $object->getId();
271:         $setId       = (int) $object->getAttributeSetId();
272:         $groupId     = (int) $object->getAttributeGroupId();
273: 
274:         if ($setId && $groupId && $object->getEntityTypeId()) {
275:             $adapter = $this->_getWriteAdapter();
276:             $table   = $this->getTable('eav/entity_attribute');
277: 
278:             $sortOrder = (($object->getSortOrder()) ? $object->getSortOrder() : $this->_getMaxSortOrder($object) + 1);
279:             $data = array(
280:                 'entity_type_id'     => $object->getEntityTypeId(),
281:                 'attribute_set_id'   => $setId,
282:                 'attribute_group_id' => $groupId,
283:                 'attribute_id'       => $attributeId,
284:                 'sort_order'         => $sortOrder
285:             );
286: 
287:             $where = array(
288:                 'attribute_id =?'     => $attributeId,
289:                 'attribute_set_id =?' => $setId
290:             );
291: 
292:             $adapter->delete($table, $where);
293:             $adapter->insert($table, $data);
294:         }
295: 
296:         return $this;
297:     }
298: 
299:     /**
300:      *  Save attribute options
301:      *
302:      * @param Mage_Eav_Model_Entity_Attribute $object
303:      * @return Mage_Eav_Model_Resource_Entity_Attribute
304:      */
305:     protected function _saveOption(Mage_Core_Model_Abstract $object)
306:     {
307:         $option = $object->getOption();
308:         if (is_array($option)) {
309:             $adapter            = $this->_getWriteAdapter();
310:             $optionTable        = $this->getTable('eav/attribute_option');
311:             $optionValueTable   = $this->getTable('eav/attribute_option_value');
312: 
313:             $stores = Mage::app()->getStores(true);
314:             if (isset($option['value'])) {
315:                 $attributeDefaultValue = array();
316:                 if (!is_array($object->getDefault())) {
317:                     $object->setDefault(array());
318:                 }
319: 
320:                 foreach ($option['value'] as $optionId => $values) {
321:                     $intOptionId = (int) $optionId;
322:                     if (!empty($option['delete'][$optionId])) {
323:                         if ($intOptionId) {
324:                             $adapter->delete($optionTable, array('option_id = ?' => $intOptionId));
325:                         }
326:                         continue;
327:                     }
328: 
329:                     $sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
330:                     if (!$intOptionId) {
331:                         $data = array(
332:                            'attribute_id'  => $object->getId(),
333:                            'sort_order'    => $sortOrder
334:                         );
335:                         $adapter->insert($optionTable, $data);
336:                         $intOptionId = $adapter->lastInsertId($optionTable);
337:                     } else {
338:                         $data  = array('sort_order'    => $sortOrder);
339:                         $where = array('option_id =?' => $intOptionId);
340:                         $adapter->update($optionTable, $data, $where);
341:                     }
342: 
343:                     if (in_array($optionId, $object->getDefault())) {
344:                         if ($object->getFrontendInput() == 'multiselect') {
345:                             $attributeDefaultValue[] = $intOptionId;
346:                         } elseif ($object->getFrontendInput() == 'select') {
347:                             $attributeDefaultValue = array($intOptionId);
348:                         }
349:                     }
350: 
351:                     // Default value
352:                     if (!isset($values[0])) {
353:                         Mage::throwException(Mage::helper('eav')->__('Default option value is not defined'));
354:                     }
355: 
356:                     $adapter->delete($optionValueTable, array('option_id =?' => $intOptionId));
357:                     foreach ($stores as $store) {
358:                         if (isset($values[$store->getId()])
359:                             && (!empty($values[$store->getId()])
360:                             || $values[$store->getId()] == "0")
361:                         ) {
362:                             $data = array(
363:                                 'option_id' => $intOptionId,
364:                                 'store_id'  => $store->getId(),
365:                                 'value'     => $values[$store->getId()],
366:                             );
367:                             $adapter->insert($optionValueTable, $data);
368:                         }
369:                     }
370:                 }
371:                 $bind  = array('default_value' => implode(',', $attributeDefaultValue));
372:                 $where = array('attribute_id =?' => $object->getId());
373:                 $adapter->update($this->getMainTable(), $bind, $where);
374:             }
375:         }
376: 
377:         return $this;
378:     }
379: 
380: 
381:     /**
382:      * Retrieve attribute id by entity type code and attribute code
383:      *
384:      * @param string $entityType
385:      * @param string $code
386:      * @return int
387:      */
388:     public function getIdByCode($entityType, $code)
389:     {
390:         $adapter = $this->_getReadAdapter();
391:         $bind    = array(
392:             ':entity_type_code' => $entityType,
393:             ':attribute_code'   => $code
394:         );
395:         $select = $adapter->select()
396:             ->from(array('a' => $this->getTable('eav/attribute')), array('a.attribute_id'))
397:             ->join(
398:                 array('t' => $this->getTable('eav/entity_type')),
399:                 'a.entity_type_id = t.entity_type_id',
400:                 array())
401:             ->where('t.entity_type_code = :entity_type_code')
402:             ->where('a.attribute_code = :attribute_code');
403: 
404:         return $adapter->fetchOne($select, $bind);
405:     }
406: 
407:     /**
408:      * Retrieve attribute codes by front-end type
409:      *
410:      * @param string $frontendType
411:      * @return array
412:      */
413:     public function getAttributeCodesByFrontendType($frontendType)
414:     {
415:         $adapter = $this->_getReadAdapter();
416:         $bind    = array(':frontend_input' => $frontendType);
417:         $select  = $adapter->select()
418:             ->from($this->getTable('eav/attribute'), 'attribute_code')
419:             ->where('frontend_input = :frontend_input');
420: 
421:         return $adapter->fetchCol($select, $bind);
422:     }
423: 
424:     /**
425:      * Retrieve Select For Flat Attribute update
426:      *
427:      * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
428:      * @param int $storeId
429:      * @return Varien_Db_Select
430:      */
431:     public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $storeId)
432:     {
433:         $adapter = $this->_getReadAdapter();
434:         $joinConditionTemplate = "%s.entity_id=%s.entity_id"
435:             ." AND %s.entity_type_id = ".$attribute->getEntityTypeId()
436:             ." AND %s.attribute_id = ".$attribute->getId()
437:             ." AND %s.store_id = %d";
438:         $joinCondition = sprintf($joinConditionTemplate,
439:             'e', 't1', 't1', 't1', 't1',
440:             Mage_Core_Model_App::ADMIN_STORE_ID);
441:         if ($attribute->getFlatAddChildData()) {
442:             $joinCondition .= ' AND e.child_id = t1.entity_id';
443:         }
444: 
445:         $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value');
446: 
447:         /** @var $select Varien_Db_Select */
448:         $select = $adapter->select()
449:             ->joinLeft(
450:                 array('t1' => $attribute->getBackend()->getTable()),
451:                 $joinCondition,
452:                 array())
453:             ->joinLeft(
454:                 array('t2' => $attribute->getBackend()->getTable()),
455:                 sprintf($joinConditionTemplate, 't1', 't2', 't2', 't2', 't2', $storeId),
456:                 array($attribute->getAttributeCode() => $valueExpr));
457:         if ($attribute->getFlatAddChildData()) {
458:             $select->where("e.is_child = ?", 0);
459:         }
460: 
461:         return $select;
462:     }
463: 
464:     /**
465:      * Returns the column descriptions for a table
466:      *
467:      * @param string $table
468:      * @return array
469:      */
470:     public function describeTable($table)
471:     {
472:         return $this->_getReadAdapter()->describeTable($table);
473:     }
474: 
475:     /**
476:      * Retrieve additional attribute table name for specified entity type
477:      *
478:      * @param integer $entityTypeId
479:      * @return string
480:      */
481:     public function getAdditionalAttributeTable($entityTypeId)
482:     {
483:         return Mage::getResourceSingleton('eav/entity_type')->getAdditionalAttributeTable($entityTypeId);
484:     }
485: 
486:     /**
487:      * Load additional attribute data.
488:      * Load label of current active store
489:      *
490:      * @param Mage_Eav_Model_Entity_Attribute $object
491:      * @return Mage_Eav_Model_Resource_Entity_Attribute
492:      */
493:     protected function _afterLoad(Mage_Core_Model_Abstract $object)
494:     {
495:         /** @var $entityType Mage_Eav_Model_Entity_Type */
496:         $entityType = $object->getData('entity_type');
497:         if ($entityType) {
498:             $additionalTable = $entityType->getAdditionalAttributeTable();
499:         } else {
500:             $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId());
501:         }
502: 
503:         if ($additionalTable) {
504:             $adapter = $this->_getReadAdapter();
505:             $bind    = array(':attribute_id' => $object->getId());
506:             $select  = $adapter->select()
507:                 ->from($this->getTable($additionalTable))
508:                 ->where('attribute_id = :attribute_id');
509: 
510:             $result = $adapter->fetchRow($select, $bind);
511:             if ($result) {
512:                 $object->addData($result);
513:             }
514:         }
515: 
516:         return $this;
517:     }
518: 
519:     /**
520:      * Retrieve store labels by given attribute id
521:      *
522:      * @param integer $attributeId
523:      * @return array
524:      */
525:     public function getStoreLabelsByAttributeId($attributeId)
526:     {
527:         $adapter   = $this->_getReadAdapter();
528:         $bind      = array(':attribute_id' => $attributeId);
529:         $select    = $adapter->select()
530:             ->from($this->getTable('eav/attribute_label'), array('store_id', 'value'))
531:             ->where('attribute_id = :attribute_id');
532: 
533:         return $adapter->fetchPairs($select, $bind);
534:     }
535: 
536:     /**
537:      * Load by given attributes ids and return only exist attribute ids
538:      *
539:      * @param array $attributeIds
540:      * @return array
541:      */
542:     public function getValidAttributeIds($attributeIds)
543:     {
544:         $adapter   = $this->_getReadAdapter();
545:         $select    = $adapter->select()
546:             ->from($this->getMainTable(), array('attribute_id'))
547:             ->where('attribute_id IN (?)', $attributeIds);
548: 
549:         return $adapter->fetchCol($select);
550:     }
551: }
552: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0