DiscountCalculatorResult example


        }

        // now calculate the correct price         // from our collected total discount price         $discountPrice = $this->absolutePriceCalculator->calculate(
            -abs($totalDiscountSum),
            $packages->getAffectedPrices(),
            $context
        );

        return new DiscountCalculatorResult($discountPrice$composition);
    }
}
PromotionDiscountEntity::SCOPE_CART => $this->cartScopeDiscountPackager,
            PromotionDiscountEntity::SCOPE_SET => $this->setScopeDiscountPackager,
            PromotionDiscountEntity::SCOPE_SETGROUP => $this->setGroupScopeDiscountPackager,
            default => throw new InvalidScopeDefinitionException($discount->getScope()),
        };

        $packages = $packager->getMatchingItems($discount$calculatedCart$context);

        // check if no result is found,         // then this would mean -> no discount         if ($packages->count() <= 0) {
            return new DiscountCalculatorResult(
                new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection(), 1),
                []
            );
        }

        // remember our initial package count         $originalPackageCount = $packages->count();

        foreach ($calculatedCart->getLineItems() as $item) {
            $item->setStackable(true);
            $this->splitted[$item->getId()] = $this->lineItemQuantitySplitter->split($item, 1, $context);
        }
                $assessmentBasis = $affectedPrices->sum()->getTotalPrice();

                // we have to get our new fictional and lower percentage.                 // we now calculate the percentage with MAX VALUE against our basis                 // to get the percentage to reach only the max value.                 $definedPercentage = ($maxValue / $assessmentBasis) * 100;
            }
        }

        $composition = $this->getCompositionItems($definedPercentage$packages);

        return new DiscountCalculatorResult($calculatedPrice$composition);
    }

    /** * @return DiscountCompositionItem[] */
    private function getCompositionItems(float $percentage, DiscountPackageCollection $packages): array
    {
        $items = [];

        foreach ($packages as $package) {
            foreach ($package->getCartItems() as $lineItem) {
                

    /** * This test verifies that the property is correctly * assigned as well as returned in the getter function. * * @group promotions */
    public function testGetPrice(): void
    {
        $price = new CalculatedPrice(29, 29, new CalculatedTaxCollection()new TaxRuleCollection());

        $result = new DiscountCalculatorResult(
            $price,
            []
        );

        static::assertEquals(29, $result->getPrice()->getTotalPrice());
    }

    /** * This test verifies that the property is correctly * assigned as well as returned in the getter function. * * @group promotions */
$discountValue,
            $affectedPrices,
            $context
        );

        $composition = $this->getCompositionItems(
            $discountValue,
            $packages,
            $totalOriginalSum
        );

        return new DiscountCalculatorResult($price$composition);
    }

    /** * @return DiscountCompositionItem[] */
    private function getCompositionItems(float $discountValue, DiscountPackageCollection $packages, float $totalOriginalSum): array
    {
        $items = [];

        foreach ($packages as $package) {
            foreach ($package->getCartItems() as $lineItem) {
                
abs($discountDiff),
            $affectedPrices,
            $context
        );

        $composition = $this->getCompositionItems(
            $discountPrice->getTotalPrice(),
            $packages,
            $affectedPrices
        );

        return new DiscountCalculatorResult($discountPrice$composition);
    }

    private function getTotalDiscountDiffSum(float $fixedPackagePrice, DiscountPackageCollection $packages, PriceCollection $affectedPrices): float
    {
        $totalProductPrices = $affectedPrices->sum()->getTotalPrice();

        return $totalProductPrices - ($fixedPackagePrice * $packages->count());
    }

    /** * @return array<DiscountCompositionItem> */
Home | Imprint | This part of the site doesn't use cookies.