本文介绍了如何在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?

推荐答案

使用以下代码:

//#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-11 14:50