Skip to content

Commit ea82feb

Browse files
AnujNehraAnujNehra
authored andcommitted
ACP2E-1975: GraphQL cannot add product with customizable option to cart
1 parent 4308cb5 commit ea82feb

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

app/code/Magento/Quote/Model/Cart/AddProductsToCart.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\Quote\Model\Cart;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\Framework\Exception\NoSuchEntityException;
1211
use Magento\Quote\Api\CartRepositoryInterface;
1312
use Magento\Quote\Model\Cart\BuyRequest\BuyRequestBuilder;
@@ -47,33 +46,25 @@ class AddProductsToCart
4746
*/
4847
private $error;
4948

50-
/**
51-
* @var ProductRepositoryInterface
52-
*/
53-
private $productRepository;
54-
5549
/**
5650
* @param CartRepositoryInterface $cartRepository
5751
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
5852
* @param BuyRequestBuilder $requestBuilder
5953
* @param ProductReaderInterface $productReader
6054
* @param AddProductsToCartError $addProductsToCartError
61-
* @param ProductRepositoryInterface $productRepository
6255
*/
6356
public function __construct(
6457
CartRepositoryInterface $cartRepository,
6558
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
6659
BuyRequestBuilder $requestBuilder,
6760
ProductReaderInterface $productReader,
68-
AddProductsToCartError $addProductsToCartError,
69-
ProductRepositoryInterface $productRepository
61+
AddProductsToCartError $addProductsToCartError
7062
) {
7163
$this->cartRepository = $cartRepository;
7264
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
7365
$this->requestBuilder = $requestBuilder;
7466
$this->productReader = $productReader;
7567
$this->error = $addProductsToCartError;
76-
$this->productRepository = $productRepository;
7768
}
7869

7970
/**
@@ -143,6 +134,7 @@ function ($item) {
143134
},
144135
$cartItems
145136
);
137+
$this->productReader->loadProducts($skus, $cart->getStoreId());
146138
foreach ($cartItems as $cartItemPosition => $cartItem) {
147139
$errors = $this->addItemToCart($cart, $cartItem, $cartItemPosition);
148140
if ($errors) {
@@ -173,11 +165,7 @@ private function addItemToCart(Quote $cart, Data\CartItem $cartItem, int $cartIt
173165
$cartItemPosition
174166
);
175167
} else {
176-
try {
177-
$product = clone $this->productRepository->get($sku, false, $cart->getStoreId());
178-
} catch (NoSuchEntityException $e) {
179-
$product = null;
180-
}
168+
$product = $this->productReader->getProductBySku($sku);
181169
if (!$product || !$product->isSaleable() || !$product->isAvailable()) {
182170
$errors[] = $this->error->create(
183171
__('Could not find a product with SKU "%sku"', ['sku' => $sku])->render(),

app/code/Magento/Quote/Model/Cart/ProductReader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function loadProducts(array $skus, int $storeId): void
6464
$this->productCollection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
6565
$this->productCollection->load();
6666
foreach ($this->productCollection->getItems() as $productItem) {
67+
$productItem->setOptions($productItem->getProductOptionsCollection()->getItems());
6768
$this->productsBySku[$productItem->getData(ProductInterface::SKU)] = $productItem;
6869
}
6970
}

0 commit comments

Comments
 (0)