PermittedAutomaticPromotions example


    private function searchPromotionsAuto(CartDataCollection $data, SalesChannelContext $context): array
    {
        if ($data->has('promotions-auto')) {
            return $data->get('promotions-auto');
        }

        $criteria = (new Criteria())->addFilter(new PermittedAutomaticPromotions($context->getSalesChannel()->getId()));

        /** @var string $association */
        foreach ($this->requiredDalAssociations as $association) {
            $criteria->addAssociation($association);
        }

        /** @var PromotionCollection $automaticPromotions */
        $automaticPromotions = $this->gateway->get($criteria$context);

        $data->set('promotions-auto', $automaticPromotions->getElements());

        
$this->salesChannel->setId('DE');
    }

    /** * This test verifies, that we get the * expected and defined criteria from the template. * * @group promotions */
    public function testCriteria(): void
    {
        $template = new PermittedAutomaticPromotions($this->salesChannel->getId());

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

    private function getExpectedFilter(): MultiFilter
    {
        return new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('active', true),
                new EqualsFilter('promotion.salesChannels.salesChannelId', $this->salesChannel->getId()),
                
Home | Imprint | This part of the site doesn't use cookies.