Skip to content

Commit 7a6f1d4

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-39104' into 2.4-develop-pr48
2 parents 830b844 + e55a9e3 commit 7a6f1d4

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,17 @@ public function validate(Observer $observer)
157157
if ($stockStatus->getStockStatus() === Stock::STOCK_OUT_OF_STOCK
158158
|| $parentStockStatus && $parentStockStatus->getStockStatus() == Stock::STOCK_OUT_OF_STOCK
159159
) {
160-
$quoteItem->addErrorInfo(
161-
'cataloginventory',
162-
Data::ERROR_QTY,
163-
__('This product is out of stock.')
164-
);
160+
$hasError = $quoteItem->getStockStateResult()
161+
? $quoteItem->getStockStateResult()->getHasError() : false;
162+
if (!$hasError) {
163+
$quoteItem->addErrorInfo(
164+
'cataloginventory',
165+
Data::ERROR_QTY,
166+
__('This product is out of stock.')
167+
);
168+
} else {
169+
$quoteItem->addErrorInfo(null, Data::ERROR_QTY);
170+
}
165171
$quoteItem->getQuote()->addErrorInfo(
166172
'stock',
167173
'cataloginventory',

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/QuantityValidatorTest.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function setUp(): void
153153
->getMock();
154154
$this->storeMock = $this->createMock(Store::class);
155155
$this->quoteItemMock = $this->getMockBuilder(Item::class)
156-
->addMethods(['getProductId', 'getHasError'])
156+
->addMethods(['getProductId', 'getHasError', 'getStockStateResult'])
157157
->onlyMethods(
158158
[
159159
'getQuote',
@@ -460,6 +460,53 @@ public function testException()
460460
$this->quantityValidator->validate($this->observerMock);
461461
}
462462

463+
/**
464+
* This tests the scenario when the error is in the quote item already
465+
*
466+
* @return void
467+
*/
468+
public function testValidateOutStockWithAlreadyErrorInQuoteItem(): void
469+
{
470+
$this->createInitialStub(1);
471+
$resultMock = $this->getMockBuilder(DataObject::class)
472+
->addMethods(['checkQtyIncrements', 'getMessage', 'getQuoteMessage', 'getHasError'])
473+
->getMock();
474+
$resultMock->method('getHasError')
475+
->willReturn(true);
476+
$this->stockRegistryMock->method('getStockItem')
477+
->willReturn($this->stockItemMock);
478+
$this->stockRegistryMock->expects($this->at(1))
479+
->method('getStockStatus')
480+
->willReturn($this->stockStatusMock);
481+
$this->quoteItemMock->method('getParentItem')
482+
->willReturn($this->parentItemMock);
483+
$this->quoteItemMock->method('getStockStateResult')
484+
->willReturn($resultMock);
485+
$this->stockRegistryMock->expects($this->at(2))
486+
->method('getStockStatus')
487+
->willReturn($this->parentStockItemMock);
488+
$this->parentStockItemMock->method('getStockStatus')
489+
->willReturn(0);
490+
$this->stockStatusMock->expects($this->atLeastOnce())
491+
->method('getStockStatus')
492+
->willReturn(1);
493+
$this->quoteItemMock->expects($this->once())
494+
->method('addErrorInfo')
495+
->with(
496+
null,
497+
Data::ERROR_QTY,
498+
);
499+
$this->quoteMock->expects($this->once())
500+
->method('addErrorInfo')
501+
->with(
502+
'stock',
503+
'cataloginventory',
504+
Data::ERROR_QTY,
505+
__('Some of the products are out of stock.')
506+
);
507+
$this->quantityValidator->validate($this->observerMock);
508+
}
509+
463510
/**
464511
* @param $qty
465512
* @param $hasError

app/code/Magento/ConfigurableProduct/Test/Mftf/Test/NoOptionAvailableToConfigureDisabledProductTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<actionGroup ref="AdminSetStockStatusActionGroup" stepKey="outOfStockStatus">
126126
<argument name="stockStatus" value="Out of Stock"/>
127127
</actionGroup>
128-
128+
129129
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveSecondProductForm"/>
130130
<!-- Go to created customer page -->
131131
<comment userInput="Go to created customer page" stepKey="goToCreatedCustomerPage"/>
@@ -158,7 +158,7 @@
158158
<waitForPageLoad stepKey="waitForPageLoad"/>
159159
<click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickToAddProductToOrder"/>
160160
<waitForPageLoad stepKey="waitForNewOrderPageLoad"/>
161-
<see userInput="This product is out of stock." stepKey="seeTheErrorMessageDisplayed"/>
161+
<see userInput="There are no source items with the in stock status" stepKey="seeTheErrorMessageDisplayed"/>
162162

163163
<actionGroup ref="NavigateToNewOrderPageExistingCustomerActionGroup" stepKey="createNewOrderThirdTime">
164164
<argument name="customer" value="$createCustomer$"/>

dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function updateItemDataProvider(): array
326326
'use_config_backorders' => 0,
327327
'backorders' => Stock::BACKORDERS_NO,
328328
],
329-
'This product is out of stock.'
329+
'There are no source items with the in stock status'
330330
],
331331
[
332332
[

0 commit comments

Comments
 (0)