- 02 Sep , 2015
- by Ankita Agrawal
- 0 comments
- 1128 Views
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 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.
Code: We are creating a website “website1”, a store “store1” and store views “view_nl”, “view_fr” and “view_en”.
//#addWebsite /** @var $website Mage_Core_Model_Website */ $website = Mage::getModel('core/website'); $website->setCode('website1') ->setName('website1') ->save();
//#addStoreGroup /** @var $storeGroup Mage_Core_Model_Store_Group */ $storeGroup = Mage::getModel('core/store_group'); $storeGroup->setWebsiteId($website->getId()) ->setName('store1') ->setRootCategoryId(2) ->save();
//#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();
$store2 = Mage::getModel('core/store'); $store2->setCode('view_fr') ->setWebsiteId($storeGroup->getWebsiteId()) ->setGroupId($storeGroup->getId()) ->setName('View FR') ->setIsActive(1) ->save();
$store3 = Mage::getModel('core/store'); $store3->setCode('view_en') ->setWebsiteId($storeGroup->getWebsiteId()) ->setGroupId($storeGroup->getId()) ->setName('View EN') ->setIsActive(1) ->save();
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.