createTestFixtureFixedDiscountPromotion example


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

        // add 2 test products         $this->createTestFixtureProduct($productId1, 119, 19, $this->getContainer()$this->context);
        $this->createTestFixtureProduct($productId2, 107, 7, $this->getContainer()$this->context);

        // add a new promotion         $this->createTestFixtureFixedDiscountPromotion($promotionId, 200, PromotionDiscountEntity::SCOPE_SET, $code$this->getContainer()$this->context);
        $this->createSetGroupFixture('COUNT', 5, 'PRICE_ASC', $promotionId$this->getContainer());

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

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

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

        
static::assertCount(1, $calculatedTaxForCustomItem);

        $calculatedTaxForProductItem = array_filter($calculatedTaxesfn ($tax) => $tax['taxRate'] === $taxForProductItem);

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

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

        // There are 2 line items in cart including 1 product and 1 automatic promotion         $cart = $this->getCart($browser, TestDefaults::SALES_CHANNEL);
        static::assertCount(2, $cart['lineItems']);
        static::assertSame('product', $cart['lineItems'][0]['type']);
        

        $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->createTestFixtureFixedDiscountPromotion($promotionId, 70, PromotionDiscountEntity::SCOPE_CART, $code$this->getContainer()$this->context);

        $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
$productTwoId = Uuid::randomHex();
        $promotionId = Uuid::randomHex();
        $promotionCode = 'BF19';

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

        // add a new sample product         $this->createTestFixtureProduct($productTwoId, 100, 7, $this->getContainer()$this->context);

        // add a new promotion black friday         $this->createTestFixtureFixedDiscountPromotion($promotionId, 30, PromotionDiscountEntity::SCOPE_CART, $promotionCode$this->getContainer()$this->context);

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

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

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

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

        

        $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);

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

        static::assertEquals(40, $cart->getPrice()->getPositionPrice());
        
private function hasColumn(string $table, string $columnName): bool
    {
        return \in_array($columnNamearray_column($this->connection->fetchAllAssociative(\sprintf('SHOW COLUMNS FROM `%s`', $table)), 'Field'), true);
    }

    private function buildPromotionLineItem(Context $context, bool $promotionExists): void
    {
        if ($promotionExists) {
            $salesChannel = new SalesChannelEntity();
            $salesChannel->setId(TestDefaults::SALES_CHANNEL);

            $this->createTestFixtureFixedDiscountPromotion(
                $this->ids->get('promotion'),
                70,
                PromotionDiscountEntity::SCOPE_CART,
                $this->ids->get('promotion-code'),
                $this->getContainer(),
                Generator::createSalesChannelContext($context, null, $salesChannel)
            );
        }

        $orderData = $this->getOrderData($this->ids->get('order')$context);
        unset($orderData[0]['orderCustomer']);
        
Home | Imprint | This part of the site doesn't use cookies.