How To Create Magento 2 StoreGroup Programmatically

How can I create Magento 2’s StoreGroup programmatically, like from phtml

You can call ‘groupFactory ‘ class to create Magento 2’s Store Group and use the group resource model to save the group object. Here is the example to create a Magento 2’s store group programmatically

$groupFactory = \Magento\Framework\App\ObjectManager::getInstance()
$groupResourceModel = \Magento\Framework\App\ObjectManager::getInstance()
            ->get('use Magento\Store\Model\ResourceModel\Group');
$group = $groupFactory->create();

$group->setName('Custom Store Group Name');
$group->setDefaultStoreId(3); $groupResourceModel->save($group);

Leave a Reply

Notify of