Skip to content

Commit 0167614

Browse files
Merge pull request #624 from magento/MAGECLOUD-4428
MAGECLOUD-4428: [2002.0] Deliver patches for MSI
2 parents 68f81e0 + 01a56fb commit 0167614

7 files changed

+517
-0
lines changed

patches.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,33 @@
198198
"Fix credis pipeline issue": {
199199
"1.6": "MAGETWO-67097__fix_credis_pipeline_bug__2.1.4.patch"
200200
}
201+
},
202+
"magento/module-inventory-catalog": {
203+
"Price indexer fails with large catalogs": {
204+
">=1.0.3 <1.0.6": "MSI-2210__price_indexer_fails_with_large_catalogs__1.0.3.patch"
205+
}
206+
},
207+
"magento/module-inventory-indexer": {
208+
"Avoid quering inventory default stock view in storefront": {
209+
">=1.0.3 <1.0.6": "MSI-GH-2350__avoid_quering_inventory_default_stock_view_in_storefront__1.0.3.patch"
210+
},
211+
"Avoid group concat from source item indexer": {
212+
">=1.0.3 <1.0.6": "MSI-GH-2515__eliminate_group_concat_from_source_item_indexer__indexer__1.0.3.patch"
213+
}
214+
},
215+
"magento/module-inventory-reservations": {
216+
"Avoid group concat from source item indexer": {
217+
">=1.0.3 <1.0.6": "MSI-GH-2515__eliminate_group_concat_from_source_item_indexer__reservations__1.0.3.patch"
218+
}
219+
},
220+
"magento/module-inventory-configurable-product-indexer": {
221+
"Avoid group concat from source item indexer": {
222+
">=1.0.3 <1.0.5": "MSI-GH-2515__eliminate_group_concat_from_source_item_indexer__configurable-product-indexer__1.0.3.patch"
223+
}
224+
},
225+
"magento/module-inventory-grouped-product-indexer": {
226+
"Avoid group concat from source item indexer": {
227+
">=1.0.3 <1.0.5": "MSI-GH-2515__eliminate_group_concat_from_source_item_indexer__grouped-product-indexer__1.0.3.patch"
228+
}
201229
}
202230
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
diff -Nuar a/vendor/magento/module-inventory-catalog/Plugin/CatalogInventory/Model/Indexer/ModifySelectInProductPriceIndexFilter.php b/vendor/magento/module-inventory-catalog/Plugin/CatalogInventory/Model/Indexer/ModifySelectInProductPriceIndexFilter.php
2+
--- a/vendor/magento/module-inventory-catalog/Plugin/CatalogInventory/Model/Indexer/ModifySelectInProductPriceIndexFilter.php
3+
+++ b/vendor/magento/module-inventory-catalog/Plugin/CatalogInventory/Model/Indexer/ModifySelectInProductPriceIndexFilter.php
4+
@@ -11,6 +11,8 @@
5+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
6+
use Magento\CatalogInventory\Model\Indexer\ProductPriceIndexFilter;
7+
use Magento\Framework\App\ResourceConnection;
8+
+use Magento\InventoryApi\Api\Data\StockInterface;
9+
+use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface;
10+
use Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface;
11+
use Magento\InventorySalesApi\Model\StockByWebsiteIdResolverInterface;
12+
13+
@@ -39,22 +41,30 @@ class ModifySelectInProductPriceIndexFilter
14+
*/
15+
private $stockByWebsiteIdResolver;
16+
17+
+ /**
18+
+ * @var DefaultStockProviderInterface
19+
+ */
20+
+ private $defaultStockProvider;
21+
+
22+
/**
23+
* @param StockIndexTableNameResolverInterface $stockIndexTableNameResolver
24+
* @param StockConfigurationInterface $stockConfiguration
25+
* @param ResourceConnection $resourceConnection
26+
* @param StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver
27+
+ * @param DefaultStockProviderInterface $defaultStockProvider
28+
*/
29+
public function __construct(
30+
StockIndexTableNameResolverInterface $stockIndexTableNameResolver,
31+
StockConfigurationInterface $stockConfiguration,
32+
ResourceConnection $resourceConnection,
33+
- StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver
34+
+ StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver,
35+
+ DefaultStockProviderInterface $defaultStockProvider
36+
) {
37+
$this->stockIndexTableNameResolver = $stockIndexTableNameResolver;
38+
$this->stockConfiguration = $stockConfiguration;
39+
$this->resourceConnection = $resourceConnection;
40+
$this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver;
41+
+ $this->defaultStockProvider = $defaultStockProvider;
42+
}
43+
44+
/**
45+
@@ -84,7 +94,8 @@ public function aroundModifyPrice(
46+
$select->from(['price_index' => $priceTable->getTableName()], []);
47+
$priceEntityField = $priceTable->getEntityField();
48+
49+
- if ($this->resourceConnection->getConnection()->isTableExists($stockTable)) {
50+
+ if (!$this->isDefaultStock($stock)
51+
+ && $this->resourceConnection->getConnection()->isTableExists($stockTable)) {
52+
$select->joinInner(
53+
['product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')],
54+
"product_entity.entity_id = price_index.{$priceEntityField}",
55+
@@ -95,6 +106,17 @@ public function aroundModifyPrice(
56+
[]
57+
);
58+
$select->where('inventory_stock.is_salable = 0 OR inventory_stock.is_salable IS NULL');
59+
+ } else {
60+
+ $legacyStockTableName = $this->resourceConnection->getTableName('cataloginventory_stock_status');
61+
+ $select->joinLeft(
62+
+ ['stock_status' => $legacyStockTableName],
63+
+ sprintf(
64+
+ 'stock_status.product_id = price_index.%s',
65+
+ $priceEntityField
66+
+ ),
67+
+ []
68+
+ );
69+
+ $select->where('stock_status.stock_status = 0 OR stock_status.stock_status IS NULL');
70+
}
71+
72+
$select->where('price_index.website_id = ?', $websiteId);
73+
@@ -126,4 +148,15 @@ private function getWebsiteIdsFromProducts(array $entityIds): array
74+
75+
return $result;
76+
}
77+
+
78+
+ /**
79+
+ * Checks if inventory stock is DB view
80+
+ *
81+
+ * @param StockInterface $stock
82+
+ * @return bool
83+
+ */
84+
+ private function isDefaultStock(StockInterface $stock): bool
85+
+ {
86+
+ return (int)$stock->getStockId() === $this->defaultStockProvider->getId();
87+
+ }
88+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
diff -Nuar a/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemData.php b/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemData.php
2+
--- a/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemData.php
3+
+++ b/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemData.php
4+
@@ -12,6 +12,8 @@
5+
use Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface;
6+
use Magento\InventorySalesApi\Model\GetStockItemDataInterface;
7+
use Magento\InventoryIndexer\Indexer\IndexStructure;
8+
+use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface;
9+
+use Magento\InventoryCatalogApi\Model\GetProductIdsBySkusInterface;
10+
11+
/**
12+
* @inheritdoc
13+
@@ -28,16 +30,32 @@ class GetStockItemData implements GetStockItemDataInterface
14+
*/
15+
private $stockIndexTableNameResolver;
16+
17+
+ /**
18+
+ * @var DefaultStockProviderInterface
19+
+ */
20+
+ private $defaultStockProvider;
21+
+
22+
+ /**
23+
+ * @var GetProductIdsBySkusInterface
24+
+ */
25+
+ private $getProductIdsBySkus;
26+
+
27+
/**
28+
* @param ResourceConnection $resource
29+
* @param StockIndexTableNameResolverInterface $stockIndexTableNameResolver
30+
+ * @param DefaultStockProviderInterface $defaultStockProvider
31+
+ * @param GetProductIdsBySkusInterface $getProductIdsBySkus
32+
*/
33+
public function __construct(
34+
ResourceConnection $resource,
35+
- StockIndexTableNameResolverInterface $stockIndexTableNameResolver
36+
+ StockIndexTableNameResolverInterface $stockIndexTableNameResolver,
37+
+ DefaultStockProviderInterface $defaultStockProvider,
38+
+ GetProductIdsBySkusInterface $getProductIdsBySkus
39+
) {
40+
$this->resource = $resource;
41+
$this->stockIndexTableNameResolver = $stockIndexTableNameResolver;
42+
+ $this->defaultStockProvider = $defaultStockProvider;
43+
+ $this->getProductIdsBySkus = $getProductIdsBySkus;
44+
}
45+
46+
/**
47+
@@ -45,18 +63,29 @@ public function __construct(
48+
*/
49+
public function execute(string $sku, int $stockId): ?array
50+
{
51+
- $stockItemTableName = $this->stockIndexTableNameResolver->execute($stockId);
52+
-
53+
$connection = $this->resource->getConnection();
54+
- $select = $connection->select()
55+
- ->from(
56+
+ $select = $connection->select();
57+
+
58+
+ if ($this->defaultStockProvider->getId() === $stockId) {
59+
+ $productId = current($this->getProductIdsBySkus->execute([$sku]));
60+
+ $stockItemTableName = $this->resource->getTableName('cataloginventory_stock_status');
61+
+ $select->from(
62+
+ $stockItemTableName,
63+
+ [
64+
+ GetStockItemDataInterface::QUANTITY => 'qty',
65+
+ GetStockItemDataInterface::IS_SALABLE => 'stock_status',
66+
+ ]
67+
+ )->where('product_id = ?', $productId);
68+
+ } else {
69+
+ $stockItemTableName = $this->stockIndexTableNameResolver->execute($stockId);
70+
+ $select->from(
71+
$stockItemTableName,
72+
[
73+
GetStockItemDataInterface::QUANTITY => IndexStructure::QUANTITY,
74+
GetStockItemDataInterface::IS_SALABLE => IndexStructure::IS_SALABLE,
75+
]
76+
- )
77+
- ->where(IndexStructure::SKU . ' = ?', $sku);
78+
+ )->where(IndexStructure::SKU . ' = ?', $sku);
79+
+ }
80+
81+
try {
82+
if ($connection->isTableExists($stockItemTableName)) {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
diff -Nuar a/vendor/magento/module-inventory-configurable-product-indexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php b/vendor/magento/module-inventory-configurable-product-indexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php
2+
--- a/vendor/magento/module-inventory-configurable-product-indexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php
3+
+++ b/vendor/magento/module-inventory-configurable-product-indexer/Indexer/SourceItem/SiblingSkuListInStockProvider.php
4+
@@ -31,10 +31,6 @@ class SiblingSkuListInStockProvider
5+
*/
6+
private $skuListInStockFactory;
7+
8+
- /**
9+
- * @var int
10+
- */
11+
- private $groupConcatMaxLen;
12+
/**
13+
* @var MetadataPool
14+
*/
15+
@@ -56,7 +52,6 @@ class SiblingSkuListInStockProvider
16+
* @param ResourceConnection $resourceConnection
17+
* @param SkuListInStockFactory $skuListInStockFactory
18+
* @param MetadataPool $metadataPool
19+
- * @param int $groupConcatMaxLen
20+
* @param string $tableNameSourceItem
21+
* @param string $tableNameStockSourceLink
22+
*/
23+
@@ -64,13 +59,11 @@ public function __construct(
24+
ResourceConnection $resourceConnection,
25+
SkuListInStockFactory $skuListInStockFactory,
26+
MetadataPool $metadataPool,
27+
- int $groupConcatMaxLen,
28+
$tableNameSourceItem,
29+
$tableNameStockSourceLink
30+
) {
31+
$this->resourceConnection = $resourceConnection;
32+
$this->skuListInStockFactory = $skuListInStockFactory;
33+
- $this->groupConcatMaxLen = $groupConcatMaxLen;
34+
$this->metadataPool = $metadataPool;
35+
$this->tableNameSourceItem = $tableNameSourceItem;
36+
$this->tableNameStockSourceLink = $tableNameStockSourceLink;
37+
@@ -91,15 +84,13 @@ public function execute(array $sourceItemIds): array
38+
39+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
40+
$linkField = $metadata->getLinkField();
41+
+ $items = [];
42+
43+
$select = $connection
44+
->select()
45+
->from(
46+
['source_item' => $sourceItemTable],
47+
- [
48+
- SourceItemInterface::SKU =>
49+
- "GROUP_CONCAT(DISTINCT sibling_product_entity." . SourceItemInterface::SKU . " SEPARATOR ',')"
50+
- ]
51+
+ [SourceItemInterface::SKU => 'sibling_product_entity.' . SourceItemInterface::SKU]
52+
)->joinInner(
53+
['stock_source_link' => $sourceStockLinkTable],
54+
sprintf(
55+
@@ -124,11 +115,17 @@ public function execute(array $sourceItemIds): array
56+
['sibling_product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')],
57+
'sibling_product_entity.' . $linkField . ' = sibling_link.product_id',
58+
[]
59+
- )->where('source_item.source_item_id IN (?)', $sourceItemIds)
60+
- ->group(['stock_source_link.' . StockSourceLinkInterface::STOCK_ID]);
61+
+ )->where(
62+
+ 'source_item.source_item_id IN (?)',
63+
+ $sourceItemIds
64+
+ );
65+
+
66+
+ $dbStatement = $connection->query($select);
67+
+ while ($item = $dbStatement->fetch()) {
68+
+ $items[$item[StockSourceLinkInterface::STOCK_ID]][$item[SourceItemInterface::SKU]] =
69+
+ $item[SourceItemInterface::SKU];
70+
+ }
71+
72+
- $connection->query('SET group_concat_max_len = ' . $this->groupConcatMaxLen);
73+
- $items = $connection->fetchAll($select);
74+
return $this->getStockIdToSkuList($items);
75+
}
76+
77+
@@ -141,11 +138,11 @@ public function execute(array $sourceItemIds): array
78+
private function getStockIdToSkuList(array $items): array
79+
{
80+
$skuListInStockList = [];
81+
- foreach ($items as $item) {
82+
+ foreach ($items as $stockId => $skuList) {
83+
/** @var SkuListInStock $skuListInStock */
84+
$skuListInStock = $this->skuListInStockFactory->create();
85+
- $skuListInStock->setStockId((int)$item[StockSourceLinkInterface::STOCK_ID]);
86+
- $skuListInStock->setSkuList(explode(',', $item[SourceItemInterface::SKU]));
87+
+ $skuListInStock->setStockId((int)$stockId);
88+
+ $skuListInStock->setSkuList($skuList);
89+
$skuListInStockList[] = $skuListInStock;
90+
}
91+
return $skuListInStockList;
92+
diff -Nuar a/vendor/magento/module-inventory-configurable-product-indexer/etc/di.xml b/vendor/magento/module-inventory-configurable-product-indexer/etc/di.xml
93+
--- a/vendor/magento/module-inventory-configurable-product-indexer/etc/di.xml
94+
+++ b/vendor/magento/module-inventory-configurable-product-indexer/etc/di.xml
95+
@@ -27,7 +27,6 @@
96+
</type>
97+
<type name="Magento\InventoryConfigurableProductIndexer\Indexer\SourceItem\SiblingSkuListInStockProvider">
98+
<arguments>
99+
- <argument name="groupConcatMaxLen" xsi:type="number">2000</argument>
100+
<argument name="tableNameSourceItem" xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM</argument>
101+
<argument name="tableNameStockSourceLink" xsi:type="const">Magento\Inventory\Model\ResourceModel\StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK</argument>
102+
</arguments>

0 commit comments

Comments
 (0)