Skip to content

Commit 3469559

Browse files
committed
GraphQL-530: [Cart Operations] Update Cart Items validation messages
1 parent 496d36a commit 3469559

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/UpdateCartItems.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1717
use Magento\Quote\Api\CartItemRepositoryInterface;
1818
use Magento\Quote\Model\Quote;
19+
use Magento\Quote\Model\Quote\Item;
1920
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
2021

2122
/**
@@ -111,24 +112,32 @@ private function processCartItems(Quote $cart, array $items): void
111112
$this->cartItemRepository->deleteById((int)$cart->getId(), $itemId);
112113
} else {
113114
$cartItem->setQty($qty);
115+
$this->validateCartItem($cartItem);
116+
$this->cartItemRepository->save($cartItem);
117+
}
118+
}
119+
}
114120

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+
}
130133

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+
);
132141
}
133142
}
134143
}

0 commit comments

Comments
 (0)