8
8
namespace Magento \GroupedProduct \Model \ResourceModel \Product \Indexer \Price ;
9
9
10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
- use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \BasePriceModifier ;
12
- use Magento \Eav \Model \Config ;
13
11
use Magento \Framework \App \ResourceConnection ;
14
12
use Magento \Framework \DB \Adapter \AdapterInterface ;
15
13
use Magento \Framework \Indexer \DimensionalIndexerInterface ;
16
14
use Magento \Framework \EntityManager \MetadataPool ;
17
15
use Magento \Catalog \Model \Indexer \Product \Price \TableMaintainer ;
18
- use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \Query \BaseFinalPrice ;
19
16
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \IndexTableStructureFactory ;
20
17
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \IndexTableStructure ;
21
18
use Magento \Catalog \Model \ResourceModel \Product \Indexer \Price \PriceModifierInterface ;
22
- use Magento \GroupedProduct \Model \Product \Type \Grouped as GroupedType ;
23
19
use Magento \GroupedProduct \Model \ResourceModel \Product \Link ;
24
20
use Magento \Store \Model \Indexer \WebsiteDimensionProvider ;
25
21
use Magento \Customer \Model \Indexer \CustomerGroupDimensionProvider ;
@@ -61,63 +57,33 @@ class Grouped implements DimensionalIndexerInterface
61
57
*/
62
58
private $ connection ;
63
59
64
- /**
65
- * @var PriceModifierInterface[]
66
- */
67
- private $ priceModifiers ;
68
-
69
60
/**
70
61
* @var bool
71
62
*/
72
63
private $ fullReindexAction ;
73
- /**
74
- * @var BasePriceModifier
75
- */
76
- private $ basePriceModifier ;
77
64
78
65
/**
79
66
* @param IndexTableStructureFactory $indexTableStructureFactory
80
67
* @param TableMaintainer $tableMaintainer
81
68
* @param MetadataPool $metadataPool
82
69
* @param ResourceConnection $resource
83
- * @param BasePriceModifier $basePriceModifier
84
70
* @param string $connectionName
85
71
* @param bool $fullReindexAction
86
- * @param array $priceModifiers
87
72
*/
88
73
public function __construct (
89
74
IndexTableStructureFactory $ indexTableStructureFactory ,
90
75
TableMaintainer $ tableMaintainer ,
91
76
MetadataPool $ metadataPool ,
92
77
ResourceConnection $ resource ,
93
- BasePriceModifier $ basePriceModifier ,
94
78
$ connectionName = 'indexer ' ,
95
- $ fullReindexAction = false ,
96
- array $ priceModifiers = []
79
+ $ fullReindexAction = false
97
80
) {
98
81
$ this ->indexTableStructureFactory = $ indexTableStructureFactory ;
99
82
$ this ->tableMaintainer = $ tableMaintainer ;
100
83
$ this ->connectionName = $ connectionName ;
101
- $ this ->priceModifiers = $ priceModifiers ;
102
84
$ this ->metadataPool = $ metadataPool ;
103
85
$ this ->resource = $ resource ;
104
86
$ this ->fullReindexAction = $ fullReindexAction ;
105
- $ this ->connection = $ this ->resource ->getConnection ($ this ->connectionName );
106
- $ this ->basePriceModifier = $ basePriceModifier ;
107
- }
108
-
109
- /**
110
- * Get main table
111
- *
112
- * @param array $dimensions
113
- * @return string
114
- */
115
- private function getMainTable ($ dimensions )
116
- {
117
- if ($ this ->fullReindexAction ) {
118
- return $ this ->tableMaintainer ->getMainReplicaTable ($ dimensions );
119
- }
120
- return $ this ->tableMaintainer ->getMainTable ($ dimensions );
121
87
}
122
88
123
89
/**
@@ -140,52 +106,32 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
140
106
'maxPriceField ' => 'max_price ' ,
141
107
'tierPriceField ' => 'tier_price ' ,
142
108
]);
143
- $ this ->basePriceModifier ->modifyPrice ($ temporaryPriceTable , iterator_to_array ($ entityIds ));
144
109
$ query = $ this ->_prepareGroupedProductPriceDataSelect ($ dimensions , iterator_to_array ($ entityIds ))
145
110
->insertFromSelect ($ temporaryPriceTable ->getTableName ());
146
- $ this ->connection ->query ($ query );
111
+ $ this ->getConnection () ->query ($ query );
147
112
}
148
113
149
114
/**
150
115
* Prepare data index select for Grouped products prices
151
116
* @param $dimensions
152
- * @param int| array $entityIds the parent entity ids limitation
117
+ * @param array $entityIds the parent entity ids limitation
153
118
* @return \Magento\Framework\DB\Select
154
119
*/
155
120
protected function _prepareGroupedProductPriceDataSelect ($ dimensions , $ entityIds = null )
156
121
{
157
- $ select = $ this ->connection ->select ();
158
-
159
- $ select ->from (
160
- ['e ' => $ this ->getTable ('catalog_product_entity ' )],
161
- 'entity_id '
162
- );
122
+ $ connection = $ this ->getConnection ();
163
123
124
+ $ taxClassId = $ connection ->getCheckSql ('MIN(i.tax_class_id) IS NULL ' , '0 ' , 'MIN(i.tax_class_id) ' );
125
+ $ minCheckSql = $ connection ->getCheckSql ('e.required_options = 0 ' , 'i.min_price ' , 0 );
126
+ $ maxCheckSql = $ connection ->getCheckSql ('e.required_options = 0 ' , 'i.max_price ' , 0 );
164
127
$ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
165
- $ select ->joinLeft (
166
- ['l ' => $ this ->getTable ('catalog_product_link ' )],
167
- 'e. ' . $ linkField . ' = l.product_id AND l.link_type_id= ' . Link::LINK_TYPE_GROUPED ,
168
- []
169
- );
170
- //aditional infromation about inner products
171
- $ select ->joinLeft (
172
- ['le ' => $ this ->getTable ('catalog_product_entity ' )],
173
- 'le.entity_id = l.linked_product_id ' ,
174
- []
175
- );
128
+
129
+ $ select = $ connection ->select ()->from (['l ' => $ this ->getTable ('catalog_product_link ' )], []);
176
130
$ select ->columns (
177
131
[
178
- 'i.customer_group_id ' ,
179
- 'i.website_id ' ,
180
- ]
181
- );
182
- $ taxClassId = $ this ->connection ->getCheckSql ('MIN(i.tax_class_id) IS NULL ' , '0 ' , 'MIN(i.tax_class_id) ' );
183
- $ minCheckSql = $ this ->connection ->getCheckSql ('le.required_options = 0 ' , 'i.min_price ' , 0 );
184
- $ maxCheckSql = $ this ->connection ->getCheckSql ('le.required_options = 0 ' , 'i.max_price ' , 0 );
185
- $ select ->joinLeft (
186
- ['i ' => $ this ->getMainTable ($ dimensions )],
187
- 'i.entity_id = l.linked_product_id ' ,
188
- [
132
+ 'entity_id ' => new \Zend_Db_Expr ('l.product_id ' ),
133
+ 'customer_group_id ' => new \Zend_Db_Expr ('i.customer_group_id ' ),
134
+ 'website_id ' => new \Zend_Db_Expr ('i.website_id ' ),
189
135
'tax_class_id ' => $ taxClassId ,
190
136
'price ' => new \Zend_Db_Expr ('NULL ' ),
191
137
'final_price ' => new \Zend_Db_Expr ('NULL ' ),
@@ -194,24 +140,21 @@ protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds
194
140
'tier_price ' => new \Zend_Db_Expr ('NULL ' ),
195
141
]
196
142
);
197
- $ select ->group (
198
- ['e.entity_id ' , 'i.customer_group_id ' , 'i.website_id ' ]
199
- );
200
- $ select ->where (
201
- 'e.type_id=? ' ,
202
- GroupedType::TYPE_CODE
203
- );
143
+ $ select ->join (['i ' => $ this ->getMainTable ($ dimensions )], 'i.entity_id = l.linked_product_id ' , []);
144
+ $ select ->join (['e ' => $ this ->getTable ('catalog_product_entity ' )], "e. $ linkField = l.linked_product_id " , []);
145
+ $ select ->where ('l.link_type_id = ? ' , Link::LINK_TYPE_GROUPED );
146
+ $ select ->group (['l.product_id ' , 'i.customer_group_id ' , 'i.website_id ' ]);
204
147
205
148
if ($ entityIds !== null ) {
206
- $ select ->where ('e.entity_id IN(?) ' , $ entityIds );
149
+ $ select ->where ('l.product_id IN(?) ' , $ entityIds );
207
150
}
208
151
209
152
foreach ($ dimensions as $ dimension ) {
210
153
if ($ dimension ->getName () === WebsiteDimensionProvider::DIMENSION_NAME ) {
211
- $ select ->where ('`i` .website_id = ? ' , $ dimension ->getValue ());
154
+ $ select ->where ('i .website_id = ? ' , $ dimension ->getValue ());
212
155
}
213
156
if ($ dimension ->getName () === CustomerGroupDimensionProvider::DIMENSION_NAME ) {
214
- $ select ->where ('`i` .customer_group_id = ? ' , $ dimension ->getValue ());
157
+ $ select ->where ('i .customer_group_id = ? ' , $ dimension ->getValue ());
215
158
}
216
159
}
217
160
@@ -222,4 +165,33 @@ private function getTable($tableName)
222
165
{
223
166
return $ this ->resource ->getTableName ($ tableName , $ this ->connectionName );
224
167
}
168
+
169
+ /**
170
+ * Get connection
171
+ *
172
+ * return \Magento\Framework\DB\Adapter\AdapterInterface
173
+ * @throws \DomainException
174
+ */
175
+ private function getConnection (): \Magento \Framework \DB \Adapter \AdapterInterface
176
+ {
177
+ if ($ this ->connection === null ) {
178
+ $ this ->connection = $ this ->resource ->getConnection ($ this ->connectionName );
179
+ }
180
+
181
+ return $ this ->connection ;
182
+ }
183
+
184
+ /**
185
+ * Get main table
186
+ *
187
+ * @param array $dimensions
188
+ * @return string
189
+ */
190
+ private function getMainTable ($ dimensions )
191
+ {
192
+ if ($ this ->fullReindexAction ) {
193
+ return $ this ->tableMaintainer ->getMainReplicaTable ($ dimensions );
194
+ }
195
+ return $ this ->tableMaintainer ->getMainTable ($ dimensions );
196
+ }
225
197
}
0 commit comments