getIdsByArea example

$cart = $this->validateTaxFree($context$cart$behaviorContext);

            $index = 0;
            foreach ($rules as $rule) {
                ++$index;
                $this->logger->info(
                    sprintf('#%d Rule detection: %s with priority %d (id: %s)', $index$rule->getName()$rule->getPriority()$rule->getId())
                );
            }

            $context->setRuleIds($rules->getIds());
            $context->setAreaRuleIds($rules->getIdsByArea());

            // save the cart if errors exist, so the errors get persisted             if ($cart->getErrors()->count() > 0 || $this->updated($cart$timestamps)) {
                $this->cartPersister->save($cart$context);
            }

            return new RuleLoaderResult($cart$rules);
        });
    }

    private function loadRules(Context $context): RuleCollection
    {
$ruleE = new RuleEntity();
        $ruleE->setId(Uuid::randomHex());
        $ruleE->setAreas(['a', 'd']);

        $collection = new RuleCollection([$ruleA$ruleB$ruleC$ruleD$ruleE]);

        static::assertEquals([
            'a' => [$ruleA->getId()$ruleE->getId()],
            'b' => [$ruleA->getId()$ruleB->getId()],
            'c' => [$ruleB->getId()$ruleC->getId()],
            'd' => [$ruleE->getId()],
        ]$collection->getIdsByArea());
    }
}
Home | Imprint | This part of the site doesn't use cookies.