missingLineItemPrice example

/** * @param array<string, CalculatedTaxCollection>|null $taxes */
    private function applyLineItemTaxes(LineItemCollection $lineItems, ?array $taxes): void
    {
        if (!$taxes) {
            return;
        }

        foreach ($lineItems as $lineItem) {
            if (!$lineItem->getPrice()) {
                throw CartException::missingLineItemPrice($lineItem->getUniqueIdentifier());
            }

            // trickle down for nested line items             if ($lineItem->hasChildren()) {
                $this->applyLineItemTaxes($lineItem->getChildren()$taxes);
            }

            // line item has no tax sum provided             if (!\array_key_exists($lineItem->getUniqueIdentifier()$taxes)) {
                continue;
            }

            
public function process(CartDataCollection $data, Cart $original, Cart $toCalculate, SalesChannelContext $context, CartBehavior $behavior): void
    {
        Profiler::trace('cart::product::process', function D) use ($data$original$toCalculate$context): void {
            $hash = $this->generator->getSalesChannelContextHash($context);

            $items = $original->getLineItems()->filterFlatByType(LineItem::PRODUCT_LINE_ITEM_TYPE);

            foreach ($items as $item) {
                $definition = $item->getPriceDefinition();

                if (!$definition instanceof QuantityPriceDefinition) {
                    throw CartException::missingLineItemPrice($item->getId());
                }
                $definition->setQuantity($item->getQuantity());

                $item->setPrice($this->calculator->calculate($definition$context));
                $item->setDataContextHash($hash);
            }

            $this->featureBuilder->add($items$data$context);

            // handle all products which stored in root level             $items = $original->getLineItems()->filterType(LineItem::PRODUCT_LINE_ITEM_TYPE);

            


        $definition = $item->getPriceDefinition();

        if ($definition instanceof PercentagePriceDefinition) {
            $price = $this->percentageCalculator->calculate($definition->getPercentage()$scope->filterGoods()->getPrices()$context);
        } elseif ($definition instanceof CurrencyPriceDefinition) {
            $price = $this->currencyCalculator->calculate($definition->getPrice()$scope->filterGoods()->getPrices()$context);
        } elseif ($definition instanceof QuantityPriceDefinition) {
            $price = $this->quantityCalculator->calculate($definition$context);
        } else {
            throw CartException::missingLineItemPrice($item->getId());
        }

        $item->setPrice($price);
    }

    private function validate(LineItem $item): bool
    {
        foreach ($item->getChildren() as $child) {
            if ($child->getPrice() === null) {
                return false;
            }

            
->getPrices();

            return $this->percentagePriceCalculator->calculate($definition->getPercentage()$prices$context);
        }

        if ($definition instanceof QuantityPriceDefinition) {
            $definition->setQuantity($lineItem->getQuantity());

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

        throw CartException::missingLineItemPrice($lineItem->getId());
    }
}
Home | Imprint | This part of the site doesn't use cookies.