@@ -110,62 +110,14 @@ public function getQuery(array $dimensions, string $productType, array $entityId
110
110
111
111
$ select = $ connection ->select ()->from (
112
112
['e ' => $ this ->getTable ('catalog_product_entity ' )],
113
- ['entity_id ' ]
114
- )->joinInner (
115
- ['cg ' => $ this ->getTable ('customer_group ' )],
116
- array_key_exists (CustomerGroupDimensionProvider::DIMENSION_NAME , $ dimensions )
117
- ? sprintf (
118
- '%s = %s ' ,
119
- $ this ->dimensionToFieldMapper [CustomerGroupDimensionProvider::DIMENSION_NAME ],
120
- $ dimensions [CustomerGroupDimensionProvider::DIMENSION_NAME ]->getValue ()
121
- ) : '' ,
122
- ['customer_group_id ' ]
123
- )->joinInner (
124
- ['pw ' => $ this ->getTable ('catalog_product_website ' )],
125
- 'pw.product_id = e.entity_id ' ,
126
- ['pw.website_id ' ]
127
- )->joinInner (
128
- ['cwd ' => $ this ->getTable ('catalog_product_index_website ' )],
129
- 'pw.website_id = cwd.website_id ' ,
130
113
[]
131
114
)->joinLeft (
132
- // customer group website limitations
133
- ['cgw ' => $ this ->getTable ('customer_group_excluded_website ' )],
134
- 'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id ' ,
135
- []
136
- )->joinLeft (
137
- // we need this only for BCC in case someone expects table `tp` to be present in query
138
- ['tp ' => $ this ->getTable ('catalog_product_index_tier_price ' )],
139
- 'tp.entity_id = e.entity_id AND ' .
140
- ' tp.customer_group_id = cg.customer_group_id AND tp.website_id = pw.website_id ' ,
141
- []
142
- )->joinLeft (
143
- // calculate tier price specified as Website = `All Websites` and Customer Group = `Specific Customer Group`
144
- ['tier_price_1 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
145
- 'tier_price_1. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_1.all_groups = 0 ' .
146
- ' AND tier_price_1.customer_group_id = cg.customer_group_id AND tier_price_1.qty = 1 ' .
147
- ' AND tier_price_1.website_id = 0 ' ,
148
- []
149
- )->joinLeft (
150
- // calculate tier price specified as Website = `Specific Website`
151
- //and Customer Group = `Specific Customer Group`
152
- ['tier_price_2 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
153
- 'tier_price_2. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_2.all_groups = 0 ' .
154
- 'AND tier_price_2.customer_group_id = cg.customer_group_id AND tier_price_2.qty = 1 ' .
155
- ' AND tier_price_2.website_id = pw.website_id ' ,
156
- []
157
- )->joinLeft (
158
- // calculate tier price specified as Website = `All Websites` and Customer Group = `ALL GROUPS`
159
- ['tier_price_3 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
160
- 'tier_price_3. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_3.all_groups = 1 ' .
161
- 'AND tier_price_3.customer_group_id = 0 AND tier_price_3.qty = 1 AND tier_price_3.website_id = 0 ' ,
115
+ ['pw ' => $ this ->getTable ('catalog_product_website ' )],
116
+ 'pw.product_id = e.entity_id ' ,
162
117
[]
163
118
)->joinLeft (
164
- // calculate tier price specified as Website = `Specific Website` and Customer Group = `ALL GROUPS`
165
- ['tier_price_4 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
166
- 'tier_price_4. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_4.all_groups = 1 ' .
167
- ' AND tier_price_4.customer_group_id = 0 AND tier_price_4.qty = 1 ' .
168
- ' AND tier_price_4.website_id = pw.website_id ' ,
119
+ ['cwd ' => $ this ->getTable ('catalog_product_index_website ' )],
120
+ 'pw.website_id = cwd.website_id ' ,
169
121
[]
170
122
);
171
123
@@ -183,7 +135,6 @@ public function getQuery(array $dimensions, string $productType, array $entityId
183
135
} else {
184
136
$ taxClassId = new \Zend_Db_Expr (0 );
185
137
}
186
- $ select ->columns (['tax_class_id ' => $ taxClassId ]);
187
138
188
139
$ this ->joinAttributeProcessor ->process ($ select , 'status ' , Status::STATUS_ENABLED );
189
140
@@ -213,8 +164,56 @@ public function getQuery(array $dimensions, string $productType, array $entityId
213
164
]
214
165
);
215
166
167
+ $ select ->join (
168
+ ['cg ' => $ this ->getTable ('customer_group ' )],
169
+ array_key_exists (CustomerGroupDimensionProvider::DIMENSION_NAME , $ dimensions )
170
+ ? sprintf (
171
+ '%s = %s ' ,
172
+ $ this ->dimensionToFieldMapper [CustomerGroupDimensionProvider::DIMENSION_NAME ],
173
+ $ dimensions [CustomerGroupDimensionProvider::DIMENSION_NAME ]->getValue ()
174
+ ) : '' ,
175
+ []
176
+ )->joinLeft (
177
+ // customer group website limitations
178
+ ['cgw ' => $ this ->getTable ('customer_group_excluded_website ' )],
179
+ 'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id ' ,
180
+ []
181
+ )->joinLeft (
182
+ // calculate tier price specified as Website = `All Websites` and Customer Group = `Specific Customer Group`
183
+ ['tier_price_1 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
184
+ 'tier_price_1. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_1.all_groups = 0 ' .
185
+ ' AND tier_price_1.customer_group_id = cg.customer_group_id AND tier_price_1.qty = 1 ' .
186
+ ' AND tier_price_1.website_id = 0 ' ,
187
+ []
188
+ )->joinLeft (
189
+ // calculate tier price specified as Website = `All Websites` and Customer Group = `ALL GROUPS`
190
+ ['tier_price_3 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
191
+ 'tier_price_3. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_3.all_groups = 1 ' .
192
+ 'AND tier_price_3.customer_group_id = 0 AND tier_price_3.qty = 1 AND tier_price_3.website_id = 0 ' ,
193
+ []
194
+ )->joinLeft (
195
+ // calculate tier price specified as Website = `Specific Website` and Customer Group = `ALL GROUPS`
196
+ ['tier_price_4 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
197
+ 'tier_price_4. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_4.all_groups = 1 ' .
198
+ ' AND tier_price_4.customer_group_id = 0 AND tier_price_4.qty = 1 ' .
199
+ ' AND tier_price_4.website_id = pw.website_id ' ,
200
+ []
201
+ )->joinLeft (
202
+ // calculate tier price specified as Website = `Specific Website`
203
+ //and Customer Group = `Specific Customer Group`
204
+ ['tier_price_2 ' => $ this ->getTable ('catalog_product_entity_tier_price ' )],
205
+ 'tier_price_2. ' . $ linkField . ' = e. ' . $ linkField . ' AND tier_price_2.all_groups = 0 ' .
206
+ 'AND tier_price_2.customer_group_id = cg.customer_group_id AND tier_price_2.qty = 1 ' .
207
+ ' AND tier_price_2.website_id = pw.website_id ' ,
208
+ []
209
+ );
210
+ // the order of fields is important!
216
211
$ select ->columns (
217
212
[
213
+ 'entity_id ' ,
214
+ 'cg.customer_group_id ' ,
215
+ 'pw.website_id ' ,
216
+ 'tax_class_id ' => $ taxClassId ,
218
217
//orig_price in catalog_product_index_price_final_tmp
219
218
'price ' => $ connection ->getIfNullSql ($ price , 0 ),
220
219
//price in catalog_product_index_price_final_tmp
@@ -227,14 +226,14 @@ public function getQuery(array $dimensions, string $productType, array $entityId
227
226
228
227
$ select ->where ("e.type_id = ? " , $ productType );
229
228
229
+ // exclude websites that are limited for customer group
230
+ $ select ->where ('cgw.website_id IS NULL ' );
231
+
230
232
if ($ entityIds !== null ) {
231
233
$ select ->where (sprintf ('e.entity_id BETWEEN %s AND %s ' , min ($ entityIds ), max ($ entityIds )));
232
- $ select ->where ('e.entity_id IN(?) ' , $ entityIds );
234
+ $ select ->where ('e.entity_id IN(?) ' , $ entityIds, \Zend_Db:: INT_TYPE );
233
235
}
234
236
235
- // exclude websites that are limited for customer group
236
- $ select ->where ('cgw.website_id IS NULL ' );
237
-
238
237
/**
239
238
* throw event for backward compatibility
240
239
*/
0 commit comments