Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a site,store and view programmatically in magento

Tags:

magento

I am trying to create a website, store and view programmatically. I found this code:

$websiteModel = Mage::getModel('core/website');

$postData = array();
$postData['website']['name'] = 'Store Name';
$postData['website']['code'] = 'store_name';
$postData['website']['sort_order'] = '';
//$postData['website']['is_default'] = '';
$postData['website']['website_id'] = '';

$websiteModel->setData($postData['website']);

Would something like that work? Also what would be the models associated with store and view?

like image 378
Nithin Avatar asked Nov 29 '11 10:11

Nithin


People also ask

What is difference between store and store view in Magento?

Stores can be used to define for example different (looking) stores with the same information. Store Views are mostly used to handle different languages on your website. You will typically have one Store View per language. You can also have different base currency and prices on website level.

What is store view in Magento 2?

What is the store view in Magento 2? In Magento 2 you can create a website with multiple stores different in design, purpose, products, etc. Store Views correspondingly are the variations of the same store in different languages. Every Magento 2 store initially has a default store view.


1 Answers

Use this code:

//#addWebsite
    /** @var $website Mage_Core_Model_Website */
    $website = Mage::getModel('core/website');
    $website->setCode('<your_website_code_here>')
        ->setName('<your_website_name>')
        ->save();

//#addStoreGroup
    /** @var $storeGroup Mage_Core_Model_Store_Group */
    $storeGroup = Mage::getModel('core/store_group');
    $storeGroup->setWebsiteId($website->getId())
        ->setName('<your_store_name>')
        ->setRootCategoryId('<needed_root_category_id>')
        ->save();

//#addStore
    /** @var $store Mage_Core_Model_Store */
    $store = Mage::getModel('core/store');
    $store->setCode('<your_store_view_code_here>')
        ->setWebsiteId($storeGroup->getWebsiteId())
        ->setGroupId($storeGroup->getId())
        ->setName('<your_store_view_name>')
        ->setIsActive(1)
        ->save();

If you need do it from frontend - add line Mage::registry('isSecureArea'); before this code.

like image 168
Dmytro Zavalkin Avatar answered Oct 24 '22 12:10

Dmytro Zavalkin