Skip to content

Instantly share code, notes, and snippets.

@unicoder88
Created November 21, 2016 19:42
Show Gist options
  • Save unicoder88/d62d013d37f04b1d2b9ced2b91dc6300 to your computer and use it in GitHub Desktop.
Save unicoder88/d62d013d37f04b1d2b9ced2b91dc6300 to your computer and use it in GitHub Desktop.
<?php
/**
* Store detection taking into account scope inheritance
*/
public function getStoreByList($mcListId, $includeDefault = FALSE)
{
static $storeLists;
static $defaultCode;
if (null === $storeLists) {
$defaultCode = Mage::app()->getDefaultStoreView()->getCode();
$storeLists = array();
foreach (Mage::app()->getStores($includeDefault) as $store) {
/** @var Mage_Core_Model_Store $store */
$listId = $store->getConfig(Ebizmarts_MageMonkey_Model_Config::GENERAL_LIST);
$storeLists[$store->getCode()] = $listId;
}
}
// check default store match first
if ($storeLists[$defaultCode] == $mcListId) {
return $defaultCode;
}
// search in rest of the stores
foreach ($storeLists as $code => $listId) {
if ($listId == $mcListId) {
return $code;
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment