本文整理匯總了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);
}