本文整理汇总了PHP中Mage_Eav_Model_Entity_Attribute_Abstract::_beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Attribute_Abstract::_beforeSave方法的具体用法?PHP Mage_Eav_Model_Entity_Attribute_Abstract::_beforeSave怎么用?PHP Mage_Eav_Model_Entity_Attribute_Abstract::_beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Eav_Model_Entity_Attribute_Abstract
的用法示例。
在下文中一共展示了Mage_Eav_Model_Entity_Attribute_Abstract::_beforeSave方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
protected function _beforeSave()
{
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('eav/entity_attribute_frontend_datetime');
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_media');
}
}
if ($this->getFrontendInput() == 'price') {
if (!$this->getBackendModel()) {
$this->setBackendModel('catalog/product_attribute_backend_price');
}
}
return parent::_beforeSave();
}
示例2: _beforeSave
/**
* Prepare data for save
*
* @return Mage_Eav_Model_Entity_Attribute
* @throws Mage_Eav_Exception
*/
protected function _beforeSave()
{
/**
* Check for maximum attribute_code length
*/
if (isset($this->_data['attribute_code']) && !Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) {
throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
}
$defaultValue = $this->getDefaultValue();
$hasDefaultValue = (string) $defaultValue != '';
if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
$locale = Mage::app()->getLocale()->getLocaleCode();
if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => $locale))) {
throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value'));
}
try {
$filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
$this->setDefaultValue($filter->filter($defaultValue));
} catch (Exception $e) {
throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value'));
}
}
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('eav/entity_attribute_frontend_datetime');
}
// save default date value as timestamp
if ($hasDefaultValue) {
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
try {
$defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
$this->setDefaultValue($defaultValue);
} catch (Exception $e) {
throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default date'));
}
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_media');
}
}
return parent::_beforeSave();
}
示例3: _beforeSave
/**
* Prepare data for save
*
* @return Mage_Eav_Model_Entity_Attribute
*/
protected function _beforeSave()
{
// prevent overriding product data
if (isset($this->_data['attribute_code']) && Mage::getModel('Mage_Catalog_Model_Product')->isReservedAttribute($this)) {
throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
}
/**
* Check for maximum attribute_code length
*/
if (isset($this->_data['attribute_code']) && !Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) {
throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
}
$defaultValue = $this->getDefaultValue();
$hasDefaultValue = (string) $defaultValue != '';
if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => Mage::app()->getLocale()->getLocaleCode()))) {
throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid default decimal value'));
}
try {
$filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
$this->setDefaultValue($filter->filter($defaultValue));
} catch (Exception $e) {
throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid default decimal value'));
}
}
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('Mage_Eav_Model_Entity_Attribute_Backend_Datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('Mage_Eav_Model_Entity_Attribute_Frontend_Datetime');
}
// save default date value as timestamp
if ($hasDefaultValue) {
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
try {
$defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
$this->setDefaultValue($defaultValue);
} catch (Exception $e) {
throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid default date'));
}
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('Mage_Eav_Model_Entity_Attribute_Backend_Default');
}
}
return parent::_beforeSave();
}
示例4: _beforeSave
protected function _beforeSave()
{
// prevent overriding product data
if (isset($this->_data['attribute_code']) && AO::getModel('catalog/product')->isReservedAttribute($this)) {
AO::throwException(AO::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please, try another attribute code.', $this->_data['attribute_code']));
}
// prevent changing attribute scope, if used in configurable products
if (isset($this->_origData['is_global'])) {
if (!isset($this->_data['is_global'])) {
AO::throwException('0_o');
}
if ($this->_data['is_global'] != $this->_origData['is_global'] && $this->_getResource()->isUsedBySuperProducts($this)) {
AO::throwException(AO::helper('eav')->__('Scope must not be changed, because the attribute is used in configurable products.'));
}
}
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('eav/entity_attribute_frontend_datetime');
}
// save default date value as timestamp
if ($defaultValue = $this->getDefaultValue()) {
$format = AO::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$this->setDefaultValue(AO::app()->getLocale()->date($defaultValue, $format, null, false)->toValue());
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_media');
}
}
if ($this->getFrontendInput() == 'price') {
if (!$this->getBackendModel()) {
$this->setBackendModel('catalog/product_attribute_backend_price');
}
}
return parent::_beforeSave();
}
示例5: _beforeSave
protected function _beforeSave()
{
// prevent overriding product data
if (isset($this->_data['attribute_code']) && Mage::getModel('catalog/product')->isReservedAttribute($this)) {
Mage::throwException(Mage::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code.', $this->_data['attribute_code']));
}
$defaultValue = $this->getDefaultValue();
$hasDefaultValue = (string) $defaultValue != '';
if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => Mage::app()->getLocale()->getLocaleCode()))) {
throw new Exception('Invalid default decimal value.');
}
try {
$filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
$this->setDefaultValue($filter->filter($defaultValue));
} catch (Exception $e) {
throw new Exception('Invalid default decimal value.');
}
}
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('eav/entity_attribute_frontend_datetime');
}
// save default date value as timestamp
if ($hasDefaultValue) {
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
try {
$defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
$this->setDefaultValue($defaultValue);
} catch (Exception $e) {
throw new Exception('Invalid default date.');
}
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_media');
}
}
return parent::_beforeSave();
}
示例6: _beforeSave
protected function _beforeSave()
{
// prevent overriding product data
if (isset($this->_data['attribute_code']) && Mage::getModel('catalog/product')->isReservedAttribute($this)) {
Mage::throwException(Mage::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please, try another attribute code.', $this->_data['attribute_code']));
}
if ($this->getBackendType() == 'datetime') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_datetime');
}
if (!$this->getFrontendModel()) {
$this->setFrontendModel('eav/entity_attribute_frontend_datetime');
}
// save default date value as timestamp
if ($defaultValue = $this->getDefaultValue()) {
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
try {
$defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
$this->setDefaultValue($defaultValue);
} catch (Exception $e) {
throw new Exception("Invalid default date.");
}
}
}
if ($this->getBackendType() == 'gallery') {
if (!$this->getBackendModel()) {
$this->setBackendModel('eav/entity_attribute_backend_media');
}
}
return parent::_beforeSave();
}