-
Notifications
You must be signed in to change notification settings - Fork 337
/
InstallData.php
113 lines (103 loc) · 3.62 KB
/
InstallData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
* @copyright 2020 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalog\Setup;
use Magento\Catalog\Model\Category;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Framework\Indexer\IndexerInterfaceFactory;
/**
* Catalog installer
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @author Aurelien FOUCRET <aurelien.foucret@smile.fr>
*/
class InstallData implements InstallDataInterface
{
/**
* EAV setup factory
*
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* @var \Smile\ElasticsuiteCatalog\Setup\CatalogSetup
*/
private $catalogSetup;
/**
* @var \Smile\ElasticsuiteCatalog\Setup\IndexerInterfaceFactory
*/
private $indexerFactory;
/**
* Class Constructor
*
* @param EavSetupFactory $eavSetupFactory Eav setup factory.
* @param CatalogSetupFactory $catalogSetupFactory Catalog Setup factory.
* @param IndexerInterfaceFactory $indexerFactory Indexer Factory.
*/
public function __construct(
EavSetupFactory $eavSetupFactory,
CatalogSetupFactory $catalogSetupFactory,
IndexerInterfaceFactory $indexerFactory
) {
$this->catalogSetup = $catalogSetupFactory->create();
$this->eavSetupFactory = $eavSetupFactory;
$this->indexerFactory = $indexerFactory;
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* Installs Data for the module :
* - Create attribute on category to enable/disable name indexation for search
* - Update is anchor attribute (hidden frontend input, null source model, enabled by default).
*
* @param ModuleDataSetupInterface $setup The setup interface
* @param ModuleContextInterface $context The module Context
*
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$this->catalogSetup->addCategoryNameSearchAttribute($eavSetup);
$this->catalogSetup->addIsDisplayCategoryInAutocompleteAttribute($eavSetup);
$this->catalogSetup->updateIsDisplayInAutocompleteAttribute($eavSetup);
$this->catalogSetup->updateCategoryIsAnchorAttribute($eavSetup);
$this->catalogSetup->updateDefaultValuesForNameAttributes($eavSetup);
$this->catalogSetup->updateCategorySearchableAttributes($eavSetup);
$this->catalogSetup->updateImageAttribute($eavSetup);
$this->catalogSetup->updateDefaultValuesForSkuAttribute($eavSetup);
$this->getIndexer('elasticsuite_categories_fulltext')->reindexAll();
$setup->endSetup();
}
/**
* Retrieve an indexer by its Id
*
* @param string $indexerId The indexer Id
*
* @return \Magento\Framework\Indexer\IndexerInterface
*/
private function getIndexer($indexerId)
{
return $this->indexerFactory->create()->load($indexerId);
}
}