Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento 2-如何基于默认值创建属性集_Php_Magento2_Magento 2.0 - Fatal编程技术网

Php Magento 2-如何基于默认值创建属性集

Php Magento 2-如何基于默认值创建属性集,php,magento2,magento-2.0,Php,Magento2,Magento 2.0,我目前有以下创建新属性集的代码: use Magento\Framework\ObjectManagerInterface; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; class AttributeModel extends \Magento\Framework\Model\AbstractModel { const ENTITY_TYPE

我目前有以下创建新属性集的代码:

use Magento\Framework\ObjectManagerInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class AttributeModel extends \Magento\Framework\Model\AbstractModel
{

    const ENTITY_TYPE = \Magento\Catalog\Model\Product::ENTITY;

    protected $_objectManager;
    protected $_moduleDataSetup;
    protected $_eavSetupFactory;

    public function __construct(
        ObjectManagerInterface $objectManager,
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory,
    ) {

        $this->_objectManager = $objectManager;
        $this->_moduleDataSetup = $moduleDataSetup;
        $this->_eavSetupFactory = $eavSetupFactory;

    }

    public function createSet($name)
    {

        $eavSetup = $this->_eavSetupFactory->create([
            'setup' => $this->_moduleDataSetup
        ]);

        $eavSetup->addAttributeSet(self::ENTITY_TYPE, $name, 0);

    }

}
但是,该集没有指定属性。如何基于默认设置创建集合,以便使用基本属性预先填充集合


非常感谢您的帮助。

事实证明AttributeSetManagementInterface模型有一个create函数,该函数接受一个可选的骨架ID,新集合可以基于该ID。我最终使用objectManager进行快速修复,我相信有更好的方法

下面对上述操作代码进行了扩展:

public function createSet($name)
{

    $eavSetup = $this->_eavSetupFactory->create([
        'setup' => $this->_moduleDataSetup
    ]);

    $defaultId = $eavSetup->getDefaultAttributeSetId(self::ENTITY_TYPE);

    $model = $this->_objectManager
    ->create('Magento\Eav\Api\Data\AttributeSetInterface')
    ->setId(null)
    ->setEntityTypeId(4)
    ->setAttributeSetName($name);

    $this->_objectManager
    ->create('Magento\Eav\Api\AttributeSetManagementInterface')
    ->create(self::ENTITY_TYPE, $model, $defaultId)
    ->save();

}