Skip to content

Commit 8493a45

Browse files
authored
LYNX-530 - Insufficient stock error message shown according to configuration (#294)
1 parent c29a553 commit 8493a45

File tree

20 files changed

+86
-27
lines changed

20 files changed

+86
-27
lines changed

app/code/Magento/Checkout/Test/Mftf/Test/StorefrontProductQuantityAcceptLowerThanStockQuantityAfterChangingStockInBackendTest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<description value="Verify if lower than stock product quantity is accepted after changing stock qty in backend"/>
1515
<severity value="CRITICAL"/>
1616
<testCaseId value="AC-5987"/>
17-
<group value="mtf_migrated"/>
17+
<group value="mtf_migrated"/>
1818
</annotations>
1919

2020
<before>
@@ -61,14 +61,14 @@
6161
<waitForAjaxLoad stepKey="waitForAjaxLoad1"/>
6262

6363
<!--Assert "The requested qty is not available"-->
64-
<see selector="{{CheckoutCartMessageSection.errorMessage}}" userInput="The requested qty is not available" stepKey="seeTheErrorMessageDisplayed"/>
64+
<see selector="{{CheckoutCartMessageSection.errorMessage}}" userInput="Not enough items for sale" stepKey="seeTheErrorMessageDisplayed"/>
6565

6666
<fillField selector="{{CheckoutCartProductSection.qty($$simpleProduct.sku$$)}}" userInput="8" stepKey="updateProductQty"/>
6767
<click selector="{{CheckoutCartProductSection.updateShoppingCartButton}}" stepKey="clickUpdateShoppingCart"/>
6868
<waitForAjaxLoad stepKey="waitForAjaxLoad2"/>
6969
<waitForAjaxLoad stepKey="waitForPageLoad2"/>
7070

71-
<dontSee userInput="The requested qty is not available" stepKey="dontSeeTheErrorMessageDisplayed"/>
71+
<dontSee userInput="Not enough items for sale" stepKey="dontSeeTheErrorMessageDisplayed"/>
7272

7373
</test>
7474
</tests>

app/code/Magento/Customer/Test/Mftf/Test/StorefrontAddProductToCartVerifyThatErrorMessageShouldNotDisappearTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<actionGroup ref="StorefrontProductPageAddSimpleProductToCartActionGroup" stepKey="addProductToCart"/>
5151
<!-- Check that error remains -->
5252
<actionGroup ref="StorefrontAssertProductAddToCartErrorMessageActionGroup" stepKey="assertFailure">
53-
<argument name="message" value="The requested qty is not available"/>
53+
<argument name="message" value="Not enough items for sale"/>
5454
</actionGroup>
5555
</test>
5656
</tests>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class AddProductsToCartError
3333
'The fewest you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
3434
'The most you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
3535
'The requested qty is not available' => self::ERROR_INSUFFICIENT_STOCK,
36+
'Not enough items for sale' => self::ERROR_INSUFFICIENT_STOCK,
37+
'Only %s of %s available' => self::ERROR_INSUFFICIENT_STOCK,
3638
];
3739

