99
1010use Exception ;
1111use Magento \Catalog \Api \Data \ProductInterface ;
12- use Magento \Framework \App \Config \ScopeConfigInterface ;
1312use Magento \Framework \App \ResourceConnection ;
1413use Magento \Framework \DB \Select ;
1514use Magento \Framework \EntityManager \MetadataPool ;
@@ -44,30 +43,22 @@ class SelectBuilder
4443 */
4544 private $ metadataPool ;
4645
47- /**
48- * @var ScopeConfigInterface
49- */
50- private $ config ;
51-
5246 /**
5347 * @param ResourceConnection $resourceConnection
5448 * @param IndexNameBuilder $indexNameBuilder
5549 * @param IndexNameResolverInterface $indexNameResolver
5650 * @param MetadataPool $metadataPool
57- * @param ScopeConfigInterface $config
5851 */
5952 public function __construct (
6053 ResourceConnection $ resourceConnection ,
6154 IndexNameBuilder $ indexNameBuilder ,
6255 IndexNameResolverInterface $ indexNameResolver ,
63- MetadataPool $ metadataPool ,
64- ScopeConfigInterface $ config
56+ MetadataPool $ metadataPool
6557 ) {
6658 $ this ->resourceConnection = $ resourceConnection ;
6759 $ this ->indexNameBuilder = $ indexNameBuilder ;
6860 $ this ->indexNameResolver = $ indexNameResolver ;
6961 $ this ->metadataPool = $ metadataPool ;
70- $ this ->config = $ config ;
7162 }
7263
7364 /**
@@ -91,19 +82,14 @@ public function execute(int $stockId): Select
9182
9283 $ metadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
9384 $ linkField = $ metadata ->getLinkField ();
94- $ manageStock = (int )$ this ->config ->getValue ('cataloginventory/item_options/manage_stock ' );
95- $ isSalableExpr = $ manageStock
96- ? 'IF(MAX(parent_stock.manage_stock = 0), MAX(stock.is_salable), IF(MAX(parent_stock.is_in_stock) = 1, '
97- . 'MAX(stock.is_salable), 0)) '
98- : 'IF(MAX(parent_stock.use_config_manage_stock) = 0, IF(MAX(parent_stock.manage_stock) = 1 AND '
99- . 'MAX(parent_stock.is_in_stock = 0), 0, MAX(stock.is_salable)), MAX(stock.is_salable)) ' ;
85+
10086 $ select = $ connection ->select ()
10187 ->from (
10288 ['stock ' => $ indexTableName ],
10389 [
10490 IndexStructure::SKU => 'parent_product_entity.sku ' ,
10591 IndexStructure::QUANTITY => 'SUM(stock.quantity) ' ,
106- IndexStructure::IS_SALABLE => $ isSalableExpr ,
92+ IndexStructure::IS_SALABLE => ' MAX(stock.is_salable) ' ,
10793 ]
10894 )->joinInner (
10995 ['product_entity ' => $ this ->resourceConnection ->getTableName ('catalog_product_entity ' )],
@@ -117,10 +103,6 @@ public function execute(int $stockId): Select
117103 ['parent_product_entity ' => $ this ->resourceConnection ->getTableName ('catalog_product_entity ' )],
118104 'parent_product_entity. ' . $ linkField . ' = parent_link.parent_product_id ' ,
119105 []
120- )->joinInner (
121- ['parent_stock ' => $ this ->resourceConnection ->getTableName ('cataloginventory_stock_item ' )],
122- 'parent_product_entity.entity_id = parent_stock.product_id ' ,
123- []
124106 )
125107 ->group (['parent_product_entity.sku ' ]);
126108
0 commit comments