7
7
8
8
namespace Magento \Bundle \Model \Plugin ;
9
9
10
+ use Magento \Bundle \Model \Link ;
10
11
use Magento \Bundle \Model \Product \Price ;
11
12
use Magento \Catalog \Api \Data \ProductInterface ;
12
- use Magento \Catalog \Api \ProductRepositoryInterface ;
13
13
use Magento \Catalog \Model \Product \Type ;
14
14
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \IndexTableStructure ;
15
15
use Magento \CatalogInventory \Api \StockConfigurationInterface ;
@@ -38,11 +38,6 @@ class ProductPriceIndexModifier
38
38
*/
39
39
private MetadataPool $ metadataPool ;
40
40
41
- /**
42
- * @var ProductRepositoryInterface
43
- */
44
- private ProductRepositoryInterface $ productRepository ;
45
-
46
41
/**
47
42
* @var string
48
43
*/
@@ -52,22 +47,18 @@ class ProductPriceIndexModifier
52
47
* @param StockConfigurationInterface $stockConfiguration
53
48
* @param ResourceConnection $resourceConnection
54
49
* @param MetadataPool $metadataPool
55
- * @param ProductRepositoryInterface|null $productRepository
56
50
* @param string $connectionName
57
51
*/
58
52
public function __construct (
59
53
StockConfigurationInterface $ stockConfiguration ,
60
54
ResourceConnection $ resourceConnection ,
61
55
MetadataPool $ metadataPool ,
62
- ?ProductRepositoryInterface $ productRepository = null ,
63
56
string $ connectionName = 'indexer '
64
57
) {
65
58
$ this ->stockConfiguration = $ stockConfiguration ;
66
59
$ this ->resourceConnection = $ resourceConnection ;
67
60
$ this ->metadataPool = $ metadataPool ;
68
61
$ this ->connectionName = $ connectionName ;
69
- $ this ->productRepository = $ productRepository ?: \Magento \Framework \App \ObjectManager::getInstance ()
70
- ->get (ProductRepositoryInterface::class);
71
62
}
72
63
73
64
/**
@@ -110,28 +101,45 @@ private function filterProductsFromDynamicPriceBundle(string $priceTableName, ar
110
101
$ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
111
102
$ connection = $ this ->resourceConnection ->getConnection ($ this ->connectionName );
112
103
$ 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
+ );
115
111
$ select ->joinInner (
116
112
['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
118
115
);
119
116
$ select ->joinInner (
120
117
['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
122
130
);
123
131
$ select ->where ('selection.product_id IN (?) ' , $ productIds );
124
132
$ select ->where ('product.type_id = ? ' , Type::TYPE_BUNDLE );
133
+ $ select ->group ('selection.product_id ' );
125
134
$ bundleProducts = $ connection ->fetchAll ($ select );
126
135
127
136
if (empty ($ bundleProducts )) {
128
- return [] ;
137
+ return $ productIds ;
129
138
}
130
139
131
140
$ 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 ) {
135
143
$ filteredProducts [] = $ bundle ['child_product_id ' ];
136
144
}
137
145
}
0 commit comments