Setting up Multiple Websites, Stores & Views on Magento

Sep 2, 2015 2:00:05 PM

Magento is such a magical portal. The many things a developer can work with using Magento is simply inspiring. There are hardly any two thoughts raised when someones says that Magento is the most trusted eCommerce portal in the world. Even Alexa puts about 10,000 Magento sites in the world’s top 1 million sites.

That is quite a substantial number compared to Magento’s other competitors viz Prestashop, Shopify, WooCommerce etc.

Magento meta-chart

Magento users understand the potential of the technology they are using and in order to siphon maximum business benefits they use utilizing their technology to the maximum benefits. This will require many users accessing the admin panel and also working separately on multiple websites, stores and views to effectuate a sublime workflow.

In Magento, we can add multiple website, stores and store views. Normally we can easily create these from the admin panel but sometimes we are required to create a script. For example, if more than one user is working on same project then we don't prefer that every developer will create website individually in its admin. Instead of this, let they can use the installer file to create multiple website, stores and views.

New Call-to-action

Code: We are creating a website "website1", a store "store1" and store views "view_nl", "view_fr" and "view_en".

[php]//#addWebsite
/** @var $website Mage_Core_Model_Website */
$website = Mage::getModel('core/website');
$website->setCode('website1')
->setName('website1')
->save();[/php]

[php]//#addStoreGroup
/** @var $storeGroup Mage_Core_Model_Store_Group */
$storeGroup = Mage::getModel('core/store_group');
$storeGroup->setWebsiteId($website->getId())
->setName('store1')
->setRootCategoryId(2)
->save();[/php]

[php]//#addStores
/** @var $store Mage_Core_Model_Store */
$store1 = Mage::getModel('core/store');
$store1->setCode('view_nl')
->setWebsiteId($storeGroup->getWebsiteId())
->setGroupId($storeGroup->getId())
->setName('View NL')
->setIsActive(1)
->save();[/php]

[php]$store2 = Mage::getModel('core/store');
$store2->setCode('view_fr')
->setWebsiteId($storeGroup->getWebsiteId())
->setGroupId($storeGroup->getId())
->setName('View FR')
->setIsActive(1)
->save();[/php]

[php]$store3 = Mage::getModel('core/store');
$store3->setCode('view_en')
->setWebsiteId($storeGroup->getWebsiteId())
->setGroupId($storeGroup->getId())
->setName('View EN')
->setIsActive(1)
->save();[/php]

The above code will work smoothly on any Magento based portal and will most definitely accelerate your admin processes.

Magento holds a thousand wondrous secrets behind its doors, the above is just a key to unlock one of those secrets. I have been and will continue to provide you the keys to Magento’s various surprise features along with the codes to access it through my coming blog posts. So stay tuned with more news regarding Magento and other technologies by subscribing to the Daffodil blog.

Ankita Agrawal

Written by Ankita Agrawal

Ankita Agrawal is leading Magento team and providing best in class e-commerce products and aimed at client satisfaction. She is very good at innovating and implementing latest marketplace solutions. Having a great experience of providing customized and featured products, she fits best for handling higher complexity projects.