Skip to content

Commit a2df257

Browse files
committed
MC-29851: Unexpected message appears if you try to add products to order via admin panel
1 parent b7a3f9a commit a2df257

File tree

6 files changed

+153
-6
lines changed

6 files changed

+153
-6
lines changed

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/QuoteItemQtyList.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\CatalogInventory\Model\Quote\Item\QuantityValidator;
78

9+
/**
10+
* Process product qty from quote items.
11+
*/
812
class QuoteItemQtyList
913
{
1014
/**
@@ -16,12 +20,13 @@ class QuoteItemQtyList
1620
protected $_checkedQuoteItems = [];
1721

1822
/**
19-
* Get product qty includes information from all quote items
20-
* Need be used only in singleton mode
23+
* Get product qty includes information from all quote items.
2124
*
22-
* @param int $productId
23-
* @param int $quoteItemId
24-
* @param int $quoteId
25+
* Need be used only in singleton mode.
26+
*
27+
* @param int $productId
28+
* @param int $quoteItemId
29+
* @param int $quoteId
2530
* @param float $itemQty
2631
*
2732
* @return int
@@ -44,4 +49,14 @@ public function getQty($productId, $quoteItemId, $quoteId, $itemQty)
4449

4550
return $qty;
4651
}
52+
53+
/**
54+
* Clear array with checked Quote items.
55+
*
56+
* @return void
57+
*/
58+
public function clear(): void
59+
{
60+
$this->_checkedQuoteItems = [];
61+
}
4762
}

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
99
use Magento\CatalogInventory\Api\StockRegistryInterface;
1010
use Magento\CatalogInventory\Api\StockStateInterface;
11+
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\Pricing\PriceCurrencyInterface;
1214
use Magento\Framework\Session\SessionManagerInterface;
1315
use Magento\Quote\Model\Quote\Item;
@@ -72,6 +74,11 @@ class Grid extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
7274
*/
7375
protected $stockState;
7476

