Skip to content

Commit

Permalink
Merge pull request magento#1170 from magento-engcom/configurableindex…
Browse files Browse the repository at this point in the history
…er-dependency-refactor

Removed Inventory dependency for InventoryConfigurableProductIndexer
  • Loading branch information
maghamed authored May 18, 2018
2 parents f9f56b3 + b184b75 commit 967a87d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

use Exception;
use Magento\Framework\App\ResourceConnection;
use Magento\Inventory\Model\ResourceModel\SourceItem as SourceItemResourceModel;
use Magento\Inventory\Model\ResourceModel\StockSourceLink as StockSourceLinkResourceModel;
use Magento\Inventory\Model\StockSourceLink;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\Data\StockSourceLinkInterface;
use Magento\InventoryIndexer\Indexer\SourceItem\SkuListInStock;
use Magento\InventoryIndexer\Indexer\SourceItem\SkuListInStockFactory;
use Magento\Framework\EntityManager\MetadataPool;
Expand Down Expand Up @@ -42,24 +40,40 @@ class SiblingSkuListInStockProvider
*/
private $metadataPool;

/**
* @var string
*/
private $tableNameSourceItem;

/**
* @var string
*/
private $tableNameStockSourceLink;

/**
* GetSkuListInStock constructor.
*
* @param ResourceConnection $resourceConnection
* @param SkuListInStockFactory $skuListInStockFactory
* @param MetadataPool $metadataPool
* @param int $groupConcatMaxLen
* @param string $tableNameSourceItem
* @param string $tableNameStockSourceLink
*/
public function __construct(
ResourceConnection $resourceConnection,
SkuListInStockFactory $skuListInStockFactory,
MetadataPool $metadataPool,
int $groupConcatMaxLen
int $groupConcatMaxLen,
$tableNameSourceItem,
$tableNameStockSourceLink
) {
$this->resourceConnection = $resourceConnection;
$this->skuListInStockFactory = $skuListInStockFactory;
$this->groupConcatMaxLen = $groupConcatMaxLen;
$this->metadataPool = $metadataPool;
$this->tableNameSourceItem = $tableNameSourceItem;
$this->tableNameStockSourceLink = $tableNameStockSourceLink;
}

/**
Expand All @@ -72,12 +86,8 @@ public function __construct(
public function execute(array $sourceItemIds): array
{
$connection = $this->resourceConnection->getConnection();
$sourceStockLinkTable = $this->resourceConnection->getTableName(
StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK
);
$sourceItemTable = $this->resourceConnection->getTableName(
SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM
);
$sourceStockLinkTable = $this->resourceConnection->getTableName($this->tableNameStockSourceLink);
$sourceItemTable = $this->resourceConnection->getTableName($this->tableNameSourceItem);

$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
$linkField = $metadata->getLinkField();
Expand All @@ -95,9 +105,9 @@ public function execute(array $sourceItemIds): array
sprintf(
'source_item.%s = stock_source_link.%s',
SourceItemInterface::SOURCE_CODE,
StockSourceLink::SOURCE_CODE
StockSourceLinkInterface::SOURCE_CODE
),
[StockSourceLink::STOCK_ID]
[StockSourceLinkInterface::STOCK_ID]
)->joinInner(
['child_product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')],
'child_product_entity.sku = source_item.sku',
Expand All @@ -115,7 +125,7 @@ public function execute(array $sourceItemIds): array
'sibling_product_entity.' . $linkField . ' = sibling_link.product_id',
[]
)->where('source_item.source_item_id IN (?)', $sourceItemIds)
->group(['stock_source_link.' . StockSourceLink::STOCK_ID]);
->group(['stock_source_link.' . StockSourceLinkInterface::STOCK_ID]);

$connection->query('SET group_concat_max_len = ' . $this->groupConcatMaxLen);
$items = $connection->fetchAll($select);
Expand All @@ -134,7 +144,7 @@ private function getStockIdToSkuList(array $items): array
foreach ($items as $item) {
/** @var SkuListInStock $skuListInStock */
$skuListInStock = $this->skuListInStockFactory->create();
$skuListInStock->setStockId((int)$item[StockSourceLink::STOCK_ID]);
$skuListInStock->setStockId((int)$item[StockSourceLinkInterface::STOCK_ID]);
$skuListInStock->setSkuList(explode(',', $item[SourceItemInterface::SKU]));
$skuListInStockList[] = $skuListInStock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"php": "~7.1.3||~7.2.0",
"magento/framework": "*",
"magento/module-catalog": "*",
"magento/module-inventory": "*",
"magento/module-inventory-api": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-inventory-indexer": "*",
"magento/module-inventory-multi-dimensional-indexer-api": "*"
},
"suggest": {
"magento/module-inventory": "*"
},
"type": "magento2-module",
"license": [
"OSL-3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<type name="Magento\InventoryConfigurableProductIndexer\Indexer\SourceItem\SiblingSkuListInStockProvider">
<arguments>
<argument name="groupConcatMaxLen" xsi:type="number">2000</argument>
<argument name="tableNameSourceItem" xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM</argument>
<argument name="tableNameStockSourceLink" xsi:type="const">Magento\Inventory\Model\ResourceModel\StockSourceLink::TABLE_NAME_STOCK_SOURCE_LINK</argument>
</arguments>
</type>
</config>

0 comments on commit 967a87d

Please sign in to comment.