@param AddToCartCommandInterface $addCartItemCommand

{@inheritdoc}
339935
public function validate($addCartItemCommand, Constraint $constraint): void
    {
        Assert::isInstanceOf($addCartItemCommand, AddToCartCommandInterface::class);
        Assert::isInstanceOf($constraint, CartItemAvailability::class);

        /** @var OrderItemInterface $cartItem */
        $cartItem = $addCartItemCommand->getCartItem();

        $isStockSufficient = $this->availabilityChecker->isStockSufficient(
            $cartItem->getVariant(),
            $cartItem->getQuantity() + $this->getExistingCartItemQuantityFromCart($addCartItemCommand->getCart(), $cartItem)
        );

        if (!$isStockSufficient) {
            $this->context->addViolation(
                $constraint->message,
                ['%itemName%' => $cartItem->getVariant()->getInventoryName()]
            );
        }
    }
654668
public function updateCartObject($cart) {
    if (isset($cart->customer_id)) {
      $cart->customer_id = (string) $cart->customer_id;
    }

    // Some ecommerce backends, like hybris, don't save the billing like they
    // do with shipping. So if a billing was set we don't want it to be
    // overwritten when the API response comes back.
    $current_billing = $this->getBilling();
    if (!empty($current_billing) && empty($cart->billing)) {
      $cart->billing = $current_billing;
    }

    if (isset($cart->carrier)) {
      // We use it as array internally everywhere, even set as array.
      $cart->carrier = (array) $cart->carrier;

      // If carrier is with empty structure, we remove it.
      if (empty($cart->carrier['carrier_code'])) {
        unset($cart->carrier);
      }
    }

    $this->cart = $cart;
    $this->updateCartItemsCount();
  }
862663
protected function getCartProductInCart(CartProductInterface $cartProduct, CartInterface $cart)
    {
        return $this->getRepository()->findOneBy([
            'id'   => $cartProduct->getId(),
            'cart' => $cart
        ]);
    }
551153
private function addItemToCart(CartItem $cartItem, $qty = 1)
    {
        $cartItem->setQuantity($qty);
        $cartItem->setTaxRate(config('shoppingcart.tax'));

        $content = $this->getContent();

        if ($content->has($cartItem->rowId)) {
            $cartItem->setQuantity($cartItem->getQuantity() + $content->get($cartItem->rowId)->qty);
        }

        $content->put($cartItem->rowId, $cartItem);

        $this->content = serialize($content);

        $this->save();

        return $this;
    }
649625
private function addSelectedProducts(CategoryInterface $category)
    {
        $selectedProducts = $this->getRequest()->getParam('selected_products', []);

        $addedProducts = isset($selectedProducts['added_products']) ? $selectedProducts['added_products'] : [];
        $category->setAddedProductIds($addedProducts);

        $deletedProducts = isset($selectedProducts['deleted_products']) ? $selectedProducts['deleted_products'] : [];
        $category->setDeletedProductIds($deletedProducts);

        return $this;
    }
416764
protected function addComment($payment, $commentContent)
    {
        if ($commentContent) {
            $comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
            $comment->setComment($commentContent);

            $payment->addComment($comment);
        }
    }
1316772
public function loadOrderShippingMethod(
        CartInterface $cart,
        OrderInterface $order
    ) {
        $shippingMethodId = $cart->getShippingMethod();

        if (empty($shippingMethodId)) {
            return $this;
        }

        $shippingMethod = $this
            ->shippingWrapper
            ->getOneById($cart, $shippingMethodId);

        if ($shippingMethod instanceof ShippingMethod) {
            $order->setShippingAmount($shippingMethod->getPrice());
            $order->setShippingMethod($shippingMethod);
        }
    }
1296246
public function validateCartIntegrity(CartInterface $cart)
    {
        /**
         * Check every CartLine.
         *
         * @var CartLineInterface $cartLine
         */
        foreach ($cart->getCartLines() as $cartLine) {
            $this->validateCartLine($cartLine);
        }
    }
63028
protected function addPaymentOptions(RadioGroup $radioGroup, CartInterface $cart)
    {
        $shippingMethodCost = $cart->getShippingMethodCost();
        if (null !== $shippingMethodCost) {
            $shippingMethod = $shippingMethodCost->getShippingMethod();
            $collection     = $shippingMethod->getPaymentMethods();

            $collection->map(function (PaymentMethodInterface $paymentMethod) use ($radioGroup) {
                $radioGroup->addOptionToSelect($paymentMethod->getId(), $paymentMethod->translate()->getName());
            });
        }
    }
359414
protected function addAddCart()
    {
        if (!$this->isError()) {
            $id = $this->cart->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
864487
public function addMethod(PaymentInterface $instance)
    {
        if (null === $instance->getCode()) {
            throw new \RuntimeException(sprintf('Payment handler of class %s must return a code on getCode method. Please refer to the documentation (https://sonata-project.org/bundles/ecommerce/master/doc/reference/bundles/payment/index.html)', \get_class($instance)));
        }

        $this->methods[$instance->getCode()] = $instance;
    }
418592
public function saveCart(CartInterface $cart)
    {
        if (!$cart->getCartLines()->isEmpty()) {
            $this->cartObjectManager->persist($cart);
        }

        $this
            ->cartObjectManager
            ->flush();
    }
147269
public function loadCartShippingAmount(CartInterface $cart)
    {
        $shippingMethodId = $cart->getShippingMethod();

        if (empty($shippingMethodId)) {
            return;
        }

        $shippingMethod = $this
            ->shippingWrapper
            ->getOneById($cart, $shippingMethodId);

        if ($shippingMethod instanceof ShippingMethod) {
            $cart->setShippingAmount(
                $shippingMethod->getPrice()
            );
        }
    }
91712
public function tryAutomaticCoupons(CartInterface $cart)
    {
        if ($cart->getCartLines()->isEmpty()) {
            return;
        }

        $automaticCoupons = $this->getNonAppliedAutomaticCoupons($cart);

        foreach ($automaticCoupons as $coupon) {
            try {
                $this
                    ->cartCouponManager
                    ->addCoupon($cart, $coupon);
            } catch (AbstractCouponException $e) {
                // Silently tries next coupon on controlled exception
            }
        }
    }
692019
protected function registerMakeAddonCommand($command)
    {
        $this->app->singleton($command, function ($app) {
            return new Addons\Commands\AddonMakeCommand($app);
        });
    }
200145
public function dispatchCartLineOnAddEvent(
        CartInterface $cart,
        CartLineInterface $cartLine
    ) {
        $this->eventDispatcher->dispatch(
            ElcodiCartEvents::CARTLINE_ONADD,
            new CartLineOnAddEvent(
                $cart,
                $cartLine
            )
        );

        return $this;
    }
58177
public function createAndSaveCartCoupon(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        /**
         * We create a new instance of CartCoupon.
         * We also persist and flush relation.
         */
        $cartCoupon = $this
            ->cartCouponDirector
            ->create();

        $cartCoupon->setCart($cart);
        $cartCoupon->setCoupon($coupon);

        $this
            ->cartCouponDirector
            ->save($cartCoupon);

        return $cartCoupon;
    }