DiscountAbsoluteCalculator example

        // discount, the packages might be restructure         // also make sure we have correct cart items in our restructured packages from the picker         $packages = $this->advancedPicker->pickItems($discount$packages);
        $packages = $this->enrichPackagesWithCartData($packages$calculatedCart$context);

        // if we have any graduation settings, make sure to reduce the items         // that are eligible for our discount by executing our graduation resolver.         $packages = $this->advancedFilter->filterPackages($discount$packages$originalPackageCount);
        $packages = $this->enrichPackagesWithCartData($packages$calculatedCart$context);

        $calculator = match ($discount->getType()) {
            PromotionDiscountEntity::TYPE_ABSOLUTE => new DiscountAbsoluteCalculator($this->absolutePriceCalculator),
            PromotionDiscountEntity::TYPE_PERCENTAGE => new DiscountPercentageCalculator($this->absolutePriceCalculator, $this->percentagePriceCalculator),
            PromotionDiscountEntity::TYPE_FIXED => new DiscountFixedPriceCalculator($this->absolutePriceCalculator),
            PromotionDiscountEntity::TYPE_FIXED_UNIT => new DiscountFixedUnitPriceCalculator($this->absolutePriceCalculator),
            default => throw new DiscountCalculatorNotFoundException($discount->getType()),
        };

        $result = $calculator->calculate($discount$packages$context);

        // now aggregate any composition items         // which might be duplicated due to separate packages         $aggregatedCompositionItems = $this->discountCompositionBuilder->aggregateCompositionItems($result->getCompositionItems());
        
$taxCalculator = new TaxCalculator();

        $calculator = new AbsolutePriceCalculator(
            new QuantityPriceCalculator(
                new GrossPriceCalculator($taxCalculator$rounding),
                new NetPriceCalculator($taxCalculator$rounding),
            ),
            new PercentageTaxRuleBuilder()
        );

        $discountCalculator = new DiscountAbsoluteCalculator($calculator);

        $priceDefinition = new AbsolutePriceDefinition($discountIn);
        $discount = new DiscountLineItem('foo', $priceDefinition['discountScope' => 'foo', 'discountType' => 'bar'], null);

        $lineItem = new LineItem(Uuid::randomHex(), LineItem::PRODUCT_LINE_ITEM_TYPE, Uuid::randomHex(), 2);
        $lineItem->setPrice(new CalculatedPrice($packageSum / 2, $packageSumnew CalculatedTaxCollection()new TaxRuleCollection()));

        $package = new DiscountPackage(
            new LineItemQuantityCollection([
                new LineItemQuantity($lineItem->getId(), 1),
                new LineItemQuantity($lineItem->getId(), 1),
            ])
Home | Imprint | This part of the site doesn't use cookies.