Getting a list of magento stores

后端 未结 2 782
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 23:09

How can I get a list of store groups under a website in Magento and then a list of stores from that store group?

2条回答
  •  深忆病人
    2021-02-03 23:42

    Try this to get the objects directly

    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
    

    iterate over to get the needed scope of one specific website or store

    foreach (Mage::app()->getWebsites() as $website) {
        foreach ($website->getGroups() as $group) {
            $stores = $group->getStores();
            foreach ($stores as $store) {
                //$store is a store object
            }
        }
    }
    

    For the future if you have similar questions here's how i discovered those answers within 60 seconds. First i grep for method names or similar method names with space before method name to see where the methods are defined

    grep ' getStores' app/code -rsn 
    grep ' getWebsites' app/code -rsn 
    

    Second step is grep for usage samples to see how they are meant to use by core developers. For that i add >methodName to grep and this gives me list of files where this method is called and this will give us place to look for examples:

    grep '>getWebsites' app/code -rsn
    

提交回复
热议问题