/** * Prepare value for save * * @param mixed $value * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @return mixed */ protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute) { $type = $attribute->getBackendType(); if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') { $value = null; } return parent::_prepareValueForSave($value, $attribute); }
/** * Prepare value for save * * @param mixed $value * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @return mixed */ protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute) { if ($attribute->getBackendType() == 'decimal') { return Mage::app()->getLocale()->getNumber($value); } $backendTable = $attribute->getBackendTable(); if (!isset(self::$_attributeBackendTables[$backendTable])) { self::$_attributeBackendTables[$backendTable] = $this->_getReadAdapter()->describeTable($backendTable); } $describe = self::$_attributeBackendTables[$backendTable]; return $this->_getReadAdapter()->prepareColumnValue($describe['value'], $value); }
/** * Get attribute type for upcoming validation. * * @param Mage_Eav_Model_Entity_Attribute_Abstract|Mage_Eav_Model_Entity_Attribute $attribute * @return string */ public static function getAttributeType(Mage_Eav_Model_Entity_Attribute_Abstract $attribute) { if ($attribute->usesSource()) { return $attribute->getFrontendInput() == 'multiselect' ? 'multiselect' : 'select'; } elseif ($attribute->isStatic()) { return $attribute->getFrontendInput() == 'date' ? 'datetime' : 'varchar'; } else { return $attribute->getBackendType(); } }
/** * Prepare value for save * * @param mixed $value * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @return mixed */ protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute) { if ($attribute->getBackendType() == 'decimal') { return Mage::app()->getLocale()->getNumber($value); } return $value; }
/** * Prepare value for save * * @param mixed $value * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @return mixed */ protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute) { $type = $attribute->getBackendType(); if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') { return null; } if ($type == 'decimal') { return Mage::app()->getLocale()->getNumber($value); } return $value; }
/** * Ensure values are OK for numeric attributes before saving them * * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute Attribute to prepare the value for * @param mixed $value Value to be saved * * @return mixed The value ready for save */ protected function _prepareValueForDocumentSave($attribute, $value) { if (is_object($value)) { $value = (string) $value; } if ($value != '') { $type = strtolower($attribute->getBackendType()); // Handle numeric cast to float $value = $this->_prepareTableValueForSave($value, $attribute->getBackendType()); if ($type == "int") { // Ensure int storage is correct $value = (int) $value; } } return $value; }