Is it possible to have a setup script do:

  1. Rename the default website
  2. Rename the default store group
  3. Rename the default store view
  4. Add another store view to a store group
  5. Add another store group to a website

We have vagrant boxes and when we on board a new developer we need these things to occur so that we don't have to create them manually.

This is what we've got so far:

Mage::register('isSecureArea', true);
// Remove default website, store, and store view
$defaultWebsiteModel = Mage::getModel('core/website');
$defaultStoreGroupModel = Mage::getModel('core/store_group');
$defaultStoreView = Mage::getModel('core/store');


Yes, websites, store groups and stores are models like any others and you can create and modify them in install scripts.

Here is an example that creates a new website with store group, root category and store:

//Switch to admin store (workaround to successfully save a category)
$originalStoreId = Mage::app()->getStore()->getId();

/** @var $rootCategory Mage_Catalog_Model_Category */
$rootCategory = Mage::getModel('catalog/category');
$rootCategory->setName('UK Root Category')

/** @var $website Mage_Core_Model_Website */
$website = Mage::getModel('core/website');
    ->setName('UK Website')

/** @var $storeGroup Mage_Core_Model_Store_Group */
$storeGroup = Mage::getModel('core/store_group');

/** @var $store Mage_Core_Model_Store */
$store = Mage::getModel('core/store');
    ->setName('UK - English')

//Set store to original value

To rename an existing website, its default store group and store view, you can get it from the app model:

$ukWebsite = Mage::app()->getWebsite('main');
$ukWebsite->setName('New Website Name')->save();
$ukWebsite->getDefaultGroup()->setName('New Group Name')->save();
$ukWebsite->getDefaultStore()->setName('New Store Name')->save();

This should help you to do anything from your list.


The following code should create a store group, a store view(associated with new created store group) and also should rename the default website, store group and store view. Put the code under script.php in your root folder.

require_once ( "app/Mage.php" );

$websiteModel = Mage::getModel('core/website');
$storeGroupModel = Mage::getModel('core/store_group');
$storeViewModel = Mage::getModel('core/store');

//create storeGroup
$storeGroup = Mage::getModel('core/store_group');
$storeGroup->setWebsiteId(YOUR WEBSITE ID)
            ->setName('New Store Group')
            ->setRootCategoryId(YOUR CATEGORY ID)

//create storeView
                ->setWebsiteId(YOUR WEBSITE ID)
                ->setName('New Store View')

//rename the website, store, store_group

$storeViewModel->load('default','code')->setName('Main store View');

$storeGroupModel->load($storeViewModel->load('default','code')->getId())->setName('Main store Group');
  • is there an advantage of doing it this way over a setup script? – Stephen Johnston Mar 8 '16 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.