如何獲取Magento網站下的商店組列表以及該商店組中的商店列表?獲取magento商店列表
回答
嘗試使用此方法獲得的物品直接
Mage::app()->getWebsites(); < in file > app/code/core/Mage/Core/Model/App.php:920
Mage::app()->getStores(); < in file > app/code/core/Mage/Core/Model/App.php:834
疊代得到一個特定的網站所需要的範圍或存儲
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
//$store is a store object
}
}
}
對於未來,如果你也有類似的問題,以下是我發現的這些答案在60秒內。首先,我用grep方法名稱或空間相似的方法名之前的方法名,看看那裏的方法被定義
grep ' getStores' app/code -rsn
grep ' getWebsites' app/code -rsn
第二步是grep命令使用示例,看看他們是如何通過意味着核心開發人員使用。對於我添加>方法名到grep,這給我在哪裏,這種方法被稱爲和文件的列表,這將給予我們的地方去尋找例子:
grep '>getWebsites' app/code -rsn
安東的答案,而正確的,可重新發明輪子只是一點。 Magento Core已經有一個工具可以檢索這類數據。
您可以獲取所有網站的列表,以及它們的「孩子」用這樣的: Mage::getSingleton('adminhtml/system_store')->getStoresStructure()
您也可以通過websiteIds和StoreID,或storeGroupIds陣列的功能,以過濾列表:
public function getStoresStructure($isAll = false, $storeIds = array(), $groupIds = array(), $websiteIds = array())
輸出示例:
Array
(
[1] => Array
(
[value] => 1
[label] => Main Website
[children] => Array
(
[1] => Array
(
[value] => 1
[label] => Madison Island
[children] => Array
(
[1] => Array
(
[value] => 1
[label] => English
)
[2] => Array
(
[value] => 2
[label] => French
)
[3] => Array
(
[value] => 3
[label] => German
)
)
)
)
)
)
有一個類似的用於填充「存儲範圍」下拉列表和跨越多選擇所有管理部分。
Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true)
Array
(
[0] => Array
(
[label] => All Store Views
[value] => 0
)
[1] => Array
(
[label] => Main Website
[value] => Array
(
)
)
[2] => Array
(
[label] => Madison Island
[value] => Array
(
[0] => Array
(
[label] => English
[value] => 1
)
[1] => Array
(
[label] => French
[value] => 2
)
[2] => Array
(
[label] => German
[value] => 3
)
)
)
)
要發現這個問題,我位於具有我想要的數據管理多選,然後我打開模板提示,以找出哪些塊類是負責渲染它: Mage_Adminhtml_Block_Cms_Page_Edit_Form
。知道了這一點,我找到了代碼庫中的類(app/code/core/Mage/Admin/HTML/Block/Cms/Block/Edit/Form.php),並找到了通過搜索其標籤來創建輸入的部分視圖」)。這說明我是如何被提供的輸入的值:
$field =$fieldset->addField('store_id', 'multiselect', array(
'name' => 'stores[]',
'label' => Mage::helper('cms')->__('Store View'),
'title' => Mage::helper('cms')->__('Store View'),
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
));
的Mage::getSingleton('adminhtml/system_store')
指向類Mage_Adminhtml_Model_System_Store
,在那裏我發現了多種類似的方法也可以是有用的。 Have a look for yourself.
'values'=> Mage :: getSingleton('adminhtml/system_store') - > getStoreValuesForForm(false,true),工作過一次! – BENN1TH 2015-08-25 10:28:49
- 1. 如何獲得magento商店?
- 2. Magento商店URL
- 3. 獲取在商店
- 4. 如何通過商店ID在PHP數組中獲取Magento商店詳情?
- 5. magento商店視圖
- 6. 獲得magento當前URL由商店ID
- 7. 如何獲得Magento商店貨幣
- 8. Magento - 如何獲得商店的國家?
- 9. 在ViewController中獲取商店
- 10. magento多個商店視圖
- 11. Magento的商店 - SQL錯誤
- 12. Magento的商店 - 通過
- 13. Magento商店ID在cronjob
- 14. Magento的商店 - 擴展
- 15. Magento商店相關文本
- 16. Magento多商店SSL分享
- 17. 按部門在magento商店
- 18. Magento;派遣多商店
- 19. Magento:在商店代碼Dash
- 20. Magento商店返回URL
- 21. 如何通過Magento商店獲取CMS頁面標題?
- 22. 如何獲取Magento中的主要商店名稱?
- 23. magento - 按商店視圖獲取屬性選項標籤
- 24. Magento後端無法獲取商店視圖屬性值
- 25. 如何在magento中獲取商店徽標和圖像alt
- 26. 獲取所有貨幣可用於網站/商店在magento
- 27. 如何獲取magento商店的默認結帳網址?
- 28. Magento - 按名稱獲取商店,網站,組對象
- 29. Magento:獲取當前商店/網站的父類別
- 30. Magento:從另一家商店獲取產品價格?
非常感謝。這非常有幫助! – Blazo 2011-05-03 10:25:08
將它投票並接受它以供其他人蔘考,如果它解決了您的問題 – 2011-05-03 10:31:59
是的,它解決了我的問題。再次感謝,以及如何投票,說我需要15聲望投票 – Blazo 2011-05-03 10:38:43