|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use app\modules\shop\models\ConfigConfigurationModel; |
|
4
|
|
|
use yii\db\Migration; |
|
5
|
|
|
use yii\helpers\ArrayHelper; |
|
6
|
|
|
|
|
7
|
|
|
class m160620_112036_config_fix_parent_only extends Migration |
|
8
|
|
|
{ |
|
9
|
|
|
public function up() |
|
10
|
|
|
{ |
|
11
|
|
|
$fileName = Yii::getAlias('@app/config/web-configurables.php'); |
|
12
|
|
View Code Duplication |
if (true === is_file($fileName)) { |
|
13
|
|
|
$array = include_once($fileName); |
|
14
|
|
|
if (true === is_array($array) && |
|
15
|
|
|
null !== $onlyParent = ArrayHelper::getValue($array, 'modules.shop.filterOnlyByParentProduct', null) |
|
16
|
|
|
) { |
|
17
|
|
|
unset($array['modules']['shop']['filterOnlyByParentProduct']); |
|
18
|
|
|
$array['modules']['shop']['productsFilteringMode'] = $onlyParent === true ? |
|
19
|
|
|
ConfigConfigurationModel::FILTER_PARENTS_ONLY : |
|
20
|
|
|
ConfigConfigurationModel::FILTER_CHILDREN_ONLY; |
|
21
|
|
|
|
|
22
|
|
|
$writer = new \app\modules\config\helpers\ApplicationConfigWriter([ |
|
23
|
|
|
'filename' => '@app/config/web-configurables.php', |
|
24
|
|
|
'loadExistingConfiguration' => false, |
|
25
|
|
|
]); |
|
26
|
|
|
$writer->addValues($array); |
|
27
|
|
|
$writer->commit(); |
|
28
|
|
|
|
|
29
|
|
|
} else { |
|
30
|
|
|
echo "file @app/config/web-configurables.php cannot be changed. \n"; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$shopFilename = Yii::getAlias('@app/config/configurables-state/shop.php'); |
|
36
|
|
View Code Duplication |
if (true === file_exists($shopFilename)) { |
|
37
|
|
|
$shopConfigurablesArray = include($shopFilename); |
|
38
|
|
|
if (true === is_array($shopConfigurablesArray) && |
|
39
|
|
|
null !== $onlyParent = ArrayHelper::getValue($shopConfigurablesArray, 'filterOnlyByParentProduct', null) |
|
40
|
|
|
) { |
|
41
|
|
|
unset($shopConfigurablesArray['filterOnlyByParentProduct']); |
|
42
|
|
|
$shopConfigurablesArray['productsFilteringMode'] = $onlyParent === true ? |
|
43
|
|
|
ConfigConfigurationModel::FILTER_PARENTS_ONLY : |
|
44
|
|
|
ConfigConfigurationModel::FILTER_CHILDREN_ONLY; |
|
45
|
|
|
$writer = new \app\modules\config\helpers\ApplicationConfigWriter([ |
|
46
|
|
|
'filename' => '@app/config/configurables-state/shop.php', |
|
47
|
|
|
'loadExistingConfiguration' => false, |
|
48
|
|
|
]); |
|
49
|
|
|
$writer->addValues($shopConfigurablesArray); |
|
50
|
|
|
$writer->commit(); |
|
51
|
|
|
} else { |
|
52
|
|
|
echo " file@app/config/configurables-state/shop.php cannot be changed. \n"; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function down() |
|
59
|
|
|
{ |
|
60
|
|
|
$fileName = Yii::getAlias('@app/config/web-configurables.php'); |
|
61
|
|
View Code Duplication |
if (true === is_file($fileName)) { |
|
62
|
|
|
$array = include_once($fileName); |
|
63
|
|
|
if (true === is_array($array) && |
|
64
|
|
|
null !== $productsFilteringMode = ArrayHelper::getValue($array, |
|
65
|
|
|
'modules.shop.productsFilteringMode', null) |
|
66
|
|
|
) { |
|
67
|
|
|
unset($array['modules']['shop']['productsFilteringMode']); |
|
68
|
|
|
$array['modules']['shop']['filterOnlyByParentProduct'] = |
|
69
|
|
|
$productsFilteringMode !== ConfigConfigurationModel::FILTER_CHILDREN_ONLY ? |
|
70
|
|
|
true : |
|
71
|
|
|
false; |
|
72
|
|
|
|
|
73
|
|
|
$writer = new \app\modules\config\helpers\ApplicationConfigWriter([ |
|
74
|
|
|
'filename' => '@app/config/web-configurables.php', |
|
75
|
|
|
'loadExistingConfiguration' => false, |
|
76
|
|
|
]); |
|
77
|
|
|
$writer->addValues($array); |
|
78
|
|
|
$writer->commit(); |
|
79
|
|
|
|
|
80
|
|
|
} else { |
|
81
|
|
|
echo "file @app/config/web-configurables.php cannot be revert. \n"; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
$shopFilename = Yii::getAlias('@app/config/configurables-state/shop.php'); |
|
87
|
|
View Code Duplication |
if (true === file_exists($shopFilename)) { |
|
88
|
|
|
$shopConfigurablesArray = include($shopFilename); |
|
89
|
|
|
if (true === is_array($shopConfigurablesArray) && |
|
90
|
|
|
null !== $productsFilteringMode = ArrayHelper::getValue($shopConfigurablesArray, |
|
91
|
|
|
'productsFilteringMode', null) |
|
92
|
|
|
) { |
|
93
|
|
|
unset($shopConfigurablesArray['productsFilteringMode']); |
|
94
|
|
|
$shopConfigurablesArray['filterOnlyByParentProduct'] = |
|
95
|
|
|
$productsFilteringMode !== ConfigConfigurationModel::FILTER_CHILDREN_ONLY ? |
|
96
|
|
|
true : |
|
97
|
|
|
false; |
|
98
|
|
|
|
|
99
|
|
|
$writer = new \app\modules\config\helpers\ApplicationConfigWriter([ |
|
100
|
|
|
'filename' => '@app/config/configurables-state/shop.php', |
|
101
|
|
|
'loadExistingConfiguration' => false, |
|
102
|
|
|
]); |
|
103
|
|
|
$writer->addValues($shopConfigurablesArray); |
|
104
|
|
|
$writer->commit(); |
|
105
|
|
|
} else { |
|
106
|
|
|
echo "file @app/config/configurables-state/shop.php cannot be revert. \n"; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|