|
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
|
|
|
|
|
12
|
|
|
$fileName = Yii::getAlias('@app/config/web-configurables.php'); |
|
13
|
|
|
if (true === is_file($fileName)) { |
|
14
|
|
|
$array = include_once($fileName); |
|
15
|
|
|
if (true === is_array($array) && |
|
16
|
|
|
null !== $onlyParent = ArrayHelper::getValue($array, 'modules.shop.filterOnlyByParentProduct', null) |
|
17
|
|
|
) { |
|
18
|
|
|
unset($array['modules']['shop']['filterOnlyByParentProduct']); |
|
19
|
|
|
$array['modules']['shop']['productsFilteringMode'] = $onlyParent === true ? |
|
20
|
|
|
ConfigConfigurationModel::FILTER_PARENTS_ONLY : |
|
21
|
|
|
ConfigConfigurationModel::FILTER_CHILDREN_ONLY; |
|
22
|
|
|
|
|
23
|
|
|
$writer = new \app\modules\config\helpers\ApplicationConfigWriter([ |
|
24
|
|
|
'filename' => '@app/config/web-configurables.php', |
|
25
|
|
|
'loadExistingConfiguration' => false, |
|
26
|
|
|
]); |
|
27
|
|
|
$writer->addValues($array); |
|
28
|
|
|
$writer->commit(); |
|
29
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$shopFilename = Yii::getAlias('@app/config/configurables-state/shop.php'); |
|
35
|
|
|
if (true === file_exists($shopFilename)) { |
|
36
|
|
|
$shopConfigurablesArray = include($shopFilename); |
|
37
|
|
|
if (true === is_array($shopConfigurablesArray) && |
|
38
|
|
|
null !== $onlyParent = ArrayHelper::getValue($shopConfigurablesArray, 'filterOnlyByParentProduct', null) |
|
39
|
|
|
) { |
|
40
|
|
|
unset($shopConfigurablesArray['filterOnlyByParentProduct']); |
|
41
|
|
|
$shopConfigurablesArray['productsFilteringMode'] = $onlyParent === true ? |
|
42
|
|
|
ConfigConfigurationModel::FILTER_PARENTS_ONLY : |
|
43
|
|
|
ConfigConfigurationModel::FILTER_CHILDREN_ONLY; |
|
44
|
|
|
$writer = new \app\modules\config\helpers\ApplicationConfigWriter([ |
|
45
|
|
|
'filename' => '@app/config/configurables-state/shop.php', |
|
46
|
|
|
'loadExistingConfiguration' => false, |
|
47
|
|
|
]); |
|
48
|
|
|
$writer->addValues($shopConfigurablesArray); |
|
49
|
|
|
$writer->commit(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function down() |
|
56
|
|
|
{ |
|
57
|
|
|
echo "m160620_112036_config_fix_parent_only cannot be reverted.\n"; |
|
58
|
|
|
|
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/* |
|
63
|
|
|
// Use safeUp/safeDown to run migration code within a transaction |
|
64
|
|
|
public function safeUp() |
|
65
|
|
|
{ |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function safeDown() |
|
69
|
|
|
{ |
|
70
|
|
|
} |
|
71
|
|
|
*/ |
|
72
|
|
|
} |
|
73
|
|
|
|