PermittedGlobalCodePromotions example

/** * This test verifies, that we get the * expected and defined criteria from the template. * * @group promotions */
    public function testCriteria(): void
    {
        $codes = ['code-123'];

        $template = new PermittedGlobalCodePromotions($codes$this->salesChannel->getId());

        static::assertEquals($this->getExpectedFilter($codes)->getQueries()$template->getQueries());
    }

    /** * @param list<string> $codes */
    private function getExpectedFilter(array $codes): MultiFilter
    {
        return new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [


        // 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
Home | Imprint | This part of the site doesn't use cookies.