Skip to content

Instantly share code, notes, and snippets.

@predavlad
Last active March 7, 2018 15:16
Show Gist options
  • Save predavlad/7ded820f10d5c2bd9973176b0f3b8079 to your computer and use it in GitHub Desktop.
Save predavlad/7ded820f10d5c2bd9973176b0f3b8079 to your computer and use it in GitHub Desktop.
Move stores to newly created websites
<?php
require_once "app/Mage.php";
Mage::app();
$storeCodes = array('nl', 'dk', 'es', 'fr'); // new websites to be created - also used to get current store IDs
$websiteIds = array(1, 2); // existing websites (default + at)
$rooterCategoryId = 2; // root category for the storeGroup
foreach ($storeCodes as $code) {
/** @var $website Mage_Core_Model_Website */
$website = Mage::getModel('core/website');
$website->setCode("ielm_$code")
->setName('iELM ' . $code)
->save();
$websiteIds[] = $website->getId();
/** @var $storeGroup Mage_Core_Model_Store_Group */
$storeGroup = Mage::getModel('core/store_group');
$storeGroup->setWebsiteId($website->getId())
->setName("ielm_$code")
->setRootCategoryId($rooterCategoryId)
->save();
$const = 'IELM_Common_Helper_Data::STORE_ID_' . strtoupper($code); // constant with the storeID
/** @var $store Mage_Core_Model_Store */
$store = Mage::getModel('core/store')->load(constant($const));
$store->setWebsiteId($website->getId());
$store->setGroupId($storeGroup->getId());
$store->save();
}
$productIds= Mage::getResourceModel('catalog/product_collection')->getAllIds();
Mage::getModel('catalog/product_website')->addProducts($websiteIds, $productIds);
echo shell_exec('php shell/indexer.php reindexall');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment