@@ -121,12 +121,35 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds =
121
121
foreach ($ batchSelectIterator as $ select ) {
122
122
$ productIds = null ;
123
123
foreach ($ connection ->query ($ select )->fetchAll () as $ row ) {
124
- $ productIds [] = (int ) $ row ['product_id ' ];
124
+ if ($ row ['product_id ' ] && $ this ->isWithinDynamicPriceBundle ($ priceTable ->getTableName (), (int ) $ row ['product_id ' ])) {
125
+ $ productIds [] = (int ) $ row ['product_id ' ];
126
+ }
125
127
}
126
128
if ($ productIds !== null ) {
127
129
$ where = [$ priceTable ->getEntityField () .' IN (?) ' => $ productIds ];
128
130
$ connection ->delete ($ priceTable ->getTableName (), $ where );
129
131
}
130
132
}
131
133
}
134
+
135
+ /**
136
+ * Check if the product is used within a dynamic price bundle configuration
137
+ *
138
+ * @param string $priceTableName
139
+ * @param int $productId
140
+ * @return bool
141
+ */
142
+ private function isWithinDynamicPriceBundle (string $ priceTableName , int $ productId ): bool
143
+ {
144
+ $ connection = $ this ->resourceConnection ->getConnection ($ this ->connectionName );
145
+ $ select = $ connection ->select ();
146
+ $ select ->from (['selection ' => 'catalog_product_bundle_selection ' ], 'selection_id ' );
147
+ $ select ->joinInner (['entity ' => 'catalog_product_entity ' ], implode (' AND ' , ['selection.parent_product_id = entity.entity_id ' ]), null );
148
+ $ select ->joinInner (['price ' => $ priceTableName ], implode (' AND ' , ['price.entity_id = selection.product_id ' ]), null );
149
+ $ select ->where ('selection.product_id = ? ' , $ productId );
150
+ $ select ->where ('entity.type_id = ? ' , \Magento \Catalog \Model \Product \Type::TYPE_BUNDLE );
151
+ $ select ->where ('price.tax_class_id = ? ' , \Magento \Bundle \Model \Product \Price::PRICE_TYPE_DYNAMIC );
152
+
153
+ return intval ($ connection ->fetchOne ($ select )) != 0 ;
154
+ }
132
155
}
0 commit comments