/**
  * Set required fields before saving model
  *
  * @param Mage_Core_Model_Abstract $object
  * @return $this
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getDisplayName()) {
         if (!$object->getFrontendLabel()) {
             throw new Exception(Mage::helper('attributeSplash')->__('Splash object must have a name'));
         } else {
             $object->setDisplayName($object->getFrontendLabel());
         }
     }
     if ($object->getCategoryId()) {
         $category = Mage::getModel('catalog/category')->load($object->getCategoryId());
         if (!$category->getId()) {
             $object->setCategoryId(null);
         }
     } else {
         $object->setCategoryId(null);
     }
     if (!$object->getUrlKey()) {
         $object->setUrlKey($object->getname());
     }
     $object->setUrlKey($this->formatUrlKey($object->getUrlKey()));
     $object->setUpdatedAt(now());
     if (!$object->getCreatedAt()) {
         $object->setCreatedAt(now());
     }
     return parent::_beforeSave($object);
 }
 /**
  * Set required fields before saving model
  *
  * @param Mage_Core_Model_Abstract $object
  * @return $this
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getDisplayName()) {
         if (!$object->getFrontendLabel()) {
             throw new Exception(Mage::helper('attributeSplash')->__('Splash object must have a name'));
         } else {
             $object->setDisplayName($object->getFrontendLabel());
         }
     }
     if ($object->getCategoryId()) {
         $category = Mage::getModel('catalog/category')->load($object->getCategoryId());
         if (!$category->getId()) {
             $object->setCategoryId(null);
         }
     } else {
         $object->setCategoryId(null);
     }
     if (!$object->getUrlKey()) {
         $object->setUrlKey($object->getname());
     }
     $object->setUrlKey($this->formatUrlKey($object->getUrlKey()));
     $object->setUpdatedAt(now());
     if (!$object->getCreatedAt()) {
         $object->setCreatedAt(now());
     }
     if (is_array($object->getCustomFields())) {
         $customFields = array();
         foreach ($object->getCustomFields() as $field => $value) {
             if (trim($value) !== '') {
                 $customFields[$field] = $value;
             }
         }
         if (count($customFields) > 0) {
             $object->setCustomFields(serialize($customFields));
         } else {
             $object->setCustomFIelds('');
         }
     }
     return parent::_beforeSave($object);
 }
Пример #3
0
 /**
  * Validate attribute data before save
  *
  * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Resource_Entity_Attribute
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $frontendLabel = $object->getFrontendLabel();
     if (is_array($frontendLabel)) {
         if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') {
             Mage::throwException($this->_helper('Mage_Eav_Helper_Data')->__('Frontend label is not defined'));
         }
         $object->setFrontendLabel($frontendLabel[0])->setStoreLabels($frontendLabel);
     }
     /**
      * @todo need use default source model of entity type !!!
      */
     if (!$object->getId()) {
         if ($object->getFrontendInput() == 'select') {
             $object->setSourceModel('Mage_Eav_Model_Entity_Attribute_Source_Table');
         }
     }
     return parent::_beforeSave($object);
 }
Пример #4
0
 public function loadFromAttribute(Mage_Core_Model_Abstract $object, $attribute_code = null, $option_id = null, $store_id = null)
 {
     $read = $this->_getReadAdapter();
     if ($read && !is_null($attribute_code)) {
         $select = $read->select()->from(array('main_table' => $this->getMainTable()))->joinRight(array('aov' => $this->getTable('eav/attribute_option_value')), 'aov.option_id = main_table.attribute_option_id AND aov.store_id = main_table.attribute_value_store_id', array('value_id', 'value', 'store_id', 'option_id'))->join(array('ao' => $this->getTable('eav/attribute_option')), 'ao.option_id = aov.option_id', array())->join(array('a' => $this->getTable('eav/attribute')), 'a.attribute_id = ao.attribute_id', array('attribute_code', 'frontend_label'))->where('a.attribute_code = ?', $attribute_code)->where('ao.option_id = ?', $option_id)->where('aov.store_id in (0, ?)', $store_id)->order('aov.store_id DESC');
         $data = $read->fetchRow($select);
         if ($data) {
             $object->setData($data);
             //set the default values for the new info page, extracted from the attribute values
             if (!$object->getData('name')) {
                 $object->setData('name', __('Products by %s: %s', $object->getFrontendLabel(), $object->getValue()));
             }
             if (!$object->getData('external_url_label')) {
                 $object->setData('external_url_label', __('Visit %s on the web', $object->getValue()));
             }
             if (!$object->getData('identifier')) {
                 $object->setData('identifier', $this->formatUrlKey($object->getValue()));
             }
         }
     }
     $this->_afterLoad($object);
     return $this;
 }
 /**
  * Enter description here...
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     $frontendLabel = $object->getFrontendLabel();
     if (is_array($frontendLabel)) {
         if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') {
             AO::throwException(AO::helper('eav')->__('Frontend label is not defined'));
         }
         $object->setFrontendLabel($frontendLabel[0]);
         if ($object->getData('modulePrefix')) {
             $str = $object->getData('modulePrefix') . Mage_Core_Model_Translate::SCOPE_SEPARATOR . $frontendLabel[0];
         } else {
             $str = $frontendLabel[0];
         }
         AO::getModel('core/translate_string')->setString($str)->setTranslate($frontendLabel[0])->setStoreTranslations($frontendLabel)->save();
     }
     $applyTo = $object->getApplyTo();
     if (is_array($applyTo)) {
         $object->setApplyTo(implode(',', $applyTo));
     }
     /**
      * @todo need use default source model of entity type !!!
      */
     if (!$object->getId()) {
         if ($object->getFrontendInput() == 'select') {
             $object->setSourceModel('eav/entity_attribute_source_table');
         }
     }
     return parent::_beforeSave($object);
 }