77
88namespace Magento \Bundle \Model \ResourceModel \Indexer ;
99
10+ use Magento \Bundle \Model \Product \Type ;
1011use Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher ;
1112use Magento \CatalogInventory \Model \Indexer \Stock \Action \Full ;
1213use Magento \CatalogInventory \Model \ResourceModel \Indexer \Stock \DefaultStock ;
@@ -45,6 +46,7 @@ class Stock extends DefaultStock
4546 * @param ActiveTableSwitcher $activeTableSwitcher
4647 * @param StockStatusSelectBuilder $stockStatusSelectBuilder
4748 * @param BundleOptionStockDataSelectBuilder $bundleOptionStockDataSelectBuilder
49+ * @param OptionQtyExpressionProvider $optionQtyExpressionProvider
4850 * @param string $connectionName
4951 */
5052 public function __construct (
@@ -55,10 +57,14 @@ public function __construct(
5557 ActiveTableSwitcher $ activeTableSwitcher ,
5658 StockStatusSelectBuilder $ stockStatusSelectBuilder ,
5759 BundleOptionStockDataSelectBuilder $ bundleOptionStockDataSelectBuilder ,
60+ private readonly OptionQtyExpressionProvider $ optionQtyExpressionProvider ,
5861 $ connectionName = null
5962 ) {
6063 parent ::__construct ($ context , $ tableStrategy , $ eavConfig , $ scopeConfig , $ connectionName );
6164
65+ $ this ->_typeId = Type::TYPE_CODE ;
66+ $ this ->_isComposite = true ;
67+
6268 $ this ->activeTableSwitcher = $ activeTableSwitcher ;
6369 $ this ->stockStatusSelectBuilder = $ stockStatusSelectBuilder ;
6470 $ this ->bundleOptionStockDataSelectBuilder = $ bundleOptionStockDataSelectBuilder ;
@@ -198,11 +204,14 @@ protected function _cleanBundleOptionStockData()
198204 private function getOptionsStatusExpression (): \Zend_Db_Expr
199205 {
200206 $ connection = $ this ->getConnection ();
207+
208+ $ qtyExpr = $ this ->optionQtyExpressionProvider ->getExpression ();
201209 $ isAvailableExpr = $ connection ->getCheckSql (
202- 'bs.selection_can_change_qty = 0 AND bs.selection_qty > i.qty ' ,
210+ 'bs.selection_can_change_qty = 0 AND bs.selection_qty > ' . $ qtyExpr ,
203211 '0 ' ,
204212 'i.stock_status '
205213 );
214+
206215 if ($ this ->stockConfiguration ->getBackorders ()) {
207216 $ backordersExpr = $ connection ->getCheckSql (
208217 'cisi.use_config_backorders = 0 AND cisi.backorders = 0 ' ,
@@ -216,6 +225,7 @@ private function getOptionsStatusExpression(): \Zend_Db_Expr
216225 $ isAvailableExpr
217226 );
218227 }
228+
219229 if ($ this ->stockConfiguration ->getManageStock ()) {
220230 $ statusExpr = $ connection ->getCheckSql (
221231 'cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0 ' ,
0 commit comments