Архив метки: attribute

Добавить атрибут изображения в категорию в Magento 2

Добавить атрибут изображения в категорию в Magento 2 Здесь рассмотрим, как добавить пользовательский атрибут изображения в категорию. Шаг 1 Создайте файл InstallData.php в папке vendor \ Module \ Setup <?php namespace Vendor\Module\Setup; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; /** * @codeCoverageIgnore */ class InstallData implements InstallDataInterface { /** * EAV setup factory. * * @var EavSetupFactory */ private $_eavSetupFactory; protected $categorySetupFactory; /** * Init. * * @param EavSetupFactory $eavSetupFactory */ public function __construct(EavSetupFactory $eavSetupFactory, \Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory) { $this->_eavSetupFactory = $eavSetupFactory; $this->categorySetupFactory = $categorySetupFactory; } /** * {@inheritdoc} * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) { /** @var EavSetup $eavSetup */ $eavSetup = $this->_eavSetupFactory->create([‘setup’ => $setup]); $setup = $this->categorySetupFactory->create([‘setup’ => $setup]); $setup->addAttribute( \Magento\Catalog\Model\Category::ENTITY, ‘custom_image’, [ ‘type’ => ‘varchar’, ‘label’ => ‘Custom Image’, ‘input’ => ‘image’, ‘backend’ => ‘Magento\Catalog\Model\Category\Attribute\Backend\Image’, ‘required’ => false, ‘sort_order’ => 9, ‘global’ => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, ‘group’ => ‘General… Читать далее »

Как программно добавить атрибут категории в Magento 2

Как программно добавить атрибут категории в Magento 2 Создать файл InstallData.php Мы начнем с класса InstallData, который находится в app / code / Mageplaza / HelloWorld / Setup / InstallData.php. Содержание для этого файла: <?php namespace Mageplaza\HelloWorld\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; } } Определите метод install () <?php public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { } Создайте атрибут категории программно <?php namespace Mageplaza\HelloWorld\Setup; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Eav\Setup\EavSetupFactory; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; } public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) { $eavSetup = $this->eavSetupFactory->create([‘setup’ => $setup]); $eavSetup->addAttribute( \Magento\Catalog\Model\Category::ENTITY, ‘mp_new_attribute’, [ ‘type’ => ‘varchar’, ‘label’ => ‘Mageplaza Attribute’, ‘input’ => ‘text’, ‘sort_order’ => 100, ‘source’ => », ‘global’ => 1, ‘visible’ => true, ‘required’ => false, ‘user_defined’… Читать далее »