|
16 | 16 | use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
17 | 17 | use Magento\Quote\Api\CartItemRepositoryInterface;
|
18 | 18 | use Magento\Quote\Model\Quote;
|
| 19 | +use Magento\Quote\Model\Quote\Item; |
19 | 20 | use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
|
20 | 21 |
|
21 | 22 | /**
|
@@ -111,24 +112,32 @@ private function processCartItems(Quote $cart, array $items): void
|
111 | 112 | $this->cartItemRepository->deleteById((int)$cart->getId(), $itemId);
|
112 | 113 | } else {
|
113 | 114 | $cartItem->setQty($qty);
|
| 115 | + $this->validateCartItem($cartItem); |
| 116 | + $this->cartItemRepository->save($cartItem); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
114 | 120 |
|
115 |
| - if ($cartItem->getHasError()) { |
116 |
| - $errors = []; |
117 |
| - foreach ($cartItem->getMessage(false) as $message) { |
118 |
| - $errors[] = $message; |
119 |
| - } |
120 |
| - |
121 |
| - if (!empty($errors)) { |
122 |
| - throw new GraphQlInputException( |
123 |
| - __( |
124 |
| - 'Could not update the product with SKU %sku: %message', |
125 |
| - ['sku' => $cartItem->getSku(), 'message' => __(implode("\n", $errors))] |
126 |
| - ) |
127 |
| - ); |
128 |
| - } |
129 |
| - } |
| 121 | + /** |
| 122 | + * @param Item $cartItem |
| 123 | + * @return void |
| 124 | + * @throws GraphQlInputException |
| 125 | + */ |
| 126 | + private function validateCartItem(Item $cartItem): void |
| 127 | + { |
| 128 | + if ($cartItem->getHasError()) { |
| 129 | + $errors = []; |
| 130 | + foreach ($cartItem->getMessage(false) as $message) { |
| 131 | + $errors[] = $message; |
| 132 | + } |
130 | 133 |
|
131 |
| - $this->cartItemRepository->save($cartItem); |
| 134 | + if (!empty($errors)) { |
| 135 | + throw new GraphQlInputException( |
| 136 | + __( |
| 137 | + 'Could not update the product with SKU %sku: %message', |
| 138 | + ['sku' => $cartItem->getSku(), 'message' => __(implode("\n", $errors))] |
| 139 | + ) |
| 140 | + ); |
132 | 141 | }
|
133 | 142 | }
|
134 | 143 | }
|
|
0 commit comments