getCompositionItems example


    public function testCompositionItems(): void
    {
        $price = new CalculatedPrice(29, 29, new CalculatedTaxCollection()new TaxRuleCollection());

        $compositionItems = [
            new DiscountCompositionItem('ABC', 2, 13),
        ];

        $result = new DiscountCalculatorResult($price$compositionItems);

        static::assertSame($compositionItems$result->getCompositionItems());
    }
}
$affectedPrices = $packages->getAffectedPrices();

        $totalOriginalSum = $affectedPrices->sum()->getTotalPrice();
        $discountValue = -min(abs($definition->getPrice())$totalOriginalSum);

        $price = $this->priceCalculator->calculate(
            $discountValue,
            $affectedPrices,
            $context
        );

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

        return new DiscountCalculatorResult($price$composition);
    }

    /** * @return DiscountCompositionItem[] */
    
$discountDiff = $this->getTotalDiscountDiffSum($fixedTotalPrice$packages$affectedPrices);

        // now calculate the correct price         // from our collected total discount price         $discountPrice = $this->absolutePriceCalculator->calculate(
            -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();

        
            if (abs($result->getPrice()->getTotalPrice()) === 0.0) {
                continue;
            }

            // use our calculated price             $discountItem->setPrice($result->getPrice());

            // also add our discounted items and their meta data             // to our discount line item payload             $discountItem->setPayloadValue(
                'composition',
                $this->discountCompositionBuilder->buildCompositionPayload($result->getCompositionItems())
            );

            // add our discount item to the cart             $calculated->add($discountItem);

            $this->addPromotionAddedNotice($original$calculated$discountItem);

            // recalculate for every new discount to get the correct             // prices for any upcoming iterations             $this->calculateCart($calculated$context);
        }
    }
                // based on our discount definition.                 // the basis might only be from a few items and quantities of the cart                 $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 = [];

        
Home | Imprint | This part of the site doesn't use cookies.