Skip to content

Commit 6a129f0

Browse files
committed
ACP2E-175: Internal error when adding a disabled product to cart using GraphQl
1 parent cab4db6 commit 6a129f0

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ public function execute(array $cartItemData): array
9292
} catch (NoSuchEntityException $e) {
9393
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
9494
}
95-
if (!in_array($cart->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
96-
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
97-
}
9895

9996
$this->checkProductStock($sku, (float) $qty, (int) $cart->getStore()->getWebsiteId());
10097

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,6 @@ private function addItemToCart(CartInterface $cart, Data\CartItem $cartItem, int
151151
return;
152152
}
153153

154-
if (!in_array($cart->getStoreId(), $product->getStoreIds())) {
155-
$this->addError(
156-
__('Could not find a product with SKU "%sku"', ['sku' => $sku])->render(),
157-
$cartItemPosition
158-
);
159-
160-
return;
161-
}
162-
163154
try {
164155
$result = $cart->addProduct($product, $this->requestBuilder->build($cartItem));
165156
$this->cartRepository->save($cart);

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public function execute(Quote $cart, array $cartItemData): void
6060
} catch (NoSuchEntityException $e) {
6161
throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku]));
6262
}
63-
if (!in_array($cart->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
64-
throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku]));
65-
}
6663

6764
try {
6865
$result = $cart->addProduct($product, $this->buyRequestBuilder->build($cartItemData));

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,25 @@ public function testAddConfigurableProductWithImageToCartParentImage(): void
570570
self::assertEquals($sku, $variant['sku']);
571571
}
572572

573+
/**
574+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_in_multiple_websites_disable_first_child.php
575+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
576+
*/
577+
public function testAddConfigurableProductWithDisabledChildToCart(): void
578+
{
579+
$quantity = 1;
580+
$parentSku = 'configurable';
581+
$sku = 'simple_Option_1';
582+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
583+
584+
$this->expectException(\Exception::class);
585+
$this->expectExceptionMessage('Could not find specified product.');
586+
587+
$query = $this->getQuery($maskedQuoteId, $parentSku, $sku, $quantity);
588+
$headerMap = ['Store' => 'default'];
589+
$this->graphQlMutation($query, [], '', $headerMap);
590+
}
591+
573592
/**
574593
* @param string $maskedQuoteId
575594
* @param string $parentSku
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Action;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
14+
15+
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_product_two_websites.php');
16+
17+
$childSku = 'simple_Option_1';
18+
$objectManager = Bootstrap::getObjectManager();
19+
/** @var ProductRepositoryInterface $productRepository */
20+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
21+
$childProduct = $productRepository->get($childSku);
22+
$productAction = Bootstrap::getObjectManager()->get(Action::class);
23+
$productAction->updateAttributes(
24+
[$childProduct->getEntityId()],
25+
[ProductAttributeInterface::CODE_STATUS => Status::STATUS_DISABLED],
26+
$childProduct->getStoreId()
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
9+
10+
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_product_two_websites_rollback.php');

0 commit comments

Comments
 (0)