3840
/**
@@ -59,6 +61,7 @@ public function create(string $message, int $cartItemPosition = 0): Data\Error
5961
*/
6062
private function getErrorCode(string $message): string
6163
{
64+
$message = preg_replace('/\d+/', '%s', $message);
6265
foreach (self::MESSAGE_CODES as $codeMessage => $code) {
6366
if (false !== stripos($message, $codeMessage)) {
6467
return $code;

app/code/Magento/QuoteGraphQl/Model/Resolver/UpdateCartItems.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
104104
*/
105105
private function getErrorCode(string $message): string
106106
{
107+
$message = preg_replace('/\d+/', '%s', $message);
107108
foreach ($this->messageCodesMapper as $key => $code) {
108109
if (str_contains($message, $key)) {
109110
return $code;

app/code/Magento/QuoteGraphQl/etc/graphql/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
<item name="Could not find cart item" xsi:type="string">COULD_NOT_FIND_CART_ITEM</item>
8787
<item name="Required parameter" xsi:type="string">REQUIRED_PARAMETER_MISSING</item>
8888
<item name="The fewest you may purchase" xsi:type="string">INVALID_PARAMETER_VALUE</item>
89+
<item name="Not enough items for sale" xsi:type="string">INSUFFICIENT_STOCK</item>
90+
<item name="Only %s of %s available" xsi:type="string">INSUFFICIENT_STOCK</item>
8991
</argument>
9092
</arguments>
9193
</type>

app/code/Magento/Sales/Model/Reorder/Reorder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class Reorder
6464
'The fewest you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
6565
'The most you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
6666
'The requested qty is not available' => self::ERROR_INSUFFICIENT_STOCK,
67+
'Not enough items for sale' => self::ERROR_INSUFFICIENT_STOCK,
68+
'Only %s of %s available' => self::ERROR_INSUFFICIENT_STOCK,
6769
];
6870

6971
/**
@@ -358,7 +360,7 @@ private function addError(string $message, string $code = null): void
358360
private function getErrorCode(string $message): string
359361
{
360362
$code = self::ERROR_UNDEFINED;
361-
363+
$message = preg_replace('/\d+/', '%s', $message);
362364
$matchedCodes = array_filter(
363365
self::MESSAGE_CODES,
364366
function ($key) use ($message) {

app/code/Magento/Sales/Test/Mftf/Test/AdminAddSelectedProductToOrderTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@
7171
<argument name="productQty" value="1"/>
7272
</actionGroup>
7373
<!-- Check that error remains -->
74-
<see userInput="The requested qty is not available" stepKey="assertProductErrorRemains"/>
74+
<see userInput="Not enough items for sale" stepKey="assertProductErrorRemains"/>
7575
</test>
7676
</tests>

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp(): void
3737
public function testAddProductIfQuantityIsNotAvailable()
3838
{
3939
$this->expectException(\Exception::class);
40-
$this->expectExceptionMessage('The requested qty. is not available');
40+
$this->expectExceptionMessage('Not enough items for sale');
4141

4242
$sku = 'simple';
4343
$quantity = 200;

dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/UpdateCartItemsTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testUpdateCartItemDecimalQuantity()
4747
$itemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');
4848

4949
$quantity = 0.5;
50-
$query = $this->getQuery($maskedQuoteId, $itemId, $quantity);
50+
$query = $this->getMutation($maskedQuoteId, $itemId, $quantity);
5151
$response = $this->graphQlMutation($query);
5252

5353
$this->assertArrayHasKey('updateCartItems', $response);
@@ -72,15 +72,14 @@ public function testUpdateCartItemSetUnavailableQuantity()
7272
$itemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');
7373

7474
$quantity = 100;
75-
$query = $this->getQuery($maskedQuoteId, $itemId, $quantity);
75+
$query = $this->getMutation($maskedQuoteId, $itemId, $quantity);
7676
$response = $this->graphQlMutation($query);
77-
7877
$this->assertArrayHasKey('updateCartItems', $response);
7978
$this->assertArrayHasKey('errors', $response['updateCartItems']);
8079

8180
$responseError = $response['updateCartItems']['errors'][0];
8281
$this->assertEquals(
83-
"The requested qty. is not available",
82+
"Could not update the product with SKU simple_product: Not enough items for sale",
8483
$responseError['message']
8584
);
8685
$this->assertEquals('INSUFFICIENT_STOCK', $responseError['code']);
@@ -92,9 +91,9 @@ public function testUpdateCartItemSetUnavailableQuantity()
9291
* @param float $quantity
9392
* @return string
9493
*/
95-
private function getQuery(string $maskedQuoteId, int $itemId, float $quantity): string
94+
private function getMutation(string $maskedQuoteId, int $itemId, float $quantity): string
9695
{
97-
return <<<QUERY
96+
return <<<MUTATION
9897
mutation {
9998
updateCartItems(input: {
10099
cart_id: "{$maskedQuoteId}"
@@ -117,6 +116,6 @@ private function getQuery(string $maskedQuoteId, int $itemId, float $quantity):
117116
}
118117
}
119118
}
120-
QUERY;
119+
MUTATION;
121120
}
122121
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function testAddProductIfQuantityIsNotAvailable(): void
155155
$response = $this->graphQlMutation($query);
156156

157157
self::assertEquals(
158-
'The requested qty is not available',
158+
'Not enough items for sale',
159159
$response['addProductsToCart']['user_errors'][0]['message']
160160
);
161161
}

0 commit comments

Comments
 (0)