Skip to content

Commit bb5267e

Browse files
Merge branch '2.4-develop' into AC-13229
2 parents 737f1a5 + df07984 commit bb5267e

File tree

26 files changed

+222
-253
lines changed

26 files changed

+222
-253
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/OrderCancellationGraphQl/Model/CancelOrderErrorCodes.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

app/code/Magento/OrderCancellationGraphQl/Model/Resolver/CancelOrderError.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
use Magento\Framework\GraphQl\Config\Element\Field;
2020
use Magento\Framework\GraphQl\Query\ResolverInterface;
2121
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
22-
use Magento\OrderCancellationGraphQl\Model\CancelOrderErrorCodes;
2322

2423
/**
2524
* Resolver to return the description of a CancellationReason with error code
2625
*/
2726
class CancelOrderError implements ResolverInterface
2827
{
2928
/**
30-
* @param CancelOrderErrorCodes $cancelOrderErrorCodes
29+
* @param array $errorMessageCodesMapper
3130
*/
3231
public function __construct(
33-
private readonly CancelOrderErrorCodes $cancelOrderErrorCodes
32+
private readonly array $errorMessageCodesMapper
3433
) {
3534
}
3635

@@ -50,7 +49,7 @@ public function resolve(
5049

5150
return [
5251
'message' => $value['error'],
53-
'code' => $this->cancelOrderErrorCodes->getErrorCodeFromMapper((string) $value['error']),
52+
'code' => $this->errorMessageCodesMapper[strtolower((string) $value['error'])] ?? 'UNDEFINED',
5453
];
5554
}
5655
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@
2323
</argument>
2424
</arguments>
2525
</type>
26+
<type name="Magento\OrderCancellationGraphQl\Model\Resolver\CancelOrderError">
27+
<arguments>
28+
<argument name="errorMessageCodesMapper" xsi:type="array">
29+
<item name="order cancellation is not enabled for requested store." xsi:type="string">ORDER_CANCELLATION_DISABLED</item>
30+
<item name="current user is not authorized to cancel this order" xsi:type="string">UNAUTHORISED</item>
31+
<item name="the entity that was requested doesn't exist. verify the entity and try again." xsi:type="string">ORDER_NOT_FOUND</item>
32+
<item name="order with one or more items shipped cannot be cancelled" xsi:type="string">PARTIAL_ORDER_ITEM_SHIPPED</item>
33+
<item name="order already closed, complete, cancelled or on hold" xsi:type="string">INVALID_ORDER_STATUS</item>
34+
</argument>
35+
</arguments>
36+
</type>
2637
</config>

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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function testAddVariationFromAnotherConfigurableProductWithDifferentSuper
206206
public function testAddProductIfQuantityIsNotAvailable()
207207
{
208208
$this->expectException(\Exception::class);
209-
$this->expectExceptionMessage('The requested qty. is not available');
209+
$this->expectExceptionMessage('Not enough items for sale');
210210

211211
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
212212
$product = current($searchResponse['products']['items']);

dev/tests/api-functional/testsuite/Magento/GraphQl/OrderCancellation/CancelGuestOrderTest.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public function testAttemptToCancelOrderWhenCancellationFeatureDisabled()
151151
reason: "Sample reason"
152152
}
153153
){
154-
error
154+
errorV2 {
155+
message
156+
}
155157
order {
156158
status
157159
}
@@ -161,7 +163,9 @@ public function testAttemptToCancelOrderWhenCancellationFeatureDisabled()
161163
$this->assertEquals(
162164
[
163165
'cancelOrder' => [
164-
'error' => 'Order cancellation is not enabled for requested store.',
166+
'errorV2' => [
167+
'message' => 'Order cancellation is not enabled for requested store.'
168+
],
165169
'order' => null
166170
]
167171
],
@@ -199,7 +203,9 @@ public function testAttemptToCancelOrderWithSomeStatuses(string $status, string
199203
[
200204
'cancelOrder' =>
201205
[
202-
'error' => 'Order already closed, complete, cancelled or on hold',
206+
'errorV2' => [
207+
'message' => 'Order already closed, complete, cancelled or on hold'
208+
],
203209
'order' => [
204210
'status' => $expectedStatus
205211
]
@@ -240,7 +246,9 @@ public function testAttemptToCancelOrderWithOfflinePaymentFullyInvoicedFullyShip
240246
[
241247
'cancelOrder' =>
242248
[
243-
'error' => 'Order already closed, complete, cancelled or on hold',
249+
'errorV2' => [
250+
'message' => 'Order already closed, complete, cancelled or on hold'
251+
],
244252
'order' => [
245253
'status' => 'Complete'
246254
]
@@ -294,7 +302,9 @@ public function testAttemptToCancelOrderWithOfflinePaymentFullyInvoicedPartially
294302
[
295303
'cancelOrder' =>
296304
[
297-
'error' => 'Order with one or more items shipped cannot be cancelled',
305+
'errorV2' => [
306+
'message' => 'Order with one or more items shipped cannot be cancelled'
307+
],
298308
'order' => [
299309
'status' => 'Processing'
300310
]
@@ -335,7 +345,9 @@ public function testAttemptToCancelOrderWithOfflinePaymentFullyInvoicedFullyRefu
335345
[
336346
'cancelOrder' =>
337347
[
338-
'error' => 'Order already closed, complete, cancelled or on hold',
348+
'errorV2' => [
349+
'message' => 'Order already closed, complete, cancelled or on hold'
350+
],
339351
'order' => [
340352
'status' => 'Closed'
341353
]
@@ -369,7 +381,7 @@ public function testCancelOrderWithOutAnyAmountPaid()
369381
[
370382
'cancelOrder' =>
371383
[
372-
'error' => null,
384+
'errorV2' => null,
373385
'order' => [
374386
'status' => 'Pending'
375387
]
@@ -399,7 +411,9 @@ private function getCancelOrderMutation(OrderInterface $order): string
399411
reason: "Cancel sample reason"
400412
}
401413
){
402-
error
414+
errorV2 {
415+
message
416+
}
403417
order {
404418
status
405419
}

0 commit comments

Comments
 (0)