Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2956 Output error messages for configurable products on add all to cart #23

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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