本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Attribute::save方法的具体用法?PHP Attribute::save怎么用?PHP Attribute::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute
的用法示例。
在下文中一共展示了Attribute::save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveAttribute
private function saveAttribute()
{
if ($this->attributeObj->getId()) {
return array('result' => true, 'obj' => $this->attributeObj);
}
if (!$this->validate()) {
return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
}
$this->attributeObj = $this->catalogAttributeFactory->create();
$data = $this->params;
$data['attribute_code'] = $this->code;
$data['frontend_label'] = array(\Magento\Store\Model\Store::DEFAULT_STORE_ID => $this->primaryLabel);
$data['frontend_input'] = $this->inputType;
$data['entity_type_id'] = $this->entityTypeId;
$data['is_user_defined'] = 1;
$data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($this->inputType);
$data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($this->inputType);
$data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType);
!isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE);
!isset($data['is_configurable']) && ($data['is_configurable'] = 0);
!isset($data['is_filterable']) && ($data['is_filterable'] = 0);
!isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0);
!isset($data['apply_to']) && ($data['apply_to'] = array());
$this->prepareOptions($data);
$this->prepareDefault($data);
$this->attributeObj->addData($data);
try {
$this->attributeObj->save();
} catch (\Exception $e) {
return array('result' => false, 'error' => $e->getMessage());
}
return array('result' => true, 'obj' => $this->attributeObj);
}