diff --git a/app/code/Magento/InventoryCatalog/Model/GetProductTypesBySkus.php b/app/code/Magento/InventoryCatalog/Model/GetProductTypesBySkus.php
index a803304344d95..0b029ee2dcc34 100644
--- a/app/code/Magento/InventoryCatalog/Model/GetProductTypesBySkus.php
+++ b/app/code/Magento/InventoryCatalog/Model/GetProductTypesBySkus.php
@@ -36,13 +36,6 @@ public function __construct(
public function execute(array $skus)
{
$typesBySkus = $this->getProductTypesBySkusResource->execute($skus);
- $notFoundedSkus = array_diff($skus, array_keys($typesBySkus));
-
- if (!empty($notFoundedSkus)) {
- throw new InputException(
- __('Following products with requested skus were not found: %1', implode($notFoundedSkus, ', '))
- );
- }
$preparedTypesBySkus = [];
foreach ($typesBySkus as $sku => $type) {
diff --git a/app/code/Magento/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php b/app/code/Magento/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php
index 6288215490f45..bbc221be95cfe 100644
--- a/app/code/Magento/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php
+++ b/app/code/Magento/InventoryCatalog/Test/Integration/GetProductTypesBySkusTest.php
@@ -51,14 +51,11 @@ public function testExecute()
/**
* @magentoDataFixture ../../../../app/code/Magento/InventoryCatalog/Test/_files/products_all_types.php
- *
- * @expectedException \Magento\Framework\Exception\InputException
- * @expectedExceptionMessage Following products with requested skus were not found: not_existed_1, not_existed_2
*/
public function testExecuteWithNotExistedSkus()
{
$skus = ['not_existed_1', 'not_existed_2', 'simple_sku'];
- $this->getProductTypesBySkus->execute($skus);
+ self::assertEquals(['simple_sku' => 'simple'], $this->getProductTypesBySkus->execute($skus));
}
}
diff --git a/app/code/Magento/InventoryCatalogApi/Model/GetProductTypesBySkusInterface.php b/app/code/Magento/InventoryCatalogApi/Model/GetProductTypesBySkusInterface.php
index 78c701dd9153d..6a72726fa3f7e 100644
--- a/app/code/Magento/InventoryCatalogApi/Model/GetProductTypesBySkusInterface.php
+++ b/app/code/Magento/InventoryCatalogApi/Model/GetProductTypesBySkusInterface.php
@@ -7,8 +7,6 @@
namespace Magento\InventoryCatalogApi\Model;
-use Magento\Framework\Exception\InputException;
-
/**
* Get product types id by product skus.
*
@@ -19,7 +17,6 @@ interface GetProductTypesBySkusInterface
/**
* @param array $skus
* @return array (key: 'sku', value: 'product_type')
- * @throws InputException
*/
public function execute(array $skus);
}
diff --git a/app/code/Magento/InventoryConfiguration/Model/GetStockItemConfiguration.php b/app/code/Magento/InventoryConfiguration/Model/GetStockItemConfiguration.php
index 41acdca70e1b5..845f955559e2a 100644
--- a/app/code/Magento/InventoryConfiguration/Model/GetStockItemConfiguration.php
+++ b/app/code/Magento/InventoryConfiguration/Model/GetStockItemConfiguration.php
@@ -15,6 +15,7 @@
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
use Magento\InventorySalesApi\Model\GetStockItemDataInterface;
use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Exception\InputException;
/**
* @inheritdoc
@@ -94,17 +95,21 @@ private function getLegacyStockItem(string $sku): StockItemInterface
{
$searchCriteria = $this->legacyStockItemCriteriaFactory->create();
- $productId = $this->getProductIdsBySkus->execute([$sku])[$sku];
+ try {
+ $productId = $this->getProductIdsBySkus->execute([$sku])[$sku];
+ } catch (InputException $skuNotFoundInCatalog) {
+ $stockItem = \Magento\Framework\App\ObjectManager::getInstance()->create(StockItemInterface::class);
+ $stockItem->setManageStock(true); // Make possible to Manage Stock for Products removed from Catalog
+ return $stockItem;
+ }
$searchCriteria->addFilter(StockItemInterface::PRODUCT_ID, StockItemInterface::PRODUCT_ID, $productId);
- // TODO We use Stock::DEFAULT_STOCK_ID until we have proper multi-stock item configuration
+ // Stock::DEFAULT_STOCK_ID is used until we have proper multi-stock item configuration
$searchCriteria->addFilter(StockItemInterface::STOCK_ID, StockItemInterface::STOCK_ID, Stock::DEFAULT_STOCK_ID);
$stockItemCollection = $this->legacyStockItemRepository->getList($searchCriteria);
if ($stockItemCollection->getTotalCount() === 0) {
- // TODO:
return \Magento\Framework\App\ObjectManager::getInstance()->create(StockItemInterface::class);
- #throw new LocalizedException(__('Legacy stock item is not found'));
}
$stockItems = $stockItemCollection->getItems();
diff --git a/app/code/Magento/InventoryIndexer/Indexer/SelectBuilder.php b/app/code/Magento/InventoryIndexer/Indexer/SelectBuilder.php
index 175773034e8e2..9b6a6e552e1ce 100644
--- a/app/code/Magento/InventoryIndexer/Indexer/SelectBuilder.php
+++ b/app/code/Magento/InventoryIndexer/Indexer/SelectBuilder.php
@@ -63,11 +63,11 @@ public function execute(int $stockId): Select
$sourceCodes = $this->getSourceCodes($stockId);
$select = $connection->select();
- $select->joinInner(
+ $select->joinLeft(
['product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')],
'product_entity.sku = source_item.sku',
[]
- )->joinInner(
+ )->joinLeft(
['legacy_stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item')],
'product_entity.entity_id = legacy_stock_item.product_id',
[]
diff --git a/app/code/Magento/InventorySales/Model/PlaceReservationsForSalesEvent.php b/app/code/Magento/InventorySales/Model/PlaceReservationsForSalesEvent.php
index 74e5a027dc2c6..6ad61658c6738 100644
--- a/app/code/Magento/InventorySales/Model/PlaceReservationsForSalesEvent.php
+++ b/app/code/Magento/InventorySales/Model/PlaceReservationsForSalesEvent.php
@@ -89,7 +89,10 @@ public function execute(array $items, SalesChannelInterface $salesChannel, Sales
$reservations = [];
/** @var ItemToSellInterface $item */
foreach ($items as $item) {
- if (true === $this->isSourceItemManagementAllowedForProductType->execute($productTypes[$item->getSku()])) {
+ $currentSku = $item->getSku();
+ $skuNotExistInCatalog = !isset($productTypes[$currentSku]);
+ if ($skuNotExistInCatalog ||
+ $this->isSourceItemManagementAllowedForProductType->execute($productTypes[$currentSku])) {
$reservations[] = $this->reservationBuilder
->setSku($item->getSku())
->setQuantity((float)$item->getQuantity())
diff --git a/app/code/Magento/InventorySales/Model/ResourceModel/IsStockItemSalableCondition/SourceItemStatusCondition.php b/app/code/Magento/InventorySales/Model/ResourceModel/IsStockItemSalableCondition/SkuIsAbsentInCatalogCondition.php
similarity index 59%
rename from app/code/Magento/InventorySales/Model/ResourceModel/IsStockItemSalableCondition/SourceItemStatusCondition.php
rename to app/code/Magento/InventorySales/Model/ResourceModel/IsStockItemSalableCondition/SkuIsAbsentInCatalogCondition.php
index 8fa1bc440f0ad..a472d8b0dd5e9 100644
--- a/app/code/Magento/InventorySales/Model/ResourceModel/IsStockItemSalableCondition/SourceItemStatusCondition.php
+++ b/app/code/Magento/InventorySales/Model/ResourceModel/IsStockItemSalableCondition/SkuIsAbsentInCatalogCondition.php
@@ -8,12 +8,11 @@
namespace Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition;
use Magento\Framework\DB\Select;
-use Magento\InventoryApi\Api\Data\SourceItemInterface;
/**
- * Source Item status condition
+ * Still build Stock Item index even when there is no corresponding SKU in catalog_product_entity table
*/
-class SourceItemStatusCondition implements GetIsStockItemSalableConditionInterface
+class SkuIsAbsentInCatalogCondition implements GetIsStockItemSalableConditionInterface
{
/**
* @inheritdoc
@@ -21,6 +20,6 @@ class SourceItemStatusCondition implements GetIsStockItemSalableConditionInterfa
*/
public function execute(Select $select): string
{
- return 'MAX(source_item.' . SourceItemInterface::STATUS . ') = ' . SourceItemInterface::STATUS_IN_STOCK;
+ return 'product_entity.sku IS NULL';
}
}
diff --git a/app/code/Magento/InventorySales/Plugin/InventoryReservationsApi/PreventAppendReservationOnNotManageItemsInStockPlugin.php b/app/code/Magento/InventorySales/Plugin/InventoryReservationsApi/PreventAppendReservationOnNotManageItemsInStockPlugin.php
index 8f0f9a1ac0037..ff9953d63e64b 100644
--- a/app/code/Magento/InventorySales/Plugin/InventoryReservationsApi/PreventAppendReservationOnNotManageItemsInStockPlugin.php
+++ b/app/code/Magento/InventorySales/Plugin/InventoryReservationsApi/PreventAppendReservationOnNotManageItemsInStockPlugin.php
@@ -61,7 +61,7 @@ public function aroundExecute(AppendReservationsInterface $subject, \Closure $pr
$reservation->getStockId()
);
- if ($stockItemConfiguration->isManageStock()) {
+ if ($stockItemConfiguration === null || $stockItemConfiguration->isManageStock()) {
$reservationToAppend[] = $reservation;
}
}
diff --git a/app/code/Magento/InventorySales/etc/di.xml b/app/code/Magento/InventorySales/etc/di.xml
index bc02d9495d039..cea1bc70f5614 100644
--- a/app/code/Magento/InventorySales/etc/di.xml
+++ b/app/code/Magento/InventorySales/etc/di.xml
@@ -44,6 +44,7 @@
- Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition\ManageStockCondition
- Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition\MinQtyStockCondition
+ - Magento\InventorySales\Model\ResourceModel\IsStockItemSalableCondition\SkuIsAbsentInCatalogCondition
diff --git a/app/code/Magento/InventoryShipping/Model/SourceDeduction/SourceDeductionService.php b/app/code/Magento/InventoryShipping/Model/SourceDeduction/SourceDeductionService.php
index 6b31a1a2342d2..3add87ccc50bb 100644
--- a/app/code/Magento/InventoryShipping/Model/SourceDeduction/SourceDeductionService.php
+++ b/app/code/Magento/InventoryShipping/Model/SourceDeduction/SourceDeductionService.php
@@ -98,7 +98,8 @@ public function execute(SourceDeductionRequestInterface $sourceDeductionRequest)
$stockId
);
- if (!$stockItemConfiguration->isManageStock()) {
+ if ($stockItemConfiguration === null || !$stockItemConfiguration->isManageStock()) {
+ //Product not assigned to Given Stock or we No need to Manage Stock
continue;
}
diff --git a/app/code/Magento/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProvider.php b/app/code/Magento/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProvider.php
index 8a8e43ab7bdf4..1ffafc948d0c6 100644
--- a/app/code/Magento/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProvider.php
+++ b/app/code/Magento/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProvider.php
@@ -169,6 +169,7 @@ private function getSources(int $stockId, string $sku, float $qty): array
private function isManageStock($itemSku, $stockId)
{
$stockItemConfiguration = $this->getStockItemConfiguration->execute($itemSku, $stockId);
+
if (!empty($stockItemConfiguration)) {
return $stockItemConfiguration->isManageStock();
}