setCalculatedPrice example


    private function calculatePriceStruct(
        PriceRule $rule,
        Tax $tax,
        ShopContextInterface $context
    ): Price {
        $price = new Price($rule);

        // Calculates the normal price of the struct.         $price->setCalculatedPrice(
            $this->priceCalculatorService->calculatePrice($rule->getPrice()$tax$context)
        );

        // Check if a pseudo price is defined and calculates it too.         $price->setCalculatedPseudoPrice(
            $this->priceCalculatorService->calculatePrice($rule->getPseudoPrice()$tax$context)
        );

        if ($rule->getRegulationPrice()) {
            $price->setCalculatedRegulationPrice(
                $this->priceCalculatorService->calculatePrice($rule->getRegulationPrice()$tax$context)
            );

class ProductProxyTest extends TestCase
{
    public function testProxyPropertyAccess(): void
    {
        $product = new SalesChannelProductEntity();

        $product->setName('foo');
        $product->setStock(10);

        $product->setCalculatedPrice(
            new CalculatedPrice(10, 10, new CalculatedTaxCollection()new TaxRuleCollection())
        );

        $product->setCalculatedCheapestPrice(
            new CalculatedCheapestPrice(8, 8, new CalculatedTaxCollection()new TaxRuleCollection())
        );

        $product->setCalculatedPrices(new PriceCollection([
            new CalculatedPrice(9, 9, new CalculatedTaxCollection()new TaxRuleCollection()),
        ]));

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