Skip to content

Commit 3fbdc45

Browse files
committed
Fix message when maxSaleQty is set and qty is more than maxSaleQty
1 parent 3d228f3 commit 3fbdc45

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Quote\Model\Quote;
1313
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1414
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15+
use Magento\Config\Model\ResourceModel\Config;
1516

1617
class AddSimpleProductToCartTest extends GraphQlAbstract
1718
{
@@ -30,6 +31,11 @@ class AddSimpleProductToCartTest extends GraphQlAbstract
3031
*/
3132
private $quoteIdToMaskedId;
3233

34+
/**
35+
* @var Config
36+
*/
37+
private $config;
38+
3339
/**
3440
* @inheritdoc
3541
*/
@@ -39,6 +45,7 @@ protected function setUp()
3945
$this->quoteResource = $objectManager->get(QuoteResource::class);
4046
$this->quote = $objectManager->create(Quote::class);
4147
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
48+
$this->config = $objectManager->get(Config::class);
4249
}
4350

4451
/**
@@ -60,15 +67,18 @@ public function testAddSimpleProductsToCart()
6067

6168
/**
6269
* @magentoApiDataFixture Magento/Catalog/_files/products.php
70+
6371
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
6472
* @expectedException \Exception
65-
* @expectedExceptionMessage The requested qty is not available
73+
* @expectedExceptionMessage The most you may purchase is 5.
6674
*/
67-
public function testAddProductIfQuantityIsNotAvailable()
75+
public function testAddMoreProductsThatAllowed()
6876
{
6977
$sku = 'simple';
70-
$qty = 200;
78+
$qty = 7;
79+
$maxQty = 5;
7180

81+
$this->config->saveConfig('cataloginventory/item_options/max_sale_qty', $maxQty, 'default', 0);
7282
$maskedQuoteId = $this->getMaskedQuoteId();
7383
$query = $this->getQueryAddSimpleProduct($maskedQuoteId, $sku, $qty);
7484
$this->graphQlQuery($query);
@@ -78,23 +88,23 @@ public function testAddProductIfQuantityIsNotAvailable()
7888
* @magentoApiDataFixture Magento/Catalog/_files/products.php
7989
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
8090
* @expectedException \Exception
81-
* @expectedExceptionMessage The most you may purchase is 10000.
91+
* @expectedExceptionMessage The requested qty is not available
8292
*/
83-
public function testAddMoreProductsThatAllowed()
93+
public function testAddProductIfQuantityIsNotAvailable()
8494
{
85-
$sku = 'simple-product-with-huge-amount';
86-
$qty = 20000;
95+
$sku = 'simple';
96+
$qty = 200;
97+
8798
$maskedQuoteId = $this->getMaskedQuoteId();
8899
$query = $this->getQueryAddSimpleProduct($maskedQuoteId, $sku, $qty);
89100
$this->graphQlQuery($query);
90101
}
91102

92103
/**
93-
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
94104
* @return string
95105
* @throws \Magento\Framework\Exception\NoSuchEntityException
96106
*/
97-
public function getMaskedQuoteId()
107+
public function getMaskedQuoteId() : string
98108
{
99109
$this->quoteResource->load(
100110
$this->quote,

dev/tests/integration/testsuite/Magento/Catalog/_files/products.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,3 @@
3636
->setStockData(['use_config_manage_stock' => 1, 'qty' => 24, 'is_in_stock' => 1])
3737
->setQty(24)
3838
->save();
39-
40-
$productWithHugeQty = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
41-
->create(\Magento\Catalog\Model\Product::class, ['data' => $product->getData()]);
42-
43-
$productWithHugeQty->setUrlKey('simple-product-with-huge-amount')
44-
->setId(2)
45-
->setRowId(2)
46-
->setName('Simple Product With Huge Amount')
47-
->setSku('simple-product-with-huge-amount')
48-
->setCustomDesign('Magento/blank')
49-
->setStockData(['use_config_manage_stock' => 1, 'qty' => 50000, 'is_in_stock' => 1])
50-
->setQty(50000)
51-
->save();

0 commit comments

Comments
 (0)