Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

magento 2 create group programmatically

<?php
namespace VendorExtensionSetup;
 
use MagentoFrameworkModuleSetupMigration;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoCustomerModelGroupFactory;
 
class InstallData implements InstallDataInterface
{
    protected $groupFactory;
 
    public function __construct(GroupFactory $groupFactory) {
        $this->groupFactory = $groupFactory;
    }
 
    public function install(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $setup->startSetup();
 
        $group = $this->groupFactory->create();
        $group
            ->setCode('New Group')
            ->setTaxClassId(3) 
            ->save();
 
        $setup->endSetup();
    }
}
Source by meetanshi.com #
 
PREVIOUS NEXT
Tagged: #magento #create #group #programmatically
ADD COMMENT
Topic
Name
2+8 =