createTestFixtureProduct example


    public function testAbsoluteDiscount(): void
    {
        $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);

        

    public function testCompositionInAbsoluteDiscount(): void
    {
        $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);

        

    public function testPercentageOnMultipleItemsAndSubsetQuantities(): void
    {
        $container = $this->getContainer();
        $productId1 = Uuid::randomHex();
        $productId2 = Uuid::randomHex();

        $code = 'BF' . Random::getAlphanumericString(5);

        // prepare promotion         $this->createTestFixtureProduct($productId1, 65, 19, $container$this->context);
        $this->createTestFixtureProduct($productId2, 30, 7, $container$this->context);

        // prepare a percentage promotion with 100% OFF         // with a set group of the 2 cheapest items.         $promotionBuilder = $this->createPromotionFixtureBuilder($container)
            ->addSetGroup('COUNT', 2, 'PRICE_ASC')
            ->setCode($code)
            ->addDiscount(PromotionDiscountEntity::SCOPE_SET, PromotionDiscountEntity::TYPE_PERCENTAGE, 100.0, false, null);
        $cart = $this->getCart($promotionBuilder$productId1$productId2$code);

        static::assertEquals(65.0, $cart->getPrice()->getPositionPrice(), 'Position Total Price is wrong');
        

    public function testAddLineItemAddsToExtension(): void
    {
        $productId = Uuid::randomHex();
        $promotionId = Uuid::randomHex();
        $promotionCode = 'BF19';

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

        // add a new promotion black friday         $this->createTestFixturePercentagePromotion($promotionId$promotionCode, 100, null, $this->getContainer());

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

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

        // add promotion to cart         $this->addPromotionCode($promotionCode$cart$this->cartService, $this->context);

        

    public function testFixedUnitDiscount(): void
    {
        $productId = Uuid::randomHex();
        $productIdTwo = Uuid::randomHex();
        $promotionId = Uuid::randomHex();
        $code = 'BF19';

        // add a new sample products         $this->createTestFixtureProduct($productId, 100, 19, $this->getContainer()$this->context);
        $this->createTestFixtureProduct($productIdTwo, 100, 7, $this->getContainer()$this->context);

        // add a new promotion         $this->createTestFixtureFixedDiscountPromotion($promotionId, 40, PromotionDiscountEntity::SCOPE_CART, $code$this->getContainer()$this->context);

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

        // add products to cart         $cart = $this->addProduct($productId, 1, $cart$this->cartService, $this->context);
        $cart = $this->addProduct($productIdTwo, 1, $cart$this->cartService, $this->context);

        
static::assertCount(1, $calculatedTaxForProductItem);
    }

    public function testAddPromotion(): void
    {
        $promotionId = Uuid::randomHex();
        $productId = Uuid::randomHex();
        $code = 'BF' . Random::getAlphanumericString(5);

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex()$this->ids->get('sales-channel'));

        $this->createTestFixtureProduct($productId, 800, 19, $this->getContainer()$context);

        $this->createPromotion(
            $promotionId,
            $code,
            $this->getContainer()->get('promotion.repository'),
            $context
        );

        $this->createTestFixtureDiscount($promotionId, PromotionDiscountEntity::TYPE_ABSOLUTE, PromotionDiscountEntity::SCOPE_CART, 10, null, $this->getContainer()$context);

        // Add product

    public function testAbsoluteDeliveryDiscount(): void
    {
        $productId = Uuid::randomHex();
        $promotionId = Uuid::randomHex();

        $this->setNewShippingPrices($this->connection, 100);

        $code = 'BF';

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

        // add a new promotion black friday         $this->createTestFixtureDeliveryPromotion($promotionId, PromotionDiscountEntity::TYPE_ABSOLUTE, 10, $this->getContainer()$this->context, $code);

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

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

        static::assertEquals(100, $cart->getShippingCosts()->getTotalPrice(), 'Delivery costs should be 100 in the beginning');

        
$langId
        );
    }

    public function testUpdatingPromotionAfterUpdateProductLineItem(): void
    {
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $productId = Uuid::randomHex();
        $promotionCode = 'BF99';

        $this->createTestFixtureProduct($productId, 119, 19, $this->getContainer()$salesChannelContext);

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

        $this->addProduct($browser, TestDefaults::SALES_CHANNEL, $productId);

        // Save promotion to database         $this->createTestFixturePercentagePromotion(Uuid::randomHex()$promotionCode, 100, null, $this->getContainer());

        // Add promotion code to our cart (not existing in DB)         $this->addPromotionCodeByAPI($browser, TestDefaults::SALES_CHANNEL, $promotionCode);

        
/** * This test verifies that our promotions are not added * if our cart is empty and has no products yet. * * @group promotions */
    public function testPromotionNotAddedWithoutProduct(): void
    {
        $productId = Uuid::randomHex();
        $code = 'BF19';

        $this->createTestFixtureProduct($productId, 119, 19, $this->getContainer()$this->context);
        $this->createTestFixturePercentagePromotion(Uuid::randomHex()$code, 100, null, $this->getContainer());

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

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

        static::assertCount(0, $cart->getLineItems());
    }

    /** * This test verifies that our promotions are correctly * removed when also removing the last product * * @group promotions */

    public function testAvoidInfiniteLoopEventsWithLotsOfPromotions(): void
    {
        $productId = Uuid::randomHex();

        $this->createTestFixtureProduct($productId, 119, 19, $this->getContainer()$this->getContext());

        $codes = [100, 1, 42, 13, 19];
        $this->createBulkPromotions($codes);

        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $addListener = $this->getMockBuilder(CallableClass::class)->getMock();
        $addListener->expects(static::exactly(1 + \count($codes)))->method('__invoke');
        $this->addEventListener($dispatcher, BeforeLineItemAddedEvent::class$addListener);

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

        

    public function test100PercentageDiscount(): void
    {
        $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, 29, 17, $this->getContainer()$context);

        // add a new promotion black friday         $this->createTestFixturePercentagePromotion($promotionId$code, 100, null, $this->getContainer());

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

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

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

        

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