-
-
Save avoelkl/47f5c85ed9960931c409 to your computer and use it in GitHub Desktop.
Magento script to create a new Website, new Store Group, new Store View and new Root Catalog - all linked together.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = 'Shop:Name'; | |
$code = 'shop'; | |
// Create the root catalog | |
$category = Mage::getModel('catalog/category'); | |
$category->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$category->setData('name', $name); | |
$category->setData('url_key', $code); | |
$category->setData('display_mode', 'PRODUCTS'); | |
$category->setData('level', 1); | |
$category->setData('is_active', 1); | |
$category->setData('include_in_menu', 1); | |
$category->setData('is_anchor', 0); | |
$category->setData('custom_use_parent_settings', 0); | |
$category->setData('custom_apply_to_products', 0); | |
$category->setData('attribute_set_id', $category->getDefaultAttributeSetId()); | |
$category->save(); | |
$category->setParentId(1); | |
$category->setPath('1/'.$category->getId()); | |
$category->save(); | |
$categoryId = $category->getId(); | |
// Load the website | |
$website = Mage::getModel('core/website')->load($code, 'code'); | |
if($website->getId() > 0) { | |
$websiteId = $website->getId(); | |
$group = Mage::getModel('core/store_group')->load($websiteId, 'website_id'); | |
$group->setData('root_category_id', $category->getId()); | |
$group->save(); | |
} | |
// Create the website | |
$website->setData('name', $name); | |
$website->setData('code', $code); | |
$website->setData('sort_order', 1); | |
$website->setData('is_default', 0); | |
$website->save(); | |
$websiteId = $website->getWebsiteId(); | |
// Create the group | |
$group = Mage::getModel('core/store_group')->load($websiteId, 'website_id'); | |
$group->setData('website_id', $websiteId); | |
$group->setData('name', $name.' Shop'); | |
$group->setData('root_category_id', $category->getId()); | |
$group->save(); | |
$groupId = $group->getGroupId(); | |
// Create the store | |
$store = Mage::getModel('core/store'); | |
$store->setData('website_id', $websiteId); | |
$store->setData('group_id', $groupId); | |
$store->setData('name', $name.' Store'); | |
$store->setData('code', $code."_store"); | |
$store->setData('is_active', 1); | |
$store->save(); | |
$storeId = $store->getStoreId(); | |
// Update the website | |
$website->setData('default_group_id', $groupId); | |
$website->save(); | |
// Update the group | |
$group->setData('default_store_id', $storeId); | |
$group->save(); | |
$installer->endSetup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment