Пример #1
0
 /**
  * Get attribute type for upcoming validation.
  *
  * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|\Magento\Eav\Model\Entity\Attribute $attribute
  * @return string
  */
 public static function getAttributeType(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
 {
     $frontendInput = $attribute->getFrontendInput();
     if ($attribute->usesSource() && in_array($frontendInput, ['select', 'multiselect', 'boolean'])) {
         return $frontendInput;
     } elseif ($attribute->isStatic()) {
         return $frontendInput == 'date' ? 'datetime' : 'varchar';
     } else {
         return $attribute->getBackendType();
     }
 }
Пример #2
0
 /**
  * @param string $entityType
  * @param string $value
  * @param AbstractAttribute $attribute
  * @return string
  * @throws \Exception
  */
 protected function prepareValue($entityType, $value, AbstractAttribute $attribute)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $type = $attribute->getBackendType();
     if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') {
         $value = null;
     } elseif ($type == 'decimal') {
         $value = $this->localeFormat->getNumber($value);
     }
     $describe = $metadata->getEntityConnection()->describeTable($attribute->getBackendTable());
     return $metadata->getEntityConnection()->prepareColumnValue($describe['value'], $value);
 }
Пример #3
0
 /**
  * Prepare value for save
  *
  * @param mixed $value
  * @param AbstractAttribute $attribute
  * @return mixed
  */
 protected function _prepareValueForSave($value, AbstractAttribute $attribute)
 {
     $type = $attribute->getBackendType();
     if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') {
         $value = null;
     } elseif ($type == 'decimal') {
         $value = $this->_localeFormat->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);
 }
Пример #4
0
 /**
  * Get attribute type for upcoming validation.
  *
  * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|\Magento\Eav\Model\Entity\Attribute $attribute
  * @return string
  */
 public static function getAttributeType(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
 {
     if ($attribute->usesSource()) {
         return $attribute->getFrontendInput() == 'multiselect' ? 'multiselect' : 'select';
     } elseif ($attribute->isStatic()) {
         return $attribute->getFrontendInput() == 'date' ? 'datetime' : 'varchar';
     } else {
         return $attribute->getBackendType();
     }
 }