Skip to content

Commit 28757c2

Browse files
authored
Merge pull request magento#1292 from magento-engcom/issue-1236
Issue 1236: support of order operations for deleted from Catlog products
2 parents 36c638e + 7b4f27e commit 28757c2

File tree

11 files changed

+24
-27
lines changed

11 files changed

+24
-27
lines changed

app/code/Magento/InventoryCatalog/Model/GetProductTypesBySkus.php

-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ public function __construct(
3636
public function execute(array $skus)
3737
{
3838
$typesBySkus = $this->getProductTypesBySkusResource->execute($skus);
39-
$notFoundedSkus = array_diff($skus, array_keys($typesBySkus));
40-
41-
if (!empty($notFoundedSkus)) {
42-
throw new InputException(
43-
__('Following products with requested skus were not found: %1', implode($notFoundedSkus, ', '))
44-
);
45-
}
4639

4740
$preparedTypesBySkus = [];
4841
foreach ($typesBySkus as $sku => $type) {

app/code/Magento/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ public function testExecute()
5151

5252
/**
5353
* @magentoDataFixture ../../../../app/code/Magento/InventoryCatalog/Test/_files/products_all_types.php
54-
*
55-
* @expectedException \Magento\Framework\Exception\InputException
56-
* @expectedExceptionMessage Following products with requested skus were not found: not_existed_1, not_existed_2
5754
*/
5855
public function testExecuteWithNotExistedSkus()
5956
{
6057
$skus = ['not_existed_1', 'not_existed_2', 'simple_sku'];
6158

62-
$this->getProductTypesBySkus->execute($skus);
59+
self::assertEquals(['simple_sku' => 'simple'], $this->getProductTypesBySkus->execute($skus));
6360
}
6461
}

app/code/Magento/InventoryCatalogApi/Model/GetProductTypesBySkusInterface.php

-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\InventoryCatalogApi\Model;
99

10-
use Magento\Framework\Exception\InputException;
11-
1210
/**
1311
* Get product types id by product skus.
1412
*
@@ -19,7 +17,6 @@ interface GetProductTypesBySkusInterface
1917
/**
2018
* @param array $skus
2119
* @return array (key: 'sku', value: 'product_type')
22-
* @throws InputException
2320
*/
2421
public function execute(array $skus);
2522
}

app/code/Magento/InventoryConfiguration/Model/GetStockItemConfiguration.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
1616
use Magento\InventorySalesApi\Model\GetStockItemDataInterface;
1717
use Magento\Framework\Exception\LocalizedException;
18+
use Magento\Framework\Exception\InputException;
1819

1920
/**
2021
* @inheritdoc
@@ -94,17 +95,21 @@ private function getLegacyStockItem(string $sku): StockItemInterface
9495
{
9596
$searchCriteria = $this->legacyStockItemCriteriaFactory->create();
9697

97-
$productId = $this->getProductIdsBySkus->execute([$sku])[$sku];
98+
try {
99+
$productId = $this->getProductIdsBySkus->execute([$sku])[$sku];
100+
} catch (InputException $skuNotFoundInCatalog) {
101+
$stockItem = \Magento\Framework\App\ObjectManager::getInstance()->create(StockItemInterface::class);
102+
$stockItem->setManageStock(true); // Make possible to Manage Stock for Products removed from Catalog
103+
return $stockItem;
104+
}
98105
$searchCriteria->addFilter(StockItemInterface::PRODUCT_ID, StockItemInterface::PRODUCT_ID, $productId);
99106

100-
// TODO We use Stock::DEFAULT_STOCK_ID until we have proper multi-stock item configuration
107+
// Stock::DEFAULT_STOCK_ID is used until we have proper multi-stock item configuration
101108
$searchCriteria->addFilter(StockItemInterface::STOCK_ID, StockItemInterface::STOCK_ID, Stock::DEFAULT_STOCK_ID);
102109

103110
$stockItemCollection = $this->legacyStockItemRepository->getList($searchCriteria);
104111
if ($stockItemCollection->getTotalCount() === 0) {
105-
// TODO:
106112
return \Magento\Framework\App\ObjectManager::getInstance()->create(StockItemInterface::class);
107-
#throw new LocalizedException(__('Legacy stock item is not found'));
108113
}
109114

110115
$stockItems = $stockItemCollection->getItems();

app/code/Magento/InventoryIndexer/Indexer/SelectBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public function execute(int $stockId): Select
6363
$sourceCodes = $this->getSourceCodes($stockId);
6464

6565
$select = $connection->select();
66-
$select->joinInner(
66+
$select->joinLeft(
6767
['product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')],
6868
'product_entity.sku = source_item.sku',
6969
[]
70-
)->joinInner(
70+
)->joinLeft(
7171
['legacy_stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item')],
7272
'product_entity.entity_id = legacy_stock_item.product_id',
7373
[]

app/code/Magento/InventorySales/Model/PlaceReservationsForSalesEvent.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public function execute(array $items, SalesChannelInterface $salesChannel, Sales
8989
$reservations = [];
9090
/** @var ItemToSellInterface $item */
9191
foreach ($items as $item) {
92-
if (true === $this->isSourceItemManagementAllowedForProductType->execute($productTypes[$item->getSku()])) {
92+
$currentSku = $item->getSku();
93+
$skuNotExistInCatalog = !isset($productTypes[$currentSku]);
94+
if ($skuNotExistInCatalog ||
95+
$this->isSourceItemManagementAllowedForProductType->execute($productTypes[$currentSku])) {
9396
$reservations[] = $this->reservationBuilder
9497
->setSku($item->getSku())
9598
->setQuantity((float)$item->getQuantity())
+3-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
namespace Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition;
99

1010
use Magento\Framework\DB\Select;
11-
use Magento\InventoryApi\Api\Data\SourceItemInterface;
1211

1312
/**
14-
* Source Item status condition
13+
* Still build Stock Item index even when there is no corresponding SKU in catalog_product_entity table
1514
*/
16-
class SourceItemStatusCondition implements GetIsStockItemSalableConditionInterface
15+
class SkuIsAbsentInCatalogCondition implements GetIsStockItemSalableConditionInterface
1716
{
1817
/**
1918
* @inheritdoc
2019
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2120
*/
2221
public function execute(Select $select): string
2322
{
24-
return 'MAX(source_item.' . SourceItemInterface::STATUS . ') = ' . SourceItemInterface::STATUS_IN_STOCK;
23+
return 'product_entity.sku IS NULL';
2524
}
2625
}

app/code/Magento/InventorySales/Plugin/InventoryReservationsApi/PreventAppendReservationOnNotManageItemsInStockPlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function aroundExecute(AppendReservationsInterface $subject, \Closure $pr
6161
$reservation->getStockId()
6262
);
6363

64-
if ($stockItemConfiguration->isManageStock()) {
64+
if ($stockItemConfiguration === null || $stockItemConfiguration->isManageStock()) {
6565
$reservationToAppend[] = $reservation;
6666
}
6767
}

app/code/Magento/InventorySales/etc/di.xml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<item name="manage_stock" xsi:type="object">Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition\ManageStockCondition</item>
4545
<!-- min_qty condition includes source_item_status check (need to proper work of min_qty) -->
4646
<item name="min_qty" xsi:type="object">Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition\MinQtyStockCondition</item>
47+
<item name="non_existing_legacy_sku" xsi:type="object">Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition\SkuIsAbsentInCatalogCondition</item>
4748
</argument>
4849
</arguments>
4950
</type>

app/code/Magento/InventoryShipping/Model/SourceDeduction/SourceDeductionService.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public function execute(SourceDeductionRequestInterface $sourceDeductionRequest)
9898
$stockId
9999
);
100100

101-
if (!$stockItemConfiguration->isManageStock()) {
101+
if ($stockItemConfiguration === null || !$stockItemConfiguration->isManageStock()) {
102+
//Product not assigned to Given Stock or we No need to Manage Stock
102103
continue;
103104
}
104105

app/code/Magento/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private function getSources(int $stockId, string $sku, float $qty): array
169169
private function isManageStock($itemSku, $stockId)
170170
{
171171
$stockItemConfiguration = $this->getStockItemConfiguration->execute($itemSku, $stockId);
172+
172173
if (!empty($stockItemConfiguration)) {
173174
return $stockItemConfiguration->isManageStock();
174175
}

0 commit comments

Comments
 (0)