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 Entity attribute model
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_Eav
 33:  * @author     Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Abstract
 36: {
 37:     /**
 38:      * Prefix of model events names
 39:      *
 40:      * @var string
 41:      */
 42:     protected $_eventPrefix                         = 'eav_entity_attribute';
 43: 
 44:     CONST ATTRIBUTE_CODE_MAX_LENGTH                 = 30;
 45: 
 46:     /**
 47:      * Parameter name in event
 48:      *
 49:      * In observe method you can use $observer->getEvent()->getAttribute() in this case
 50:      *
 51:      * @var string
 52:      */
 53:     protected $_eventObject = 'attribute';
 54: 
 55:     const CACHE_TAG         = 'EAV_ATTRIBUTE';
 56:     protected $_cacheTag    = 'EAV_ATTRIBUTE';
 57: 
 58:     /**
 59:      * Retreive default attribute backend model by attribute code
 60:      *
 61:      * @return string
 62:      */
 63:     protected function _getDefaultBackendModel()
 64:     {
 65:         switch ($this->getAttributeCode()) {
 66:             case 'created_at':
 67:                 return 'eav/entity_attribute_backend_time_created';
 68: 
 69:             case 'updated_at':
 70:                 return 'eav/entity_attribute_backend_time_updated';
 71: 
 72:             case 'store_id':
 73:                 return 'eav/entity_attribute_backend_store';
 74: 
 75:             case 'increment_id':
 76:                 return 'eav/entity_attribute_backend_increment';
 77:         }
 78: 
 79:         return parent::_getDefaultBackendModel();
 80:     }
 81: 
 82:     /**
 83:      * Retreive default attribute frontend model
 84:      *
 85:      * @return string
 86:      */
 87:     protected function _getDefaultFrontendModel()
 88:     {
 89:         return parent::_getDefaultFrontendModel();
 90:     }
 91: 
 92:     /**
 93:      * Retreive default attribute source model
 94:      *
 95:      * @return string
 96:      */
 97:     protected function _getDefaultSourceModel()
 98:     {
 99:         if ($this->getAttributeCode() == 'store_id') {
100:             return 'eav/entity_attribute_source_store';
101:         }
102:         return parent::_getDefaultSourceModel();
103:     }
104: 
105:     /**
106:      * Delete entity
107:      *
108:      * @return Mage_Eav_Model_Resource_Entity_Attribute
109:      */
110:     public function deleteEntity()
111:     {
112:         return $this->_getResource()->deleteEntity($this);
113:     }
114: 
115:     /**
116:      * Load entity_attribute_id into $this by $this->attribute_set_id
117:      *
118:      * @return Mage_Core_Model_Abstract
119:      */
120:     public function loadEntityAttributeIdBySet()
121:     {
122:         // load attributes collection filtered by attribute_id and attribute_set_id
123:         $filteredAttributes = $this->getResourceCollection()
124:             ->setAttributeSetFilter($this->getAttributeSetId())
125:             ->addFieldToFilter('entity_attribute.attribute_id', $this->getId())
126:             ->load();
127:         if (count($filteredAttributes) > 0) {
128:             // getFirstItem() can be used as we can have one or zero records in the collection
129:             $this->setEntityAttributeId($filteredAttributes->getFirstItem()->getEntityAttributeId());
130:         }
131:         return $this;
132:     }
133: 
134:     /**
135:      * Prepare data for save
136:      *
137:      * @return Mage_Eav_Model_Entity_Attribute
138:      */
139:     protected function _beforeSave()
140:     {
141:         // prevent overriding product data
142:         if (isset($this->_data['attribute_code'])
143:             && Mage::getModel('catalog/product')->isReservedAttribute($this))
144:         {
145:             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
146:         }
147: 
148:         /**
149:          * Check for maximum attribute_code length
150:          */
151:         if (isset($this->_data['attribute_code']) &&
152:             !Zend_Validate::is(
153:                 $this->_data['attribute_code'],
154:                 'StringLength',
155:                 array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH)
156:             )
157:         ) {
158:             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
159:         }
160: 
161:         $defaultValue   = $this->getDefaultValue();
162:         $hasDefaultValue = ((string)$defaultValue != '');
163: 
164:         if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
165:             $locale = Mage::app()->getLocale()->getLocaleCode();
166:             if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => $locale))) {
167:                  throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value'));
168:             }
169: 
170:             try {
171:                 $filter = new Zend_Filter_LocalizedToNormalized(
172:                     array('locale' => Mage::app()->getLocale()->getLocaleCode())
173:                 );
174:                 $this->setDefaultValue($filter->filter($defaultValue));
175:             } catch (Exception $e) {
176:                 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value'));
177:             }
178:         }
179: 
180:         if ($this->getBackendType() == 'datetime') {
181:             if (!$this->getBackendModel()) {
182:                 $this->setBackendModel('eav/entity_attribute_backend_datetime');
183:             }
184: 
185:             if (!$this->getFrontendModel()) {
186:                 $this->setFrontendModel('eav/entity_attribute_frontend_datetime');
187:             }
188: 
189:             // save default date value as timestamp
190:             if ($hasDefaultValue) {
191:                 $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
192:                 try {
193:                     $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
194:                     $this->setDefaultValue($defaultValue);
195:                 } catch (Exception $e) {
196:                     throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default date'));
197:                 }
198:             }
199:         }
200: 
201:         if ($this->getBackendType() == 'gallery') {
202:             if (!$this->getBackendModel()) {
203:                 $this->setBackendModel('eav/entity_attribute_backend_media');
204:             }
205:         }
206: 
207:         return parent::_beforeSave();
208:     }
209: 
210:     /**
211:      * Save additional data
212:      *
213:      * @return Mage_Eav_Model_Entity_Attribute
214:      */
215:     protected function _afterSave()
216:     {
217:         $this->_getResource()->saveInSetIncluding($this);
218:         return parent::_afterSave();
219:     }
220: 
221:     /**
222:      * Detect backend storage type using frontend input type
223:      *
224:      * @return string backend_type field value
225:      * @param string $type frontend_input field value
226:      */
227:     public function getBackendTypeByInput($type)
228:     {
229:         $field = null;
230:         switch ($type) {
231:             case 'text':
232:             case 'gallery':
233:             case 'media_image':
234:             case 'multiselect':
235:                 $field = 'varchar';
236:                 break;
237: 
238:             case 'image':
239:             case 'textarea':
240:                 $field = 'text';
241:                 break;
242: 
243:             case 'date':
244:                 $field = 'datetime';
245:                 break;
246: 
247:             case 'select':
248:             case 'boolean':
249:                 $field = 'int';
250:                 break;
251: 
252:             case 'price':
253:                 $field = 'decimal';
254:                 break;
255:         }
256: 
257:         return $field;
258:     }
259: 
260:     /**
261:      * Detect default value using frontend input type
262:      *
263:      * @return string default_value field value
264:      * @param string $type frontend_input field name
265:      */
266:     public function getDefaultValueByInput($type)
267:     {
268:         $field = '';
269:         switch ($type) {
270:             case 'select':
271:             case 'gallery':
272:             case 'media_image':
273:                 break;
274:             case 'multiselect':
275:                 $field = null;
276:                 break;
277: 
278:             case 'text':
279:             case 'price':
280:             case 'image':
281:                 $field = 'default_value_text';
282:                 break;
283: 
284:             case 'textarea':
285:                 $field = 'default_value_textarea';
286:                 break;
287: 
288:             case 'date':
289:                 $field = 'default_value_date';
290:                 break;
291: 
292:             case 'boolean':
293:                 $field = 'default_value_yesno';
294:                 break;
295:         }
296: 
297:         return $field;
298:     }
299: 
300:     /**
301:      * Retreive attribute codes by frontend type
302:      *
303:      * @param string $type
304:      * @return array
305:      */
306:     public function getAttributeCodesByFrontendType($type)
307:     {
308:         return $this->getResource()->getAttributeCodesByFrontendType($type);
309:     }
310: 
311:     /**
312:      * Return array of labels of stores
313:      *
314:      * @return array
315:      */
316:     public function getStoreLabels()
317:     {
318:         if (!$this->getData('store_labels')) {
319:             $storeLabel = $this->getResource()->getStoreLabelsByAttributeId($this->getId());
320:             $this->setData('store_labels', $storeLabel);
321:         }
322:         return $this->getData('store_labels');
323:     }
324: 
325:     /**
326:      * Return store label of attribute
327:      *
328:      * @return string
329:      */
330:     public function getStoreLabel($storeId = null)
331:     {
332:         if ($this->hasData('store_label')) {
333:             return $this->getData('store_label');
334:         }
335:         $store = Mage::app()->getStore($storeId);
336:         $label = false;
337:         if (!$store->isAdmin()) {
338:             $labels = $this->getStoreLabels();
339:             if (isset($labels[$store->getId()])) {
340:                 return $labels[$store->getId()];
341:             }
342:         }
343:         return $this->getFrontendLabel();
344:     }
345: }
346: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0