77+
/**
78+
* @var QuoteItemQtyList
79+
*/
80+
private $quoteItemQtyList;
81+
7582
/**
7683
* @param \Magento\Backend\Block\Template\Context $context
7784
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
@@ -85,6 +92,7 @@ class Grid extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
8592
* @param StockRegistryInterface $stockRegistry
8693
* @param StockStateInterface $stockState
8794
* @param array $data
95+
* @param QuoteItemQtyList $quoteItemQtyList
8896
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8997
*/
9098
public function __construct(
@@ -99,7 +107,8 @@ public function __construct(
99107
\Magento\GiftMessage\Helper\Message $messageHelper,
100108
StockRegistryInterface $stockRegistry,
101109
StockStateInterface $stockState,
102-
array $data = []
110+
array $data = [],
111+
?QuoteItemQtyList $quoteItemQtyList = null
103112
) {
104113
$this->_messageHelper = $messageHelper;
105114
$this->_wishlistFactory = $wishlistFactory;
@@ -108,6 +117,7 @@ public function __construct(
108117
$this->_taxData = $taxData;
109118
$this->stockRegistry = $stockRegistry;
110119
$this->stockState = $stockState;
120+
$this->quoteItemQtyList = $quoteItemQtyList ?? ObjectManager::getInstance()->get(QuoteItemQtyList::class);
111121
parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $data);
112122
}
113123

@@ -132,6 +142,7 @@ public function getItems()
132142
$items = $this->getParentBlock()->getItems();
133143
$oldSuperMode = $this->getQuote()->getIsSuperMode();
134144
$this->getQuote()->setIsSuperMode(false);
145+
$this->quoteItemQtyList->clear();
135146
foreach ($items as $item) {
136147
// To dispatch inventory event sales_quote_item_qty_set_after, set item qty
137148
$item->setQty($item->getQty());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AssertAdminItemOrderedErrorActionGroup">
11+
<annotations>
12+
<description>Assert that item in "Item Ordered" grid has an error/notice</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="productName" defaultValue="{{_defaultProduct.name}}" type="string"/>
16+
<argument name="messageType" defaultValue="error" type="string"/>
17+
<argument name="message" defaultValue="The requested qty is not available" type="string"/>
18+
</arguments>
19+
<see userInput="{{message}}" selector="{{AdminOrderFormItemsOrderedSection.productMessage(productName, messageType)}}" stepKey="assertItemErrorVisible"/>
20+
</actionGroup>
21+
</actionGroups>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AssertAdminItemOrderedErrorNotVisibleActionGroup">
11+
<annotations>
12+
<description>Assert that item in "Item Ordered" grid does not have an error/notice</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="productName" defaultValue="{{_defaultProduct.name}}" type="string"/>
16+
<argument name="messageType" defaultValue="error" type="string"/>
17+
<argument name="message" defaultValue="The requested qty is not available" type="string"/>
18+
</arguments>
19+
<dontSee userInput="{{message}}" selector="{{AdminOrderFormItemsOrderedSection.productMessage(productName, messageType)}}" stepKey="assertItemErrorNotVisible"/>
20+
</actionGroup>
21+
</actionGroups>

app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormItemsOrderedSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
<element name="configureSelectAttribute" type="select" selector="select[id*=attribute]"/>
1919
<element name="itemsSKU" type="text" selector="(//div[contains(@class, 'product-sku-block')])[{{productNumber}}]" parameterized="true"/>
2020
<element name="moveProduct" type="select" selector="//td[contains(.,'{{productName}}')]/../..//td//select" parameterized="true"/>
21+
<element name="productMessage" type="text" selector="//section[@id = 'order-items']//span[text()='{{productName}}']/ancestor::tr/..//div[contains(@class, 'message-{{messageType}}')]" parameterized="true"/>
2122
</section>
2223
</sections>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminAddSelectedProductToOrderTest">
12+
<annotations>
13+
<features value="CatalogInventory"/>
14+
<stories value="Admin create order"/>
15+
<title value="Add selected products to order in Admin when requested qty more than available"/>
16+
<description value="Trying to add selected products to order in Admin when requested qty more than available"/>
17+
<useCaseId value="MC-29851"/>
18+
<testCaseId value="MC-29797"/>
19+
<severity value="MAJOR"/>
20+
<group value="sales"/>
21+
<group value="catalogInventory"/>
22+
</annotations>
23+
<before>
24+
<createData entity="Simple_US_Customer" stepKey="simpleCustomer"/>
25+
<createData entity="SimpleProduct2" stepKey="simpleProduct"/>
26+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
27+
</before>
28+
<after>
29+
<deleteData createDataKey="simpleCustomer" stepKey="deleteSimpleCustomer"/>
30+
<deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/>
31+
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
32+
</after>
33+
34+
<!-- Initiate create new order -->
35+
<actionGroup ref="NavigateToNewOrderPageExistingCustomerActionGroup" stepKey="navigateToNewOrderPageWithExistingCustomer">
36+
<argument name="customer" value="$simpleCustomer$"/>
37+
</actionGroup>
38+
<!-- Add to order maximum available quantity - 1 -->
39+
<executeJS function="return {{SimpleProduct2.quantity}} - 1" stepKey="maxQtyMinusOne"/>
40+
<actionGroup ref="AddSimpleProductToOrderActionGroup" stepKey="addProductToOrderWithMaxQtyMinusOne">
41+
<argument name="product" value="$simpleProduct$"/>
42+
<argument name="productQty" value="{$maxQtyMinusOne}"/>
43+
</actionGroup>
44+
<!-- Check that there is no error or notice -->
45+
<actionGroup ref="AssertAdminItemOrderedErrorNotVisibleActionGroup" stepKey="assertNoticeAbsent">
46+
<argument name="productName" value="$simpleProduct.name$"/>
47+
<argument name="messageType" value="notice"/>
48+
</actionGroup>
49+
<actionGroup ref="AssertAdminItemOrderedErrorNotVisibleActionGroup" stepKey="assertErrorAbsent">
50+
<argument name="productName" value="$simpleProduct.name$"/>
51+
<argument name="messageType" value="error"/>
52+
</actionGroup>
53+
<!-- Add to order maximum available quantity -->
54+
<actionGroup ref="AddSimpleProductToOrderActionGroup" stepKey="addProductToOrder">
55+
<argument name="product" value="$simpleProduct$"/>
56+
<argument name="productQty" value="1"/>
57+
</actionGroup>
58+
<!-- Check that there is no error or notice -->
59+
<actionGroup ref="AssertAdminItemOrderedErrorNotVisibleActionGroup" stepKey="assertNoticeAbsentAgain">
60+
<argument name="productName" value="$simpleProduct.name$"/>
61+
<argument name="messageType" value="notice"/>
62+
</actionGroup>
63+
<actionGroup ref="AssertAdminItemOrderedErrorNotVisibleActionGroup" stepKey="assertErrorAbsentAgain">
64+
<argument name="productName" value="$simpleProduct.name$"/>
65+
<argument name="messageType" value="error"/>
66+
</actionGroup>
67+
<!-- Add to order one more quantity -->
68+
<actionGroup ref="AddSimpleProductToOrderActionGroup" stepKey="addProductToOrderAgain">
69+
<argument name="product" value="$simpleProduct$"/>
70+
<argument name="productQty" value="1"/>
71+
</actionGroup>
72+
<!-- Check that error remains -->
73+
<actionGroup ref="AssertAdminItemOrderedErrorActionGroup" stepKey="assertProductErrorRemains">
74+
<argument name="productName" value="$simpleProduct.name$"/>
75+
<argument name="messageType" value="notice"/>
76+
</actionGroup>
77+
</test>
78+
</tests>

0 commit comments

Comments
 (0)