addDiscount example

$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');
        static::assertEquals(65.0, $cart->getPrice()->getTotalPrice(), 'Total Price is wrong');
        static::assertEquals(54.62, $cart->getPrice()->getNetPrice(), 'Net Price is wrong');
        static::assertEquals(10.38, $cart->getPrice()->getCalculatedTaxes()->getAmount(), 'Taxes are wrong');
    }

    /** * This test verifies that we give correct absolute discounts if the * set group consists of different line items and custom quantities. * We have a package of 2 of the cheapest items. * We only have 2 different products in our cart with total quantity 3 (1x and 2x). * Our cheapest 2 items are 1x the item with quantity 1 and then only 1x * the item of the products with quantity 2. * We give 50 EUR discount on that package, which means the customer has to * pay (product 1 + product 2 - 50) + product 2. * * @group promotions * * @throws CartException */
Home | Imprint | This part of the site doesn't use cookies.