getPriceForTaxState example

/** * `change()` allows a price overwrite of the current price scope. The provided price will be recalculated * over the quantity price calculator to consider quantity, tax rule and cash rounding configurations. * * @example pricing-cases/product-pricing.twig 40 5 Overwrite prices with a static defined collection * * @param PriceCollection $price The provided price can be a fetched price from the database or generated over the `PriceFactory` statically */
    public function change(PriceCollection $price): void
    {
        $value = $this->getPriceForTaxState($price$this->context);

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

        $this->overwrite($definition);
    }

    /** * `plus()` allows a price addition of the current price scope. The provided price will be recalculated via the quantity price calculator. * The provided price is interpreted as a unit price and will be added to the current unit price. The total price * is calculated afterwards considering quantity, tax rule and cash rounding configurations. * * @example pricing-cases/product-pricing.twig 14 5 Plus a static defined price to the existing calculated price * * @param PriceCollection $price The provided price can be a fetched price from the database or generated over the `PriceFactory` statically */
$definition = new QuantityPriceDefinition($price$rules, 1);

        return $this->priceCalculator->calculate($definition$context);
    }

    private function getCurrencyPrice(PriceCollection $priceCollection, SalesChannelContext $context): float
    {
        /** @var Price $price */
        $price = $priceCollection->getCurrencyPrice($context->getCurrency()->getId());

        $value = $this->getPriceForTaxState($price$context);

        if ($price->getCurrencyId() === Defaults::CURRENCY) {
            $value *= $context->getContext()->getCurrencyFactor();
        }

        return $value;
    }

    private function getPriceForTaxState(Price $price, SalesChannelContext $context): float
    {
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            
if ($price === null) {
            /** @var CalculatedPrice $price */
            $price = $this->item->get('calculatedPrice');
        }

        if ($price instanceof PriceFacade) {
            $price = $price->getInner();
        }

        if ($price instanceof PriceCollection) {
            $value = $this->getPriceForTaxState($price$this->context);

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

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

        if (!$price instanceof CalculatedPrice) {
            
\ksort($mapped, \SORT_NUMERIC);
        $max = \max(\array_keys($mapped));

        $mapped[$max + 1] = $last;

        $this->prices->clear();

        $rules = $this->context->buildTaxRules($this->product->get('taxId'));

        foreach ($mapped as $quantity => $price) {
            $value = $this->getPriceForTaxState($price$this->context);

            $definition = new QuantityPriceDefinition($value$rules$quantity);

            $this->prices->add(
                $this->priceStubs->calculateQuantity($definition$this->context)
            );
        }
    }

    /** * @internal */
$this->getRegulationPrice($prices$context)
        );

        return $definition;
    }

    private function getPriceValue(PriceCollection $price, SalesChannelContext $context): float
    {
        /** @var Price $currency */
        $currency = $price->getCurrencyPrice($context->getCurrencyId());

        $value = $this->getPriceForTaxState($currency$context);

        if ($currency->getCurrencyId() !== $context->getCurrency()->getId()) {
            $value *= $context->getContext()->getCurrencyFactor();
        }

        return $value;
    }

    private function getPriceForTaxState(Price $price, SalesChannelContext $context): float
    {
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            
Home | Imprint | This part of the site doesn't use cookies.