9
9
*/
10
10
namespace Magento \CatalogWidget \Model \Rule \Condition ;
11
11
12
- use Magento \Catalog \Api \Data \ProductInterface ;
13
12
use Magento \Catalog \Model \ProductCategoryList ;
14
13
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
14
+ use Magento \Framework \DB \Select ;
15
15
use Magento \Store \Model \Store ;
16
16
17
17
/**
@@ -201,7 +201,7 @@ protected function addNotGlobalAttribute(
201
201
\Magento \Catalog \Model \ResourceModel \Eav \Attribute $ attribute ,
202
202
Collection $ collection
203
203
) {
204
- $ storeId = $ this ->storeManager ->getStore ()->getId ();
204
+ /* $storeId = $this->storeManager->getStore()->getId();
205
205
$values = $collection->getAllAttributeValues($attribute);
206
206
$validEntities = [];
207
207
if ($values) {
@@ -227,6 +227,56 @@ protected function addNotGlobalAttribute(
227
227
$this->unsetData('value');
228
228
}
229
229
230
+ return $this;*/
231
+
232
+ $ connection = $ this ->_productResource ->getConnection ();
233
+ switch ($ attribute ->getBackendType ()) {
234
+ case 'decimal ' :
235
+ case 'datetime ' :
236
+ case 'int ' :
237
+ case 'varchar ' :
238
+ case 'text ' :
239
+ $ aliasDefault = 'at_ ' . $ attribute ->getAttributeCode () . '_default ' ;
240
+ $ aliasStore = 'at_ ' . $ attribute ->getAttributeCode ();
241
+ $ collection ->addAttributeToSelect ($ attribute ->getAttributeCode (), 'left ' );
242
+ break ;
243
+ default :
244
+ $ aliasDefault = 'at_ ' . sha1 ($ this ->getId ()) . $ attribute ->getAttributeCode () . '_default ' ;
245
+ $ aliasStore = 'at_ ' . sha1 ($ this ->getId ()) . $ attribute ->getAttributeCode ();
246
+
247
+ $ storeDefaultId = $ connection ->getIfNullSql ($ aliasDefault . '.store_id ' , Store::DEFAULT_STORE_ID );
248
+ $ storeId = $ connection ->getIfNullSql ($ aliasStore . '.store_id ' , $ this ->storeManager ->getStore ()->getId ());
249
+ $ linkField = $ attribute ->getEntity ()->getLinkField ();
250
+
251
+ $ collection ->getSelect ()->joinLeft (
252
+ [$ aliasDefault => $ collection ->getTable ($ attribute ->getBackendTable ())],
253
+ "( $ aliasDefault. $ linkField = e. $ linkField) AND ( $ aliasDefault.store_id = $ storeDefaultId) " .
254
+ " AND ( $ aliasDefault.attribute_id = {$ attribute ->getId ()}) " ,
255
+ []
256
+ );
257
+ $ collection ->getSelect ()->joinLeft (
258
+ [$ aliasStore => $ collection ->getTable ($ attribute ->getBackendTable ())],
259
+ "( $ aliasStore. $ linkField = e. $ linkField) AND ( $ aliasStore.store_id = $ storeId) " .
260
+ " AND ( $ aliasStore.attribute_id = {$ attribute ->getId ()}) " ,
261
+ []
262
+ );
263
+ }
264
+
265
+ $ fromPart = $ collection ->getSelect ()->getPart (Select::FROM );
266
+ if (isset ($ fromPart ['search_result ' ]['joinType ' ])
267
+ && $ fromPart ['search_result ' ]['joinType ' ] == Select::LEFT_JOIN
268
+ ) {
269
+ $ conditionCheck = $ connection ->quoteIdentifier ($ aliasStore . '.value_id ' ) . " > 0 " ;
270
+ $ conditionTrue = $ connection ->quoteIdentifier ($ aliasStore . '.value ' );
271
+ $ conditionFalse = $ connection ->quoteIdentifier ($ aliasDefault . '.value ' );
272
+ $ ifSql = "IF ( $ conditionCheck, $ conditionTrue, $ conditionFalse) " ;
273
+ $ joinedAttribute = new \Zend_Db_Expr ($ ifSql );
274
+ } else {
275
+ $ joinedAttribute = $ aliasStore . '. ' . 'value ' ;
276
+ }
277
+
278
+ $ this ->joinedAttributes [$ attribute ->getAttributeCode ()] = $ joinedAttribute ;
279
+
230
280
return $ this ;
231
281
}
232
282
0 commit comments