本文介绍了如何在 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']);

这样的事情行得通吗?另外,与 store 和 view 相关联的模型是什么?

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

推荐答案

使用此代码:

//#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();

如果您需要从前端执行 - 在此代码之前添加行 Mage::registry('isSecureArea');.

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

这篇关于如何在 magento 中以编程方式创建站点、存储和查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:35