Skip to content
This repository has been archived by the owner on Jun 1, 2018. It is now read-only.

Better store detection by list ID taking into account scope inheritance #155

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions app/code/community/Ebizmarts/MageMonkey/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,31 +319,41 @@ public function getAdditionalList($store)
}

/**
* Get which store is associated to given $mcListId
* Get which store is associated to given $mcListId taking into account scope inheritance
*
* @param string $mcListId
* @param bool $includeDefault Include <default> store or not on result
* @return string $store
*/
public function getStoreByList($mcListId, $includeDefault = FALSE)
{
$list = Mage::getModel('core/config_data')->getCollection()
->addValueFilter($mcListId)->getFirstItem();
static $storeLists;
static $defaultCode;

$store = null;
if ($list->getId()) {
if (null === $storeLists) {
$defaultCode = Mage::app()->getDefaultStoreView()->getCode();
$storeLists = array();

//$isDefault = (bool)($list->getScope() == 'default');
$isDefault = (bool)($list->getScope() == Mage::app()->getDefaultStoreView()->getCode());
if (!$isDefault && !$includeDefault) {
$store = (string)Mage::app()->getStore($list->getScopeId())->getCode();
} else {
$store = $list->getScope();
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;
}

return $store;
// search in rest of the stores
foreach ($storeLists as $code => $listId) {
if ($listId == $mcListId) {
return $code;
}
}

return null;
}

/**
Expand Down