Skip to content

Commit

Permalink
Merge pull request #23 from riha112/2956
Browse files Browse the repository at this point in the history
#2956 Output error messages for configurable products on add all to cart
  • Loading branch information
carinadues authored Jul 23, 2021
2 parents 55b6097 + 91900e7 commit 64b2e07
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Model/Resolver/MoveWishlistToCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,6 +96,8 @@ public function __construct(
*/
protected function addItemsToCart(array $wishlistItems, CartInterface $quote): void
{
$errors = [];

foreach ($wishlistItems as $item) {
$product = $item['product'];

Expand All @@ -112,9 +115,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 GraphQlInputException(__(json_encode($errors)));
}

try {
Expand Down

0 comments on commit 64b2e07

Please sign in to comment.