10
10
use Magento \Framework \Search \Request \Dimension ;
11
11
use Magento \Store \Model \Indexer \WebsiteDimensionProvider ;
12
12
use Magento \Customer \Model \Indexer \CustomerGroupDimensionProvider ;
13
+ use Magento \Indexer \Model \DimensionModes ;
14
+ use Magento \Indexer \Model \DimensionMode ;
13
15
14
16
/**
15
17
* Class to prepare new tables for new indexer mode
16
18
*/
17
- class ModeSwitcher
19
+ class ModeSwitcher implements \ Magento \ Indexer \ Model \ModeSwitcherInterface
18
20
{
19
- const XML_PATH_PRICE_DIMENSIONS_MODE = 'indexer/catalog_product_price/dimensions_mode ' ;
20
-
21
21
/**
22
22
* TableMaintainer
23
23
*
@@ -38,15 +38,60 @@ class ModeSwitcher
38
38
private $ dimensionsArray ;
39
39
40
40
/**
41
- * @param \Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer $tableMaintainer
42
- * @param \Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory $dimensionCollectionFactory
41
+ * @var \Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration
42
+ */
43
+ private $ dimensionModeConfiguration ;
44
+
45
+ /**
46
+ * @var ModeSwitcherConfiguration
47
+ */
48
+ private $ modeSwitcherConfiguration ;
49
+
50
+ /**
51
+ * @param TableMaintainer $tableMaintainer
52
+ * @param DimensionCollectionFactory $dimensionCollectionFactory
53
+ * @param DimensionModeConfiguration $dimensionModeConfiguration
54
+ * @param ModeSwitcherConfiguration $modeSwitcherConfiguration
43
55
*/
44
56
public function __construct (
45
- \Magento \Catalog \Model \Indexer \Product \Price \TableMaintainer $ tableMaintainer ,
46
- \Magento \Catalog \Model \Indexer \Product \Price \DimensionCollectionFactory $ dimensionCollectionFactory
57
+ TableMaintainer $ tableMaintainer ,
58
+ DimensionCollectionFactory $ dimensionCollectionFactory ,
59
+ DimensionModeConfiguration $ dimensionModeConfiguration ,
60
+ ModeSwitcherConfiguration $ modeSwitcherConfiguration
47
61
) {
48
62
$ this ->tableMaintainer = $ tableMaintainer ;
49
63
$ this ->dimensionCollectionFactory = $ dimensionCollectionFactory ;
64
+ $ this ->dimensionModeConfiguration = $ dimensionModeConfiguration ;
65
+ $ this ->modeSwitcherConfiguration = $ modeSwitcherConfiguration ;
66
+ }
67
+
68
+ /**
69
+ * @inheritdoc
70
+ */
71
+ public function getDimensionModes (): DimensionModes
72
+ {
73
+ $ dimensionsList = [];
74
+ foreach ($ this ->dimensionModeConfiguration ->getDimensionModes () as $ dimension => $ modes ) {
75
+ $ dimensionsList [] = new DimensionMode ($ dimension , $ modes );
76
+ }
77
+
78
+ return new DimensionModes ($ dimensionsList );
79
+ }
80
+
81
+ /**
82
+ * @inheritdoc
83
+ */
84
+ public function switchMode (string $ currentMode , string $ previousMode )
85
+ {
86
+ //Create new tables and move data
87
+ $ this ->createTables ($ currentMode );
88
+ $ this ->moveData ($ currentMode , $ previousMode );
89
+
90
+ //Change config options
91
+ $ this ->modeSwitcherConfiguration ->saveMode ($ currentMode );
92
+
93
+ //Delete old tables
94
+ $ this ->dropTables ($ previousMode );
50
95
}
51
96
52
97
/**
@@ -120,7 +165,7 @@ public function dropTables(string $previousMode)
120
165
*
121
166
* @param string $mode
122
167
*
123
- * @return array
168
+ * @return \Magento\Framework\Indexer\MultiDimensionProvider
124
169
*/
125
170
private function getDimensionsArray (string $ mode ): \Magento \Framework \Indexer \MultiDimensionProvider
126
171
{
0 commit comments