标签:creat ++ this mod 属性 code set eid gen
1、根据获取attribute_code来获取attribute id
$attr = $this->_objectManager->create(‘Magento\Eav\Model\ResourceModel\Entity\Attribute‘); $attributeId = $attr->getIdByCode(‘catalog_product‘, ‘brand‘);
注释:catalog_product代表属性实体类型,brand代表属性code
2、实例化eav Model类型
$eav = $this->_objectManager->create(‘Magento\Eav\Setup\EavSetup‘);
3、构建option数组
$options=array(‘option1‘,‘option2‘,‘option3‘,.....); for($i=0;$i<count($options);$i++){ $option[‘order‘][‘option‘.$i] =$i;/*option的sort_order*/ $option[‘value‘][‘option‘.$i][0] = $options[$i];/*option后台显示lable*/ $option[‘value‘][‘option‘.$i][1] = $options[$i];/*option前台显示lable*/ }
4、添加option
$eav->addAttributeOption($option);
5、应该就ok了!
标签:creat ++ this mod 属性 code set eid gen
原文地址:http://www.cnblogs.com/dongtong/p/6516067.html