久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何通過安裝腳本向 Magento 添加類別?

How to add a category to Magento via Setup script?(如何通過安裝腳本向 Magento 添加類別?)
本文介紹了如何通過安裝腳本向 Magento 添加類別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我實際上可以通過設置腳本添加一個類別,但由于某種原因,某些字段沒有正確設置.這是我的代碼

I actually can add a category via setup script, the thing is for some reason some of the fields doesn't get set properly. Here's is my code

$this->startSetup();
Mage::register('isSecureArea', 1);

$category = Mage::getModel('catalog/category');
$category->setPath('1/2') // set parent to be root category
    ->setName('Category Name')
    ->setUrlKey('category-name')
    ->setIsActive(0)
    ->setIncludeInMenu(1)
    ->setInfinitescroll(1)
    ->setDisplayMode('PAGE')
    ->setLandingPage($idToCmsBlock)
    ->setPageLayout('anotherLayoutThanDefault')
    ->setCustomUseParentSettings(0)
    ->setCustomLayoutUpdate('<reference name="head"><action method="addCss"><stylesheet>css/somecss.css</stylesheet></action></reference>')
->save();
$this->endSetup();

運行此腳本后,我創建了一個類別,其中設置了 EAV 表中的所有值.然而,即使我重新索引平面表,平面表也會缺少 displayMode、landingPage、pageLayout、customLayoutUpdate.

After running this script, I have a category created with all my value set in the EAVs table. However the Flat table will be missing displayMode, landingPage, pageLayout, customLayoutUpdate even if I re-index the flat table.

奇怪的是,如果我進入管理員,我可以看到所有這些字段都正確設置,但如果我進入我的前端,大多數這些字段都會被忽略.我將不得不轉到管理員那里,取消設置這些值并重新設置它們以使它們正常工作.

The weird thing is that if I go in the admin, I can see all those fields properly set but if I go in my frontend most of those fields are ignored. I will have to go to the admin, unset those value and reset them for each of them to work properly.

另外假設我使用 setEnabled(1),我的類別將在管理員中啟用"但不會顯示在前端.

Also let say I use setEnabled(1), my category will be "enable" in the admin but not show up in the frontend.

PS:我已激活 Flat Category,如果我禁用它似乎可以正常工作,但如果我重新索引它仍然無法正常工作.

PS: I have Flat Category activated, if I disable it seems to work fine but if I re-index it still not working.

推薦答案

我終于找到了,我不知道為什么,但那些字段沒有正確顯示,因為它們是為默認存儲 (storeId=1) 插入的,因為我的腳本正在更新腳本中運行.您需要使用 storeId 0.

I finally found it, I'm not sure why but those fields are not showing up properly because they were inserted for the default store (storeId=1) because my script is running in an update script. You need to use the storeId 0.

有了這些信息,您會認為解決方案類似于:

With this information you would think that the solution would be something like :

$this->startSetup();
Mage::register('isSecureArea', 1);

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$category = Mage::getModel('catalog/category');
$category->setPath('1/2') // set parent to be root category
    ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
    ->setName('Category Name')
    ...
    ->save();
$this->endSetup();

但是這段代碼也不起作用.事實上,在查看 Mage::app()(Mage_Core_Model_App 第 804 行)后,我注意到一個 IF 條件,如果您在安裝腳本中,該條件將始終返回默認存儲.

But this code doesn't work either. Indeed after looking into Mage::app() (Mage_Core_Model_App Line 804) I noticed a IF condition that would always return the default store if you're in a setup script.

訣竅是假裝您不在安裝腳本中,我的工作解決方案是:

The trick is to fake that you're not in a setup script, my working solution is:

$this->startSetup();
Mage::register('isSecureArea', 1);

// Force the store to be admin
Mage::app()->setUpdateMode(false);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$category = Mage::getModel('catalog/category');
$category->setPath('1/2') // set parent to be root category
    ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)
    ->setName('Category Name')
    ...
    ->save();
$this->endSetup();

這篇關于如何通過安裝腳本向 Magento 添加類別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 免费看一区二区三区 | 日本特黄特色aaa大片免费 | 毛片黄片 | 日韩在线观看一区 | 日本精品一区二区三区视频 | 精品自拍视频 | 欧美一级淫片免费视频黄 | av午夜激情 | 日韩欧美在线免费观看视频 | 91精品久久久久久综合五月天 | 成人小视频在线观看 | 久久久福利 | 亚洲一区二区三区在线视频 | 在线成人免费视频 | 超碰在线免费av | 一二三在线视频 | 亚欧精品一区 | 粉嫩一区二区三区国产精品 | 精品一级| 亚洲精品9999 | 伊人狠狠干 | 国产精品大片 | 亚洲综合成人网 | 婷婷色综合 | 久久69精品久久久久久久电影好 | 美女国产精品 | 久久一区二区视频 | 黄色片视频网站 | 一区在线观看 | 日韩久久久久久 | 精精国产xxxx视频在线播放 | 91精品国产欧美一区二区成人 | 在线看av网址 | 久久久久久综合 | 国产精品久久久精品 | 国产伦一区二区三区久久 | 九九热在线视频免费观看 | 亚洲综合色网 | 欧美成人免费电影 | 色婷婷激情综合 | 中文字幕亚洲一区二区va在线 |