1

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');

Mage::unregister('isSecureArea');
0

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();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

/** @var $rootCategory Mage_Catalog_Model_Category */
$rootCategory = Mage::getModel('catalog/category');
$rootCategory->setName('UK Root Category')
    ->setPath('1')
    ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
    ->save();

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

/** @var $storeGroup Mage_Core_Model_Store_Group */
$storeGroup = Mage::getModel('core/store_group');
$storeGroup->setWebsiteId($website->getId())
    ->setName('Default')
    ->setRootCategoryId($rootCategory->getId())
    ->save();

/** @var $store Mage_Core_Model_Store */
$store = Mage::getModel('core/store');
$store->setCode('en_uk')
    ->setWebsiteId($storeGroup->getWebsiteId())
    ->setGroupId($storeGroup->getId())
    ->setName('UK - English')
    ->setIsActive(1)
    ->save();

//Set store to original value
Mage::app()->setCurrentStore($originalStoreId);

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.

0

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.

<?php
require_once ( "app/Mage.php" );
Mage::app();

$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)
            ->save();


//create storeView
$storeViewModel->setCode('newcode')
                ->setWebsiteId(YOUR WEBSITE ID)
                ->setGroupId($storeGroup->getId())
                ->setName('New Store View')
                ->setSortOrder(0)
                ->setIsActive(1)
                ->save();


//rename the website, store, store_group
$websiteModel->load('base','code')->setName('Main');
$websiteModel->save();

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

$storeGroupModel->load($storeViewModel->load('default','code')->getId())->setName('Main store Group');
$storeGroupModel->save();
  • 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.