2
2
3
3
namespace Algolia \AlgoliaSearch \Helper \Entity ;
4
4
5
- use Algolia \AlgoliaSearch \Service \AlgoliaConnector ;
5
+ use Algolia \AlgoliaSearch \Service \AdditionalSection \ RecordBuilder as AdditionalSectionRecordBuilder ;
6
6
use Algolia \AlgoliaSearch \Service \IndexNameFetcher ;
7
7
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
8
8
use Magento \Eav \Model \Config ;
@@ -15,16 +15,20 @@ class AdditionalSectionHelper extends AbstractEntityHelper
15
15
public const INDEX_NAME_SUFFIX = '_section ' ;
16
16
17
17
public function __construct (
18
- protected ManagerInterface $ eventManager ,
19
- protected CollectionFactory $ collectionFactory ,
20
- protected Config $ eavConfig ,
21
- protected IndexNameFetcher $ indexNameFetcher ,
22
- )
23
- {
18
+ protected ManagerInterface $ eventManager ,
19
+ protected CollectionFactory $ collectionFactory ,
20
+ protected Config $ eavConfig ,
21
+ protected AdditionalSectionRecordBuilder $ additionalSectionRecordBuilder ,
22
+ protected IndexNameFetcher $ indexNameFetcher ,
23
+ ) {
24
24
parent ::__construct ($ indexNameFetcher );
25
25
}
26
26
27
- public function getIndexSettings ($ storeId ): array
27
+ /**
28
+ * @param int|null $storeId
29
+ * @return array
30
+ */
31
+ public function getIndexSettings (?int $ storeId = null ): array
28
32
{
29
33
$ indexSettings = [
30
34
'searchableAttributes ' => ['unordered(value) ' ],
@@ -68,23 +72,13 @@ public function getAttributeValues($storeId, $section): array
68
72
}
69
73
70
74
$ values = array_map (function ($ value ) use ($ section , $ storeId ) {
71
- $ record = [
72
- AlgoliaConnector::ALGOLIA_API_OBJECT_ID => $ value ,
73
- 'value ' => $ value ,
74
- ];
75
-
76
- $ transport = new DataObject ($ record );
77
- $ this ->eventManager ->dispatch (
78
- 'algolia_additional_section_item_index_before ' ,
79
- ['section ' => $ section , 'record ' => $ transport , 'store_id ' => $ storeId ]
80
- );
81
- $ this ->eventManager ->dispatch (
82
- 'algolia_additional_section_items_before_index ' ,
83
- ['section ' => $ section , 'record ' => $ transport , 'store_id ' => $ storeId ]
84
- );
85
- $ record = $ transport ->getData ();
86
-
87
- return $ record ;
75
+ $ dataObject = new DataObject ([
76
+ 'value ' => $ value ,
77
+ 'section ' => $ section ,
78
+ 'store_id ' => $ storeId
79
+ ]);
80
+
81
+ return $ this ->additionalSectionRecordBuilder ->buildRecord ($ dataObject );
88
82
}, $ values );
89
83
90
84
return $ values ;
0 commit comments