vendor/shopware/core/Checkout/Cart/CartCalculator.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart;
  3. use Shopware\Core\Profiling\Profiler;
  4. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  5. /**
  6.  * @internal
  7.  * This class is used to recalculate a modified shopping cart. For this it uses the CartRuleLoader class.
  8.  * The rule loader recalculates the cart and validates the current rules.
  9.  */
  10. class CartCalculator
  11. {
  12.     /**
  13.      * @var CartRuleLoader
  14.      */
  15.     private $cartRuleLoader;
  16.     public function __construct(CartRuleLoader $cartRuleLoader)
  17.     {
  18.         $this->cartRuleLoader $cartRuleLoader;
  19.     }
  20.     public function calculate(Cart $cartSalesChannelContext $context): Cart
  21.     {
  22.         return Profiler::trace('cart-calculation', function () use ($cart$context) {
  23.             // validate cart against the context rules
  24.             $cart $this->cartRuleLoader
  25.                 ->loadByCart($context$cart, new CartBehavior($context->getPermissions()))
  26.                 ->getCart();
  27.             $cart->markUnmodified();
  28.             foreach ($cart->getLineItems()->getFlat() as $lineItem) {
  29.                 $lineItem->markUnmodified();
  30.             }
  31.             return $cart;
  32.         });
  33.     }
  34. }