获取magento商店的列表
如何获取Magento网站下的门店组列表,然后从该门店组获取门店列表?尝试直接获取对象获取magento商店的列表,magento,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 对于未来,如果你有类似的问题,这里是我如何在60
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
对于未来,如果你有类似的问题,这里是我如何在60秒内发现这些答案的。首先,我用grep搜索方法名或类似的方法名,在方法名之前加空格,以查看方法的定义位置
grep ' getStores' app/code -rsn
grep ' getWebsites' app/code -rsn
第二步是grepforusage示例,以了解核心开发人员打算如何使用它们。为此,我向grep添加了>methodName,这给了我调用此方法的文件列表,这将为我们提供查找示例的位置:
grep '>getWebsites' app/code -rsn
安东的回答虽然正确,但可能只是稍微重新发明了一点轮子。Magento Core中已经有了检索此类数据的工具 您可以使用以下方法检索所有网站及其“子网站”的列表:
Mage::getSingleton('adminhtml/system_store')->getStoresStructure()
您还可以将WebSiteID、StoreID或StoreGroupID数组传递给函数,以筛选列表:
公共函数getstoressstructure($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\u store')->getStoreValuesForForm(false,true)
为了发现这一点,我在管理员上找到了一个包含我想要的数据的multi-select,然后打开模板提示来找出哪个块类负责呈现它:Mage\u Adminhtml\u block\u Cms\u Page\u Edit\u Form
。知道了这一点,我在代码库(app/code/core/Mage/Adminhtml/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\u-store')
指向类Mage\u-adminhtml\u-Model\u-system\u-store
,在那里我发现了许多类似的方法,它们也很有用 投票吧,接受它,如果它解决了你的问题,它就解决了我的问题,供其他人将来参考。再次感谢,以及如何投票,说我需要15个声誉来投票回答一些问题以获得必要的声誉,去一个头,阅读这个网站的常见问题解答可能也有用,在循环中使用:$group->getName();和$store->getName();如果我调用网站对象本身上的getStore而不是迭代组,是否有问题。(与循环代码的迭代相关)?我看到商店是网站的一部分,它的self?'values'=>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
)
)
)
)
$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),
));