Fix AdaptAddStockDataToCollectionPlugin
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
Currently we have a plugin \Magento\InventoryCatalog\Plugin\CatalogInventory\Model\ResourceModel\Stock\Status\AdaptAddStockDataToCollectionPlugin
which pluginizes
```
```
Magento\CatalogInventory\Model\ResourceModel\Stock\Status - which is not marked as `@api`
Method which we pluginize
```
/**
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param bool $isFilterInStock
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
*/
public function addStockDataToCollection($collection, $isFilterInStock)
```
accpets product collection - \Magento\Catalog\Model\ResourceModel\Product\Collection
but in our implementation we anyway make MySQL join on `catalog_product_entity`
```
$collection->getSelect()->joinInner(
['product' => $resource->getTable('catalog_product_entity')],
sprintf('product.entity_id = %s.entity_id', Collection::MAIN_TABLE_ALIAS),
[]
);
```
so we build such query:
```
SELECT
`e`.*, `stock_status_index`.`is_salable`
FROM
`catalog_product_entity` AS `e`
INNER JOIN
`catalog_product_entity` AS `product` ON product.entity_id = e.entity_id
INNER JOIN
`inventory_stock_1` AS `stock_status_index`
ON product.sku = stock_status_index.sku
WHERE
(stock_status_index.is_salable = 1)
```
which looks very awkward
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Magento\InventoryCatalog\Plugin\CatalogInventory\Model\ResourceModel\Stock\Status\AdaptAddStockDataToCollectionPlugin and its Magento\CatalogInventory\Model\ResourceModel\Stock\Status plugin declaration. Inspect how addStockDataToCollection builds the product collection and compare it with the shown SQL query. Done means the stock join no longer creates the redundant catalog_product_entity join while preserving stock filtering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- backend, databases
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100