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()
            ->get('Magento\Store\Model\GroupFactory');
$groupResourceModel = \Magento\Framework\App\ObjectManager::getInstance()
            ->get('use Magento\Store\Model\ResourceModel\Group');
$group = $groupFactory->create();

$group->setWebsiteId(1);
$group->setName('Custom Store Group Name');
$group->setRootCategoryId(2);
$group->setDefaultStoreId(3); $groupResourceModel->save($group);
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments