Skip to content

Commit ba10357

Browse files
committed
ACP2E-175: Internal error when adding a disabled product to cart using GraphQl
1 parent 72b9212 commit ba10357

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

app/code/Magento/CatalogGraphQl/Plugin/AvailableProductsFilter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ public function __construct(ContextFactoryInterface $contextFactory)
4141
* @throws NoSuchEntityException
4242
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4343
*/
44-
public function afterGet(ProductRepositoryInterface $subject, ProductInterface $result, $sku, $editMode = false, $storeId = null, $forceReload = false): ProductInterface
45-
{
44+
public function afterGet(
45+
ProductRepositoryInterface $subject,
46+
ProductInterface $result,
47+
$sku,
48+
$editMode = false,
49+
$storeId = null,
50+
$forceReload = false
51+
): ProductInterface {
4652
if (ProductStatus::STATUS_ENABLED !== (int) $result->getStatus()) {
4753
throw new NoSuchEntityException(
4854
__("The product that was requested doesn't exist. Verify the product and try again.")

app/code/Magento/Wishlist/Model/Wishlist/AddProductsToWishlist.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ private function addItemToWishlist(Wishlist $wishlist, WishlistItem $wishlistIte
117117
if ((int)$wishlistItem->getQuantity() === 0) {
118118
throw new LocalizedException(__("The quantity of a wish list item cannot be 0"));
119119
}
120-
if ($product->getStatus() == Status::STATUS_DISABLED) {
121-
throw new LocalizedException(__("The product is disabled"));
122-
}
123120
$options = $this->buyRequestBuilder->build($wishlistItem, (int) $product->getId());
124121
$result = $wishlist->addNewItem($product, $options);
125122

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ public function testAddDisabledProductToCart(): void
196196

197197
$this->expectException(ResponseContainsErrorsException::class);
198198
$this->expectExceptionMessage(
199-
'Could not add the product with SKU ' . $sku . ' to the shopping cart: ' .
200-
'Product that you are trying to add is not available.'
199+
'GraphQL response contains errors: Could not find a product with SKU "' . $sku . '"'
201200
);
202201

203202
$this->graphQlMutation($query);

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/CustomerWishlistTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function testAddProductToWishlistWithDisabledProduct()
261261
$addToWishlistResponse['addProductsToWishlist']['wishlist']['items_count'],
262262
'Count is greater than 0'
263263
);
264-
$message = 'The product is disabled';
264+
$message = 'Could not find a product with SKU "' . $sku . '"';
265265
$this->assertEquals(
266266
$message,
267267
$addToWishlistResponse['addProductsToWishlist']['user_errors'][0]['message']

0 commit comments

Comments
 (0)