本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::usesSource方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAttribute::usesSource方法的具体用法?PHP AbstractAttribute::usesSource怎么用?PHP AbstractAttribute::usesSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute\AbstractAttribute
的用法示例。
在下文中一共展示了AbstractAttribute::usesSource方法的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: createMetadataAttribute
/**
* @param AbstractAttribute $attribute
* @return Data\Eav\AttributeMetadata
*/
private function createMetadataAttribute($attribute)
{
$data = $this->booleanPrefixMapper($attribute->getData());
// fill options and validate rules
$data[AttributeMetadata::OPTIONS] = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : array();
$data[AttributeMetadata::VALIDATION_RULES] = $attribute->getValidateRules();
// fill scope
$data[AttributeMetadata::SCOPE] = $attribute->isScopeGlobal() ? 'global' : ($attribute->isScopeWebsite() ? 'website' : 'store');
$data[AttributeMetadata::FRONTEND_LABEL] = [];
$data[AttributeMetadata::FRONTEND_LABEL][0] = array(FrontendLabel::STORE_ID => 0, FrontendLabel::LABEL => $attribute->getFrontendLabel());
if (is_array($attribute->getStoreLabels())) {
foreach ($attribute->getStoreLabels() as $storeId => $label) {
$data[AttributeMetadata::FRONTEND_LABEL][$storeId] = array(FrontendLabel::STORE_ID => $storeId, FrontendLabel::LABEL => $label);
}
}
return $this->attributeMetadataBuilder->populateWithArray($data)->create();
}
示例3: getAttributeOptions
/**
* Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased.
*
* @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
* @return array
*/
public function getAttributeOptions(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
{
$options = [];
if ($attribute->usesSource()) {
// should attribute has index (option value) instead of a label?
$index = in_array($attribute->getAttributeCode(), $this->_indexValueAttributes) ? 'value' : 'label';
// only default (admin) store values used
$attribute->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
try {
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
foreach (is_array($option['value']) ? $option['value'] : [$option] as $innerOption) {
if (strlen($innerOption['value'])) {
// skip ' -- Please Select -- ' option
$options[$innerOption['value']] = $innerOption[$index];
}
}
}
} catch (\Exception $e) {
// ignore exceptions connected with source models
}
}
return $options;
}
示例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();
}
}