Skip to content

Commit 4f0bf65

Browse files
authored
ENGCOM-4575: While adding the product to Cart when the requested Qty is zero or less then zero, one was unexpectedly added #487
2 parents cd9ee48 + ace2c37 commit 4f0bf65

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public function execute(Quote $cart, array $cartItemData): void
6767
{
6868
$sku = $this->extractSku($cartItemData);
6969
$qty = $this->extractQty($cartItemData);
70+
if ($qty <= 0) {
71+
throw new GraphQlInputException(
72+
__('Please enter a number greater than 0 in this field.')
73+
);
74+
}
7075
$customizableOptions = $this->extractCustomizableOptions($cartItemData);
7176

7277
try {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ public function testAddSimpleProductToCart()
5959
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
6060
}
6161

62+
/**
63+
* @magentoApiDataFixture Magento/Catalog/_files/products.php
64+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
65+
* @expectedException \Exception
66+
* @expectedExceptionMessage Please enter a number greater than 0 in this field.
67+
*/
68+
public function testAddSimpleProductToCartWithNegativeQty()
69+
{
70+
$sku = 'simple';
71+
$qty = -2;
72+
$maskedQuoteId = $this->getMaskedQuoteId();
73+
74+
$query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty);
75+
$this->graphQlQuery($query);
76+
}
77+
6278
/**
6379
* @return string
6480
*/

0 commit comments

Comments
 (0)