6
6
namespace Magento \CatalogSearch \Model \Indexer \Fulltext \Action ;
7
7
8
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
+ use Magento \Catalog \Model \Product ;
9
10
use Magento \Catalog \Model \Product \Attribute \Source \Status ;
11
+ use Magento \Catalog \Model \Product \Type ;
12
+ use Magento \Catalog \Model \ResourceModel \Product \Attribute \CollectionFactory ;
13
+ use Magento \CatalogSearch \Model \ResourceModel \EngineInterface ;
14
+ use Magento \CatalogSearch \Model \ResourceModel \EngineProvider ;
15
+ use Magento \Eav \Model \Config ;
16
+ use Magento \Eav \Model \Entity \Attribute ;
10
17
use Magento \Framework \App \ResourceConnection ;
18
+ use Magento \Framework \DataObject ;
19
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
11
20
use Magento \Framework \DB \Select ;
21
+ use Magento \Framework \EntityManager \EntityMetadata ;
22
+ use Magento \Framework \EntityManager \MetadataPool ;
23
+ use Magento \Framework \Event \ManagerInterface ;
12
24
use Magento \Store \Model \Store ;
25
+ use Magento \Store \Model \StoreManagerInterface ;
26
+ use Zend_Db ;
13
27
14
28
/**
15
29
* Catalog search full test search data provider.
@@ -24,7 +38,7 @@ class DataProvider
24
38
/**
25
39
* Searchable attributes cache
26
40
*
27
- * @var \Magento\Eav\Model\Entity\ Attribute[]
41
+ * @var Attribute[]
28
42
*/
29
43
private $ searchableAttributes ;
30
44
@@ -50,40 +64,40 @@ class DataProvider
50
64
private $ productEmulators = [];
51
65
52
66
/**
53
- * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\ CollectionFactory
67
+ * @var CollectionFactory
54
68
*/
55
69
private $ productAttributeCollectionFactory ;
56
70
57
71
/**
58
72
* Eav config
59
73
*
60
- * @var \Magento\Eav\Model\ Config
74
+ * @var Config
61
75
*/
62
76
private $ eavConfig ;
63
77
64
78
/**
65
79
* Catalog product type
66
80
*
67
- * @var \Magento\Catalog\Model\Product\ Type
81
+ * @var Type
68
82
*/
69
83
private $ catalogProductType ;
70
84
71
85
/**
72
86
* Core event manager proxy
73
87
*
74
- * @var \Magento\Framework\Event\ ManagerInterface
88
+ * @var ManagerInterface
75
89
*/
76
90
private $ eventManager ;
77
91
78
92
/**
79
93
* Store manager
80
94
*
81
- * @var \Magento\Store\Model\ StoreManagerInterface
95
+ * @var StoreManagerInterface
82
96
*/
83
97
private $ storeManager ;
84
98
85
99
/**
86
- * @var \Magento\CatalogSearch\Model\ResourceModel\ EngineInterface
100
+ * @var EngineInterface
87
101
*/
88
102
private $ engine ;
89
103
@@ -93,12 +107,12 @@ class DataProvider
93
107
private $ resource ;
94
108
95
109
/**
96
- * @var \Magento\Framework\DB\Adapter\ AdapterInterface
110
+ * @var AdapterInterface
97
111
*/
98
112
private $ connection ;
99
113
100
114
/**
101
- * @var \Magento\Framework\EntityManager\ EntityMetadata
115
+ * @var EntityMetadata
102
116
*/
103
117
private $ metadata ;
104
118
@@ -126,24 +140,24 @@ class DataProvider
126
140
127
141
/**
128
142
* @param ResourceConnection $resource
129
- * @param \Magento\Catalog\Model\Product\ Type $catalogProductType
130
- * @param \Magento\Eav\Model\ Config $eavConfig
131
- * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\ CollectionFactory $prodAttributeCollectionFactory
132
- * @param \Magento\CatalogSearch\Model\ResourceModel\ EngineProvider $engineProvider
133
- * @param \Magento\Framework\Event\ ManagerInterface $eventManager
134
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
135
- * @param \Magento\Framework\EntityManager\ MetadataPool $metadataPool
143
+ * @param Type $catalogProductType
144
+ * @param Config $eavConfig
145
+ * @param CollectionFactory $prodAttributeCollectionFactory
146
+ * @param EngineProvider $engineProvider
147
+ * @param ManagerInterface $eventManager
148
+ * @param StoreManagerInterface $storeManager
149
+ * @param MetadataPool $metadataPool
136
150
* @param int $antiGapMultiplier
137
151
*/
138
152
public function __construct (
139
153
ResourceConnection $ resource ,
140
- \ Magento \ Catalog \ Model \ Product \ Type $ catalogProductType ,
141
- \ Magento \ Eav \ Model \ Config $ eavConfig ,
142
- \ Magento \ Catalog \ Model \ ResourceModel \ Product \ Attribute \ CollectionFactory $ prodAttributeCollectionFactory ,
143
- \ Magento \ CatalogSearch \ Model \ ResourceModel \ EngineProvider $ engineProvider ,
144
- \ Magento \ Framework \ Event \ ManagerInterface $ eventManager ,
145
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
146
- \ Magento \ Framework \ EntityManager \ MetadataPool $ metadataPool ,
154
+ Type $ catalogProductType ,
155
+ Config $ eavConfig ,
156
+ CollectionFactory $ prodAttributeCollectionFactory ,
157
+ EngineProvider $ engineProvider ,
158
+ ManagerInterface $ eventManager ,
159
+ StoreManagerInterface $ storeManager ,
160
+ MetadataPool $ metadataPool ,
147
161
int $ antiGapMultiplier = 5
148
162
) {
149
163
$ this ->resource = $ resource ;
@@ -224,7 +238,7 @@ private function getSelectForSearchableProducts(
224
238
$ batch
225
239
) {
226
240
$ websiteId = (int )$ this ->storeManager ->getStore ($ storeId )->getWebsiteId ();
227
- $ lastProductId = (int ) $ lastProductId ;
241
+ $ lastProductId = (int )$ lastProductId ;
228
242
229
243
$ select = $ this ->connection ->select ()
230
244
->useStraightJoin (true )
@@ -242,7 +256,7 @@ private function getSelectForSearchableProducts(
242
256
$ this ->joinAttribute ($ select , 'status ' , $ storeId , [Status::STATUS_ENABLED ]);
243
257
244
258
if ($ productIds !== null ) {
245
- $ select ->where ('e.entity_id IN (?) ' , $ productIds , \ Zend_Db::INT_TYPE );
259
+ $ select ->where ('e.entity_id IN (?) ' , $ productIds , Zend_Db::INT_TYPE );
246
260
}
247
261
$ select ->where ('e.entity_id > ? ' , $ lastProductId );
248
262
$ select ->order ('e.entity_id ' );
@@ -308,14 +322,17 @@ private function joinAttribute(Select $select, $attributeCode, $storeId, array $
308
322
*/
309
323
public function getSearchableAttributes ($ backendType = null )
310
324
{
325
+ /** TODO: Remove this block in the next minor release and add a new public method instead */
326
+ if ($ this ->eavConfig ->getEntityType (Product::ENTITY )->getNeedRefreshSearchAttributesList ()) {
327
+ $ this ->clearSearchableAttributesList ();
328
+ }
311
329
if (null === $ this ->searchableAttributes ) {
312
330
$ this ->searchableAttributes = [];
313
331
314
- /** @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection $productAttributes */
315
332
$ productAttributes = $ this ->productAttributeCollectionFactory ->create ();
316
333
$ productAttributes ->addToIndexFilter (true );
317
334
318
- /** @var \Magento\Eav\Model\Entity\ Attribute[] $attributes */
335
+ /** @var Attribute[] $attributes */
319
336
$ attributes = $ productAttributes ->getItems ();
320
337
321
338
/** @deprecated */
@@ -329,7 +346,7 @@ public function getSearchableAttributes($backendType = null)
329
346
['engine ' => $ this ->engine , 'attributes ' => $ attributes ]
330
347
);
331
348
332
- $ entity = $ this ->eavConfig ->getEntityType (\ Magento \ Catalog \ Model \ Product::ENTITY )->getEntity ();
349
+ $ entity = $ this ->eavConfig ->getEntityType (Product::ENTITY )->getEntity ();
333
350
334
351
foreach ($ attributes as $ attribute ) {
335
352
$ attribute ->setEntity ($ entity );
@@ -355,6 +372,18 @@ public function getSearchableAttributes($backendType = null)
355
372
return $ this ->searchableAttributes ;
356
373
}
357
374
375
+ /**
376
+ * Remove searchable attributes list.
377
+ *
378
+ * @return void
379
+ */
380
+ private function clearSearchableAttributesList (): void
381
+ {
382
+ $ this ->searchableAttributes = null ;
383
+ $ this ->searchableAttributesByBackendType = [];
384
+ $ this ->eavConfig ->getEntityType (Product::ENTITY )->unsNeedRefreshSearchAttributesList ();
385
+ }
386
+
358
387
/**
359
388
* Retrieve searchable attribute by Id or code
360
389
*
@@ -369,7 +398,7 @@ public function getSearchableAttribute($attribute)
369
398
return $ attributes [$ attribute ];
370
399
}
371
400
372
- return $ this ->eavConfig ->getAttribute (\ Magento \ Catalog \ Model \ Product::ENTITY , $ attribute );
401
+ return $ this ->eavConfig ->getAttribute (Product::ENTITY , $ attribute );
373
402
}
374
403
375
404
/**
@@ -386,6 +415,7 @@ private function unifyField($field, $backendType = 'varchar')
386
415
} else {
387
416
$ expr = $ field ;
388
417
}
418
+
389
419
return $ expr ;
390
420
}
391
421
@@ -411,7 +441,7 @@ public function getProductAttributes($storeId, array $productIds, array $attribu
411
441
)->where (
412
442
'cpe.entity_id IN (?) ' ,
413
443
$ productIds ,
414
- \ Zend_Db::INT_TYPE
444
+ Zend_Db::INT_TYPE
415
445
)
416
446
);
417
447
foreach ($ attributeTypes as $ backendType => $ attributeIds ) {
@@ -479,6 +509,7 @@ private function getProductTypeInstance($typeId)
479
509
480
510
$ this ->productTypes [$ typeId ] = $ this ->catalogProductType ->factory ($ productEmulator );
481
511
}
512
+
482
513
return $ this ->productTypes [$ typeId ];
483
514
}
484
515
@@ -513,6 +544,7 @@ public function getProductChildIds($productId, $typeId)
513
544
if ($ relation ->getWhere () !== null ) {
514
545
$ select ->where ($ relation ->getWhere ());
515
546
}
547
+
516
548
return $ this ->connection ->fetchCol ($ select );
517
549
}
518
550
@@ -528,10 +560,11 @@ public function getProductChildIds($productId, $typeId)
528
560
private function getProductEmulator ($ typeId )
529
561
{
530
562
if (!isset ($ this ->productEmulators [$ typeId ])) {
531
- $ productEmulator = new \ Magento \ Framework \ DataObject ();
563
+ $ productEmulator = new DataObject ();
532
564
$ productEmulator ->setTypeId ($ typeId );
533
565
$ this ->productEmulators [$ typeId ] = $ productEmulator ;
534
566
}
567
+
535
568
return $ this ->productEmulators [$ typeId ];
536
569
}
537
570
@@ -660,6 +693,7 @@ function ($value) {
660
693
$ attributeOptionValue .= $ this ->attributeOptions [$ optionKey ][$ attrValueId ] . ' ' ;
661
694
}
662
695
}
696
+
663
697
return empty ($ attributeOptionValue ) ? null : trim ($ attributeOptionValue );
664
698
}
665
699
0 commit comments