diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItems.php b/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItems.php deleted file mode 100644 index c2148dbe09933..0000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItems.php +++ /dev/null @@ -1,58 +0,0 @@ -quoteRepository = $quoteRepository; - $this->guestCartRepository = $guestCartRepository; - } - - public function update(string $maskedCartId, array $items): Quote - { - $quote = $this->guestCartRepository->get($maskedCartId); - - foreach ($items as $item) { - $quoteItem = $quote->getItemById($item['item_id']); - if ($quoteItem === false) { - throw new NoSuchEntityException(__('Could not find cart item with id: %1', $item['item_id'])); - } - - $qty = $item['qty']; - - if ($qty <= 0.0) { - $quote->removeItem($quoteItem->getItemId()); - continue; - } - - $quoteItem->setQty($qty); - } - - $this->quoteRepository->save($quote); - - return $quote; - } -} diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php index a334e7482ca47..ba38158b7fa7c 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/ApplyCouponToCart.php @@ -50,12 +50,12 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - if (!isset($args['input']['cart_id'])) { + if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } $maskedCartId = $args['input']['cart_id']; - if (!isset($args['input']['coupon_code'])) { + if (!isset($args['input']['coupon_code']) || empty($args['input']['coupon_code'])) { throw new GraphQlInputException(__('Required parameter "coupon_code" is missing')); } $couponCode = $args['input']['coupon_code']; diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php index 2df31841366a1..db74b1fa4174b 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php @@ -37,7 +37,7 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - if (!isset($args['cart_id'])) { + if (!isset($args['cart_id']) || empty($args['cart_id'])) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } $maskedCartId = $args['cart_id']; diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php index 730c927c32a0c..d0b4bfd9c7d3a 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveCouponFromCart.php @@ -50,7 +50,7 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - if (!isset($args['input']['cart_id'])) { + if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } $maskedCartId = $args['input']['cart_id']; diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php index 1838f17369ffc..2ff7af354368b 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php @@ -23,25 +23,25 @@ class RemoveItemFromCart implements ResolverInterface { /** - * @var GuestCartItemRepositoryInterface + * @var GetCartForUser */ - private $guestCartItemRepository; + private $getCartForUser; /** - * @var GetCartForUser + * @var GuestCartItemRepositoryInterface */ - private $getCartForUser; + private $guestCartItemRepository; /** - * @param GuestCartItemRepositoryInterface $guestCartItemRepository * @param GetCartForUser $getCartForUser + * @param GuestCartItemRepositoryInterface $guestCartItemRepository */ public function __construct( - GuestCartItemRepositoryInterface $guestCartItemRepository, - GetCartForUser $getCartForUser + GetCartForUser $getCartForUser, + GuestCartItemRepositoryInterface $guestCartItemRepository ) { - $this->guestCartItemRepository = $guestCartItemRepository; $this->getCartForUser = $getCartForUser; + $this->guestCartItemRepository = $guestCartItemRepository; } /** @@ -49,12 +49,12 @@ public function __construct( */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { - if (!isset($args['input']['cart_id'])) { + if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } $maskedCartId = $args['input']['cart_id']; - if (!isset($args['input']['cart_item_id'])) { + if (!isset($args['input']['cart_item_id']) || empty($args['input']['cart_item_id'])) { throw new GraphQlInputException(__('Required parameter "cart_item_id" is missing')); } $itemId = $args['input']['cart_item_id']; diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 7e99dc636e974..f5b15212a2209 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -11,6 +11,7 @@ type Mutation { addVirtualProductsToCart(input: AddVirtualProductsToCartInput): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart") applyCouponToCart(input: ApplyCouponToCartInput): ApplyCouponToCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ApplyCouponToCart") removeCouponFromCart(input: RemoveCouponFromCartInput): RemoveCouponFromCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\RemoveCouponFromCart") + updateCartItems(input: UpdateCartItemsInput): UpdateCartItemsOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\UpdateCartItems") removeItemFromCart(input: RemoveItemFromCartInput): RemoveItemFromCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\RemoveItemFromCart") setShippingAddressesOnCart(input: SetShippingAddressesOnCartInput): SetShippingAddressesOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingAddressesOnCart") setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetBillingAddressOnCart")