Exclude some store from all stores
-
06-10-2020 - |
Question
I get all stores by website but i want to exclude someone, his ID is=1 and his name is:store1.
to get all store by websites:
$websiteId=1;
$website = Mage::getModel('core/website')->load($websiteId);
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
echo $store->getId() ." ".$store->getName()."<br/>";
}
}
Someone knows how to do it with a collection ?
Solution
You can get a collection of all the stores and there you can apply your filters. For example:
// In this example, select all the stores with ID != 1 and Name != 'Dutch'
$stores = Mage::getModel('core/store')->getCollection()
->addFieldToFilter('store_id', array('neq' => 1))
->addFieldToFilter('name', array('neq' => 'Dutch'));
foreach ($stores as $store) {
echo $store->getId() . " " . $store->getName() . "<br/>";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange