77
88namespace Magento \Bundle \Model \Plugin ;
99
10+ use Magento \Bundle \Model \Link ;
1011use Magento \Bundle \Model \Product \Price ;
1112use Magento \Catalog \Api \Data \ProductInterface ;
12- use Magento \Catalog \Api \ProductRepositoryInterface ;
1313use Magento \Catalog \Model \Product \Type ;
1414use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \IndexTableStructure ;
1515use Magento \CatalogInventory \Api \StockConfigurationInterface ;
@@ -38,11 +38,6 @@ class ProductPriceIndexModifier
3838 */
3939 private MetadataPool $ metadataPool ;
4040
41- /**
42- * @var ProductRepositoryInterface
43- */
44- private ProductRepositoryInterface $ productRepository ;
45-
4641 /**
4742 * @var string
4843 */
@@ -52,22 +47,18 @@ class ProductPriceIndexModifier
5247 * @param StockConfigurationInterface $stockConfiguration
5348 * @param ResourceConnection $resourceConnection
5449 * @param MetadataPool $metadataPool
55- * @param ProductRepositoryInterface|null $productRepository
5650 * @param string $connectionName
5751 */
5852 public function __construct (
5953 StockConfigurationInterface $ stockConfiguration ,
6054 ResourceConnection $ resourceConnection ,
6155 MetadataPool $ metadataPool ,
62- ?ProductRepositoryInterface $ productRepository = null ,
6356 string $ connectionName = 'indexer '
6457 ) {
6558 $ this ->stockConfiguration = $ stockConfiguration ;
6659 $ this ->resourceConnection = $ resourceConnection ;
6760 $ this ->metadataPool = $ metadataPool ;
6861 $ this ->connectionName = $ connectionName ;
69- $ this ->productRepository = $ productRepository ?: \Magento \Framework \App \ObjectManager::getInstance ()
70- ->get (ProductRepositoryInterface::class);
7162 }
7263
7364 /**
@@ -110,28 +101,45 @@ private function filterProductsFromDynamicPriceBundle(string $priceTableName, ar
110101 $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
111102 $ connection = $ this ->resourceConnection ->getConnection ($ this ->connectionName );
112103 $ select = $ connection ->select ();
113- $ select ->from (['selection ' => $ this ->resourceConnection ->getTableName ('catalog_product_bundle_selection ' )]);
114- $ select ->columns (['product.entity_id AS bundle_id ' , 'selection.product_id AS child_product_id ' ]);
104+ $ select ->from (['selection ' => $ this ->resourceConnection ->getTableName ('catalog_product_bundle_selection ' )],
105+ [
106+ 'product.entity_id AS bundle_id ' ,
107+ 'selection.product_id AS child_product_id ' ,
108+ 'pei.value AS bundle_price_type '
109+ ]
110+ );
115111 $ select ->joinInner (
116112 ['price ' => $ this ->resourceConnection ->getTableName ($ priceTableName )],
117- implode (' AND ' , ['price.entity_id = selection.product_id ' ])
113+ implode (' AND ' , ['price.entity_id = selection.product_id ' ]),
114+ null
118115 );
119116 $ select ->joinInner (
120117 ['product ' => $ this ->resourceConnection ->getTableName ('catalog_product_entity ' )],
121- "product. $ linkField = selection.parent_product_id "
118+ "product. $ linkField = selection.parent_product_id " ,
119+ null
120+ );
121+ $ select ->joinInner (
122+ ['pei ' => $ this ->resourceConnection ->getTableName ('catalog_product_entity_int ' )],
123+ "product. $ linkField = pei. $ linkField " ,
124+ null
125+ );
126+ $ select ->joinInner (
127+ ['ea ' => $ this ->resourceConnection ->getTableName ('eav_attribute ' )],
128+ "pei.attribute_id = ea.attribute_id AND ea.attribute_code = ' " . Link::KEY_PRICE_TYPE . "' " ,
129+ null
122130 );
123131 $ select ->where ('selection.product_id IN (?) ' , $ productIds );
124132 $ select ->where ('product.type_id = ? ' , Type::TYPE_BUNDLE );
133+ $ select ->group ('selection.product_id ' );
125134 $ bundleProducts = $ connection ->fetchAll ($ select );
126135
127136 if (empty ($ bundleProducts )) {
128- return [] ;
137+ return $ productIds ;
129138 }
130139
131140 $ filteredProducts = [];
132- foreach ($ bundleProducts as $ bundle ) {
133- $ bundleProduct = $ this ->productRepository ->getById ($ bundle ['bundle_id ' ]);
134- if ($ bundleProduct ->getPriceType () != Price::PRICE_TYPE_DYNAMIC ) {
141+ foreach ($ bundleProducts as $ bundle ) {
142+ if ($ bundle ['bundle_price_type ' ] !== Price::PRICE_TYPE_DYNAMIC ) {
135143 $ filteredProducts [] = $ bundle ['child_product_id ' ];
136144 }
137145 }
0 commit comments