setPromotionDiscountPrices example

$currency->setId('C1');

        $advancedPrice = new PromotionDiscountPriceEntity();
        $advancedPrice->setUniqueIdentifier(Uuid::randomHex());
        $advancedPrice->setCurrency($currency);
        $advancedPrice->setCurrencyId($currency->getId());
        $advancedPrice->setPrice($currencyDiscountValue);

        $advancedPricesCollection = new PromotionDiscountPriceCollection([]);
        $advancedPricesCollection->add($advancedPrice);

        $discount->setPromotionDiscountPrices($advancedPricesCollection);

        $this->salesChannelContext->method('getCurrency')->willReturn($currency);

        $item = $builder->buildDiscountLineItem('code', $this->promotion, $discount, 'C1', $currencyFactor);

        $expectedPrice = -1 * $currencyDiscountValue;

        $expectedPriceDefinition = new AbsolutePriceDefinition($expectedPrice, null);

        static::assertEquals($expectedPriceDefinition$item->getPriceDefinition());
    }

    
$discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $currency = new CurrencyEntity();
        $currency->setId('currency');
        $this->salesChannelContext->method('getCurrency')->willReturn($currency);

        $advancedPrice = new PromotionDiscountPriceEntity();
        $advancedPrice->setUniqueIdentifier(Uuid::randomHex());
        $advancedPrice->setCurrency($currency);
        $advancedPrice->setCurrencyId($currency->getId());
        $advancedPrice->setPrice(20);
        $discount->setPromotionDiscountPrices(new PromotionDiscountPriceCollection([$advancedPrice]));

        $builder = new PromotionItemBuilder();

        $item = $builder->buildDiscountLineItem('', $this->promotion, $discount$currency->getId()$currencyFactor);

        static::assertEquals(20, $item->getPayload()['maxValue']);
    }

    /** * This test verifies that our max value for * absolute discounts is null. This feature is not available * for absolute discounts - only percentage discounts. * * @group promotions * * @throws CartException * @throws UnknownPromotionDiscountTypeException */
Home | Imprint | This part of the site doesn't use cookies.