Get storeviews by group ID in magento?
-
16-10-2019 - |
Question
How to get storeview ID (view) by group_id
(store) in Magento? Basically I want to list storeviews by their store_id
.
Mage::app()->getStores()
will get all storeviews, but I want to filter it by specific store group like
Mage::app()->getStores()->byGroupId($store_group_id);
so i can list all storeviews under a specific store.
Solution
$groupId = 1;
$collection = Mage::getModel('core/store')->getCollection()->addFieldToFilter('group_id', $groupId);
foreach ($collection as $store) {
//do something with $store
}
OTHER TIPS
You can use something like this
$stores = Mage::getModel('core/store')->getCollection()->addFieldToFilter('group_id',$store_group_id);
foreach($stores as $store)
{
print_r($store->getData());
}
$stores = Mage::getResourceModel('core/store_collection')
# $yourStoreGroupIds can be string or array of group ids
->addGroupFilter($yourStoreGroupIds);
foreach ($stores as $store) {
...
}
Technically the same as Marius answer because addGroupFilter
uses
public function addGroupFilter($groupId)
{
return $this->addFieldToFilter('main_table.group_id', array('in' => $groupId));
}
To just get the storeview IDs
$storeIds = $stores->getColumnValues('store_id');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange