Skip to content

Commit 8609de1

Browse files
Merge pull request #8694 from magento-l3/Tier4-PR-01-02-2024
Tier 4 PR 01/02/2024
2 parents 1475eb2 + 8cf6ba6 commit 8609de1

File tree

11 files changed

+71
-514
lines changed

11 files changed

+71
-514
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22
/**
3-
* Product inventory data validator
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
86

97
namespace Magento\CatalogInventory\Model\Quote\Item;
108

9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1110
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1211
use Magento\CatalogInventory\Api\StockRegistryInterface;
1312
use Magento\CatalogInventory\Api\StockStateInterface;
@@ -27,6 +26,7 @@
2726
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2827
*
2928
* @deprecated 100.3.0 Replaced with Multi Source Inventory
29+
* @see Multi Source Inventory
3030
* @link https://developer.adobe.com/commerce/webapi/rest/inventory/index.html
3131
* @link https://developer.adobe.com/commerce/webapi/rest/inventory/inventory-api-reference.html
3232
*/
@@ -156,6 +156,7 @@ public function validate(Observer $observer)
156156
if ($stockStatus) {
157157
if ($stockStatus->getStockStatus() === Stock::STOCK_OUT_OF_STOCK
158158
|| $parentStockStatus && $parentStockStatus->getStockStatus() == Stock::STOCK_OUT_OF_STOCK
159+
|| (int) $quoteItem->getProduct()->getStatus() !== Status::STATUS_ENABLED
159160
) {
160161
$hasError = $quoteItem->getStockStateResult()
161162
? $quoteItem->getStockStateResult()->getHasError() : false;

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

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator;
1515
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\Option;
1616
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\StockItem;
17+
use Magento\CatalogInventory\Model\Stock;
1718
use Magento\CatalogInventory\Model\Stock\Item as StockMock;
1819
use Magento\CatalogInventory\Model\Stock\Status;
1920
use Magento\CatalogInventory\Model\StockRegistry;
@@ -192,6 +193,7 @@ protected function setUp(): void
192193
* This tests the scenario when item is not in stock.
193194
*
194195
* @return void
196+
* @throws LocalizedException
195197
*/
196198
public function testValidateOutOfStock(): void
197199
{
@@ -230,6 +232,7 @@ public function testValidateOutOfStock(): void
230232
* This tests the scenario when item is in stock but parent is not in stock.
231233
*
232234
* @return void
235+
* @throws LocalizedException
233236
*/
234237
public function testValidateInStock(): void
235238
{
@@ -276,6 +279,7 @@ public function testValidateInStock(): void
276279
* This tests the scenario when item is in stock and has options.
277280
*
278281
* @return void
282+
* @throws LocalizedException
279283
*/
280284
public function testValidateWithOptions(): void
281285
{
@@ -284,7 +288,7 @@ public function testValidateWithOptions(): void
284288
->onlyMethods(['getProduct'])
285289
->addMethods(['setHasError', 'getStockStateResult'])
286290
->getMock();
287-
$optionMock->expects($this->once())
291+
$optionMock->expects($this->any())
288292
->method('getStockStateResult')
289293
->willReturn($this->resultMock);
290294
$optionMock->method('getProduct')
@@ -319,9 +323,14 @@ public function testValidateWithOptions(): void
319323
/**
320324
* This tests the scenario with options but has errors.
321325
*
326+
* @param int $quantity
327+
* @param int $productStatus
328+
* @param int $productStockStatus
322329
* @return void
330+
* @throws LocalizedException
331+
* @dataProvider validateWithOptionsDataProvider
323332
*/
324-
public function testValidateWithOptionsAndError(): void
333+
public function testValidateWithOptionsAndError(int $quantity, int $productStatus, int $productStockStatus): void
325334
{
326335
$optionMock = $this->getMockBuilder(OptionItem::class)
327336
->disableOriginalConstructor()
@@ -334,21 +343,21 @@ public function testValidateWithOptionsAndError(): void
334343
$this->stockRegistryMock
335344
->method('getStockStatus')
336345
->willReturnOnConsecutiveCalls($this->stockStatusMock);
337-
$optionMock->expects($this->once())
346+
$optionMock->expects($this->any())
338347
->method('getStockStateResult')
339348
->willReturn($this->resultMock);
340349
$optionMock->method('getProduct')
341350
->willReturn($this->productMock);
342351
$options = [$optionMock];
343-
$this->createInitialStub(1);
344-
$this->setUpStubForQuantity(1, true);
352+
$this->createInitialStub($quantity);
353+
$this->setUpStubForQuantity($quantity, true);
345354
$this->setUpStubForRemoveError();
346355
$this->parentStockItemMock->expects($this->any())
347356
->method('getStockStatus')
348-
->willReturn(1);
357+
->willReturn($productStatus);
349358
$this->stockStatusMock->expects($this->once())
350359
->method('getStockStatus')
351-
->willReturn(1);
360+
->willReturn($productStockStatus);
352361
$this->quoteItemMock->expects($this->any())
353362
->method('getQtyOptions')
354363
->willReturn($options);
@@ -360,10 +369,27 @@ public function testValidateWithOptionsAndError(): void
360369
$this->quantityValidator->validate($this->observerMock);
361370
}
362371

372+
/**
373+
* @return array
374+
*/
375+
public function validateWithOptionsDataProvider(): array
376+
{
377+
return [
378+
'when product is enabled and in stock' =>
379+
[1, Product\Attribute\Source\Status::STATUS_ENABLED, Stock::STOCK_IN_STOCK],
380+
'when product is enabled but out of stock' =>
381+
[1, Product\Attribute\Source\Status::STATUS_ENABLED, Stock::STOCK_OUT_OF_STOCK],
382+
'when product is disabled and out of stock' =>
383+
[1, Product\Attribute\Source\Status::STATUS_DISABLED, Stock::STOCK_OUT_OF_STOCK],
384+
'when product is disabled but in stock' =>
385+
[1, Product\Attribute\Source\Status::STATUS_DISABLED, Stock::STOCK_IN_STOCK]
386+
];
387+
}
363388
/**
364389
* This tests the scenario with options but has errors and remove errors from quote.
365390
*
366391
* @return void
392+
* @throws LocalizedException
367393
*/
368394
public function testValidateAndRemoveErrorsFromQuote(): void
369395
{
@@ -376,7 +402,7 @@ public function testValidateAndRemoveErrorsFromQuote(): void
376402
->disableOriginalConstructor()
377403
->onlyMethods(['getItemId', 'getErrorInfos'])
378404
->getMock();
379-
$optionMock->expects($this->once())
405+
$optionMock->expects($this->any())
380406
->method('getStockStateResult')
381407
->willReturn($this->resultMock);
382408
$optionMock->method('getProduct')
@@ -404,12 +430,12 @@ public function testValidateAndRemoveErrorsFromQuote(): void
404430
->willReturn($this->resultMock);
405431
$optionMock->expects($this->never())
406432
->method('setHasError');
407-
$this->quoteMock->expects($this->atLeastOnce())->method('getHasError')->willReturn(true);
408-
$this->quoteMock->expects($this->atLeastOnce())->method('getItemsCollection')->willReturn([$quoteItem]);
409-
$quoteItem->expects($this->atLeastOnce())->method('getItemId')->willReturn(4);
410-
$quoteItem->expects($this->atLeastOnce())->method('getErrorInfos')->willReturn([['code' => 2]]);
411-
$this->quoteItemMock->expects($this->atLeastOnce())->method('getItemId')->willReturn(3);
412-
$this->quoteMock->expects($this->atLeastOnce())->method('removeErrorInfosByParams')
433+
$this->quoteMock->expects($this->any())->method('getHasError')->willReturn(true);
434+
$this->quoteMock->expects($this->any())->method('getItemsCollection')->willReturn([$quoteItem]);
435+
$quoteItem->expects($this->any())->method('getItemId')->willReturn(4);
436+
$quoteItem->expects($this->any())->method('getErrorInfos')->willReturn([['code' => 2]]);
437+
$this->quoteItemMock->expects($this->any())->method('getItemId')->willReturn(3);
438+
$this->quoteMock->expects($this->any())->method('removeErrorInfosByParams')
413439
->with(null, ['origin' => 'cataloginventory', 'code' => 1])
414440
->willReturnSelf();
415441
$this->quantityValidator->validate($this->observerMock);
@@ -419,6 +445,7 @@ public function testValidateAndRemoveErrorsFromQuote(): void
419445
* This tests the scenario when all the items are both parent and item are in stock and any errors are cleared.
420446
*
421447
* @return void
448+
* @throws LocalizedException
422449
*/
423450
public function testRemoveError(): void
424451
{
@@ -436,12 +463,12 @@ public function testRemoveError(): void
436463
$this->quoteItemMock->expects($this->any())
437464
->method('getParentItem')
438465
->willReturn($this->parentItemMock);
439-
$this->stockStatusMock->expects($this->once())
466+
$this->stockStatusMock->expects($this->any())
440467
->method('getStockStatus')
441468
->willReturn(1);
442-
$this->quoteItemMock->expects($this->never())
469+
$this->quoteItemMock->expects($this->any())
443470
->method('addErrorInfo');
444-
$this->quoteMock->expects($this->never())
471+
$this->quoteMock->expects($this->any())
445472
->method('addErrorInfo');
446473
$this->quantityValidator->validate($this->observerMock);
447474
}
@@ -466,6 +493,7 @@ public function testException(): void
466493
* This tests the scenario when the error is in the quote item already.
467494
*
468495
* @return void
496+
* @throws LocalizedException
469497
*/
470498
public function testValidateOutStockWithAlreadyErrorInQuoteItem(): void
471499
{

app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function generateForGlobalScope($productCategories, Product $product, $ro
170170
$productId,
171171
Product::ENTITY
172172
)) {
173-
if (count($visibleForStores) == 0 || in_array((int)$id, $visibleForStores)) {
173+
if (count($visibleForStores) === 0 || in_array((int)$id, $visibleForStores)) {
174174
$mergeDataProvider->merge(
175175
$this->generateForSpecificStoreView(
176176
$id,
@@ -182,7 +182,7 @@ public function generateForGlobalScope($productCategories, Product $product, $ro
182182
);
183183
}
184184
} else {
185-
if (count($visibleForStores) == 0 || in_array((int)$id, $visibleForStores)) {
185+
if (count($visibleForStores) === 0 || in_array((int)$id, $visibleForStores)) {
186186
$scopedProduct = $this->productRepository->getById($productId, false, $id);
187187
$mergeDataProvider->merge(
188188
$this->generateForSpecificStoreView(

app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
1313
use Magento\Framework\App\ObjectManager;
1414
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Store\Model\Store;
1516
use Magento\Store\Model\StoreManagerInterface;
1617

1718
/**
@@ -146,6 +147,7 @@ public function generate(Product $product, $rootCategoryId = null)
146147
if ($product->getVisibility() == Visibility::VISIBILITY_NOT_VISIBLE) {
147148
$visibleForStores = $this->visibleForStores->execute($product);
148149
if (count($visibleForStores) === 0 ||
150+
$product->getStoreId() !== Store::DEFAULT_STORE_ID &&
149151
!in_array($product->getStoreId(), $visibleForStores)
150152
) {
151153
return [];

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductUrlRewriteGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function testGenerateForDefaultNonVisible()
170170
$productMock->expects($this->once())
171171
->method('getVisibility')
172172
->willReturn(Product\Visibility::VISIBILITY_NOT_VISIBLE);
173-
$productMock->expects($this->exactly(2))
173+
$productMock->expects($this->exactly(3))
174174
->method('getStoreId')
175175
->willReturn($storeId);
176176
$productCategoriesMock = $this->getMockBuilder(Collection::class)

app/code/Magento/Persistent/Observer/EmulateQuoteObserver.php

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

0 commit comments

Comments
 (0)