本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getBackendType方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAttribute::getBackendType方法的具体用法?PHP AbstractAttribute::getBackendType怎么用?PHP AbstractAttribute::getBackendType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute\AbstractAttribute
的用法示例。
在下文中一共展示了AbstractAttribute::getBackendType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAttributeType
/**
* 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: prepareValue
/**
* @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: _prepareValueForSave
/**
* 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: getAttributeType
/**
* 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();
}
}