From 4316abc5b0544395df16fc19a31d5bc9f2d2b992 Mon Sep 17 00:00:00 2001 From: Rihards Abolins Date: Fri, 23 Jul 2021 09:56:28 +0300 Subject: [PATCH 1/2] #2956 List of configurable product error messages --- src/Model/Resolver/MoveWishlistToCart.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Model/Resolver/MoveWishlistToCart.php b/src/Model/Resolver/MoveWishlistToCart.php index b768933..58de32a 100644 --- a/src/Model/Resolver/MoveWishlistToCart.php +++ b/src/Model/Resolver/MoveWishlistToCart.php @@ -95,6 +95,8 @@ public function __construct( */ protected function addItemsToCart(array $wishlistItems, CartInterface $quote): void { + $errors = []; + foreach ($wishlistItems as $item) { $product = $item['product']; @@ -112,9 +114,21 @@ protected function addItemsToCart(array $wishlistItems, CartInterface $quote): v $buyRequest->setData($data); $quoteItem = $quote->addProduct($product, $buyRequest); - $quoteItem->setQty($item['qty']); - $item['item']->delete(); + if (is_string($quoteItem)) { + $msg = $quoteItem[strlen($quoteItem) - 1] === '.' + ? substr($quoteItem, 0, -1) + : $quoteItem; + + $errors[] = $msg . ' for "' . $product->getName() . '"'; + } else { + $quoteItem->setQty($item['qty']); + $item['item']->delete(); + } + } + + if (count($errors) > 0) { + throw new \Exception(json_encode($errors)); } try { From 91900e70223824819bc1745c2de1a7effedaad69 Mon Sep 17 00:00:00 2001 From: Rihards Abolins Date: Fri, 23 Jul 2021 09:56:49 +0300 Subject: [PATCH 2/2] #2956 Exception type change --- src/Model/Resolver/MoveWishlistToCart.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Model/Resolver/MoveWishlistToCart.php b/src/Model/Resolver/MoveWishlistToCart.php index 58de32a..4a8a574 100644 --- a/src/Model/Resolver/MoveWishlistToCart.php +++ b/src/Model/Resolver/MoveWishlistToCart.php @@ -21,6 +21,7 @@ use Magento\Framework\DataObject; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -128,7 +129,7 @@ protected function addItemsToCart(array $wishlistItems, CartInterface $quote): v } if (count($errors) > 0) { - throw new \Exception(json_encode($errors)); + throw new GraphQlInputException(__(json_encode($errors))); } try {