createTestFixtureAbsolutePromotion example


        $productId = Uuid::randomHex();
        $promotionId = Uuid::randomHex();
        $code = 'BF' . Random::getAlphanumericString(5);

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        // add a new sample product         $this->createTestFixtureProduct($productId, 60, 17, $this->getContainer()$context);

        // add a new promotion black friday         $this->createTestFixtureAbsolutePromotion($promotionId$code, 45, $this->getContainer());

        $cart = $this->cartService->getCart($context->getToken()$context);

        // create product and add to cart         $cart = $this->addProduct($productId, 2, $cart$this->cartService, $context);

        // create promotion and add to cart         $cart = $this->addPromotionCode($code$cart$this->cartService, $context);

        static::assertEquals(75.0, $cart->getPrice()->getTotalPrice());
        static::assertEquals(75.0, $cart->getPrice()->getPositionPrice());
        

        $productId1 = Uuid::randomHex();
        $productId2 = Uuid::randomHex();
        $promotionId = Uuid::randomHex();
        $code = 'BF19';

        // add a new sample product         $this->createTestFixtureProduct($productId1, 50, 19, $this->getContainer()$this->context);
        $this->createTestFixtureProduct($productId2, 100, 19, $this->getContainer()$this->context);

        // add a new promotion         $this->createTestFixtureAbsolutePromotion($promotionId$code, 30, $this->getContainer(), PromotionDiscountEntity::SCOPE_CART);

        $cart = $this->cartService->getCart($this->context->getToken()$this->context);

        // create product and add to cart         $cart = $this->addProduct($productId1, 3, $cart$this->cartService, $this->context);
        $cart = $this->addProduct($productId2, 1, $cart$this->cartService, $this->context);

        // create promotion and add to cart         $cart = $this->addPromotionCode($code$cart$this->cartService, $this->context);

        // get discount line item
public function testMixedAbsoluteAndPercentageDiscount(): void
    {
        $productId = Uuid::randomHex();
        $promotionId1 = Uuid::randomHex();
        $promotionId2 = Uuid::randomHex();
        $context = $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        // add a new sample product         $this->createTestFixtureProduct($productId, 60, 19, $this->getContainer()$context);

        // add our existing promotions         $this->createTestFixtureAbsolutePromotion($promotionId1, 'sale', 20, $this->getContainer());
        $this->createTestFixturePercentagePromotion($promotionId2, '100off', 100, null, $this->getContainer());

        $cart = $this->cartService->getCart($context->getToken()$context);

        // create product and add to cart         $cart = $this->addProduct($productId, 5, $cart$this->cartService, $context);

        // create promotion and add to cart         $cart = $this->addPromotionCode('sale', $cart$this->cartService, $context);
        $cart = $this->addPromotionCode('100off', $cart$this->cartService, $context);

        
$salesChannelContext = $this->createDefaultSalesChannelContext();
        $this->createTestFixtureFixedDiscountPromotion(Uuid::randomHex(), 40, PromotionDiscountEntity::SCOPE_CART, null, $this->getContainer()$salesChannelContext);

        $browser = $this->createCart(TestDefaults::SALES_CHANNEL, $salesChannelContext->getToken());

        $productId = Uuid::randomHex();
        $this->createTestFixtureProduct($productId, 119, 19, $this->getContainer()$salesChannelContext);
        $this->addProduct($browser, TestDefaults::SALES_CHANNEL, $productId);

        // Add promotion code into cart         $promotionCode = Random::getAlphanumericString(5);
        $this->createTestFixtureAbsolutePromotion(Uuid::randomHex()$promotionCode, 100, $this->getContainer());
        $this->addPromotionCodeByAPI($browser, TestDefaults::SALES_CHANNEL, $promotionCode);

        // Check there are automatic promotion and promotion code in cart         $cart = $this->getCart($browser, TestDefaults::SALES_CHANNEL);
        static::assertCount(3, $cart['lineItems']);
        static::assertSame('product', $cart['lineItems'][0]['type']);
        static::assertSame('promotion', $cart['lineItems'][1]['type']);
        static::assertSame('promotion', $cart['lineItems'][2]['type']);
        static::assertSame($promotionCode$cart['lineItems'][2]['referencedId']);

        // Call to disable automatic promotion
Home | Imprint | This part of the site doesn't use cookies.