// if we have new codes to fetch
// make sure to load it and assign it to
// the code in our cache list.
if (\
count($codesToFetch) > 0
) { $salesChannelId =
$context->
getSalesChannel()->
getId();
foreach ($codesToFetch as $currentCode) { // try to find a global code first because
// that search has less data involved
$globalCriteria =
(new Criteria())->
addFilter(new PermittedGlobalCodePromotions([$currentCode],
$salesChannelId));
/** @var string $association */
foreach ($this->requiredDalAssociations
as $association) { $globalCriteria->
addAssociation($association);
} /** @var PromotionCollection $foundPromotions */
$foundPromotions =
$this->gateway->
get($globalCriteria,
$context);
if (\
count($foundPromotions->
getElements()) <= 0
) { // no global code, so try with an individual code instead