Skip to content

Commit 2656d29

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

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Quote\Model\Cart;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Quote\Api\CartRepositoryInterface;
1213
use Magento\Quote\Model\Cart\BuyRequest\BuyRequestBuilder;
@@ -165,7 +166,7 @@ private function addItemToCart(Quote $cart, Data\CartItem $cartItem, int $cartIt
165166
$cartItemPosition
166167
);
167168
} else {
168-
$product = $this->productReader->getProductBySku($sku);
169+
$product = $this->getProductOptions($this->productReader->getProductBySku($sku));
169170
if (!$product || !$product->isSaleable() || !$product->isAvailable()) {
170171
$errors[] = $this->error->create(
171172
__('Could not find a product with SKU "%sku"', ['sku' => $sku])->render(),
@@ -206,4 +207,16 @@ private function prepareErrorOutput(Quote $cart, array $errors = []): AddProduct
206207

207208
return $output;
208209
}
210+
211+
/**
212+
* Set options from product options collection
213+
*
214+
* @param ProductInterface $productItem
215+
* @return ProductInterface|null
216+
*/
217+
private function getProductOptions(ProductInterface $productItem): ?ProductInterface
218+
{
219+
$productItem->setOptions($productItem->getProductOptionsCollection()->getItems());
220+
return $productItem;
221+
}
209222
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ 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());
6867
$this->productsBySku[$productItem->getData(ProductInterface::SKU)] = $productItem;
6968
}
7069
}

0 commit comments

Comments
 (0)