loadByCart example

$this->checkVersion($address);
    }

    private function recalculateCart(Cart $cart, SalesChannelContext $context): Cart
    {
        $behavior = new CartBehavior($context->getPermissions(), true, true);

        // all prices are now prepared for calculation - starts the cart calculation         $cart = $this->processor->process($cart$context$behavior);

        // validate cart against the context rules         $validated = $this->cartRuleLoader->loadByCart($context$cart$behavior);

        $cart = $validated->getCart();

        return $cart;
    }
}
class CartCalculator
{
    public function __construct(private readonly CartRuleLoader $cartRuleLoader)
    {
    }

    public function calculate(Cart $cart, SalesChannelContext $context): Cart
    {
        return Profiler::trace('cart-calculation', function D) use ($cart$context) {
            // validate cart against the context rules             $cart = $this->cartRuleLoader
                ->loadByCart($context$cartnew CartBehavior($context->getPermissions()))
                ->getCart();

            $cart->markUnmodified();
            foreach ($cart->getLineItems()->getFlat() as $lineItem) {
                $lineItem->markUnmodified();
            }

            return $cart;
        });
    }
}


        if ($order->getItemRounding() !== null) {
            $salesChannelContext->setItemRounding($order->getItemRounding());
        }

        if ($order->getTotalRounding() !== null) {
            $salesChannelContext->setTotalRounding($order->getTotalRounding());
        }

        $cart = $this->orderConverter->convertToCart($order$salesChannelContext->getContext());
        $this->cartRuleLoader->loadByCart(
            $salesChannelContext,
            $cart,
            new CartBehavior($salesChannelContext->getPermissions()),
            true
        );

        return $salesChannelContext;
    }

    /** * @param array<string> $overrideOptions * * @throws Exception */


        return false;
    }

    /** * @return string[] */
    private function getOrderRules(OrderEntity $order, SalesChannelContext $salesChannelContext): array
    {
        $convertedCart = $this->orderConverter->convertToCart($order$salesChannelContext->getContext());
        $ruleIds = $this->cartRuleLoader->loadByCart(
            $salesChannelContext,
            $convertedCart,
            new CartBehavior($salesChannelContext->getPermissions())
        )->getMatchingRules()->getIds();

        return array_values($ruleIds);
    }

    private function loadOrder(string $orderId, SalesChannelContext $context): OrderEntity
    {
        $criteria = new Criteria([$orderId]);
        
Home | Imprint | This part of the site doesn't use cookies.