setAreaRuleIds 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
    {
$idB = Uuid::randomHex();
        $idC = Uuid::randomHex();
        $idD = Uuid::randomHex();

        $areaRuleIds = [
            'a' => [$idA$idB],
            'b' => [$idA$idC$idD],
            'c' => [$idB],
            'd' => [$idC],
        ];

        $salesChannelContext->setAreaRuleIds($areaRuleIds);

        static::assertEquals($areaRuleIds$salesChannelContext->getAreaRuleIds());

        static::assertEquals([$idA$idB]$salesChannelContext->getRuleIdsByAreas(['a']));
        static::assertEquals([$idA$idB$idC$idD]$salesChannelContext->getRuleIdsByAreas(['a', 'b']));
        static::assertEquals([$idA$idB]$salesChannelContext->getRuleIdsByAreas(['a', 'c']));
        static::assertEquals([$idC]$salesChannelContext->getRuleIdsByAreas(['d']));
        static::assertEquals([]$salesChannelContext->getRuleIdsByAreas(['f']));
    }

    private function getSalesChannelContext(): SalesChannelContext
    {

        $this->context->setTaxState($taxState);

        return $this;
    }

    /** * @param array<string, string[]> $rules */
    public function setAreaRuleIdsFluent(array $rules): self
    {
        $this->setAreaRuleIds($rules);

        return $this;
    }

    public function setItemRoundingFluent(CashRoundingConfig $rounding): self
    {
        $this->itemRounding = $rounding;

        return $this;
    }
}
Home | Imprint | This part of the site doesn't use cookies.