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

前端 未结 1 570
臣服心动
臣服心动 2020-12-31 13:01

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

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

$postData = array();
         


        
相关标签:
1条回答
  • 2020-12-31 13:50

    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.

    0 讨论(0)
提交回复
热议问题