CalculatedPriceCollection example

$price = $this->calculator->calculate($definition$context);

        $product->assign([
            'calculatedPrice' => $price,
        ]);
    }

    private function calculateAdvancePrices(Entity $product, SalesChannelContext $context, UnitCollection $units): void
    {
        $prices = $product->get('prices');

        $product->assign(['calculatedPrices' => new CalculatedPriceCollection()]);
        if ($prices === null) {
            return;
        }

        if (!$prices instanceof ProductPriceCollection) {
            return;
        }

        $prices = $this->filterRulePrices($prices$context);
        if ($prices === null) {
            return;
        }

    public function discount(float $value): void
    {
        $definition = new QuantityPriceDefinition($this->price->getUnitPrice()$this->price->getTaxRules());
        $definition->setIsCalculated(true);

        $unit = $this->priceStubs->calculateQuantity($definition$this->context);

        $discount = $this->priceStubs->calculatePercentage(\abs($value)new CalculatedPriceCollection([$unit])$this->context);

        $definition = new QuantityPriceDefinition(
            $this->price->getUnitPrice() - $discount->getUnitPrice(),
            $this->price->getTaxRules(),
            $this->getQuantity()
        );

        $this->overwrite($definition);
    }

    /** * `surcharge()` allows a percentage surcharge calculation of the current price scope. The provided value will be ensured to be negative via `abs(value)`. * The provided surcharge is interpreted as a percentage value and will be applied to the unit price and the total price as well. * * @example pricing-cases/product-pricing.twig 34 1 Adds a 10% surcharge to the existing calculated price * * @param float $value The percentage value of the surcharge. The value will be ensured to be negative via `abs(value)`. */
Home | Imprint | This part of the site doesn't use cookies.