text Crear un nuevo tipo de attribute Set

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Crear un nuevo tipo de attribute Set相关的知识,希望对你有一定的参考价值。

<?php

namespace Daytours\TransferProduct\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Registry;

use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\ObjectManagerInterface;
use \Magento\Catalog\Setup\CategorySetupFactory;


class InstallData implements InstallDataInterface
{
     /**
     * @var Registry
     */
    protected $_registry;

    /**
     * @var EavSetupFactory
     */
    protected $_eavSetupFactory;
    /**
     * @var ObjectManagerInterface
     */
    private $objectManager;

    
    /**
     * InstallData constructor.
     * @param Registry $registry
     * @param EavSetupFactory $eavSetupFactory
     * @param ObjectManagerInterface $objectManager
     * @param CategorySetupFactory $categorySetupFactory
     */

    public function __construct(
        Registry $registry,
        EavSetupFactory $eavSetupFactory,
        ObjectManagerInterface $objectManager,
        CategorySetupFactory $categorySetupFactory)
    {

        $this->_registry = $registry;
        $this->_eavSetupFactory = $eavSetupFactory;
        $this->objectManager = $objectManager;
        
    }

    /**
     * Installs data for a module
     *
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     * @return void
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $this->addAttributeSetTransfer($setup);
        $this->createProductType($setup);

        $setup->endSetup();
    }


    /**
     * Add attribute set transfer
     *
     * @return void
     */
    protected function addAttributeSetTransfer($setup)
    {
        $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);
        $entityTypeId = $eavSetup->getEntityTypeId('catalog_product');
        $defaultSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId);
        $data = [
            'attribute_set_name' => 'Transfer',
            'entity_type_id' => $entityTypeId,
            'sort_order' => 0
        ];
        $transferSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
        if (!$transferSet) {
            $transferSet = $this->objectManager->create(AttributeSet::class);
            $transferSet->setData($data);
            $transferSet->validate();
            $transferSet->save();
            $transferSet->initFromSkeleton($defaultSetId);
            $transferSet->save();
        }
    }

}

以上是关于text Crear un nuevo tipo de attribute Set的主要内容,如果未能解决你的问题,请参考以下文章

php Crear un nuevo controlador en Laravel,dentro de una subcarpeta

text Solicitud de blogs,solicitar nuevo blog autorizacion cau crear

sql Crear nuevo usuario Oracle

text META crear un tag meta escalable响应

javascript Agregar un nuevo菜单

sql Reemplazar un site url viejo por una nuevo ya sea porque se hizo un deploy de localhost al site