@@ -28,14 +28,10 @@ class UpdateBmltoPayLater implements DataPatchInterface
28
28
/**
29
29
* @var array
30
30
*/
31
- private $ bmlToPayLaterSettings = [
31
+ private $ bmlToPayLater = [
32
32
[
33
33
'pages ' => ['productpage ' ],
34
34
'data ' => [
35
- 'display ' => [
36
- 'name ' => 'display ' ,
37
- 'values ' => ['0 ' => '0 ' , '1 ' => '1 ' ]
38
- ],
39
35
'position ' => [
40
36
'name ' =>'position ' ,
41
37
'values ' => ['0 ' => 'header ' , '1 ' => 'near_pp_button ' ],
@@ -103,52 +99,73 @@ public function apply()
103
99
continue ;
104
100
}
105
101
106
- foreach ($ this ->bmlToPayLaterSettings as $ bmlToPayLaterSetting ) {
102
+ foreach ($ this ->bmlToPayLater as $ bmlToPayLaterSetting ) {
107
103
if (in_array ($ page , $ bmlToPayLaterSetting ['pages ' ])
108
104
&& array_key_exists ($ setting , $ bmlToPayLaterSetting ['data ' ])
109
105
) {
110
106
$ pageSetting = $ bmlToPayLaterSetting ['data ' ][$ setting ];
111
- $ dependsPath = isset ($ pageSetting ['depends ' ])
112
- ? self ::BMLPATH . $ page . '_ ' . $ pageSetting ['depends ' ]['name ' ]
113
- : '' ;
114
-
115
- if (!array_key_exists ('depends ' , $ pageSetting )
116
- || (array_key_exists ($ dependsPath , $ bmlSettings )
117
- && $ bmlSettings [$ dependsPath ] === $ pageSetting ['depends ' ]['value ' ])
118
- ) {
119
- $ path = $ payLaterPath . '_ ' . $ pageSetting ['name ' ];
120
- $ value = $ pageSetting ['values ' ][$ bmlValue ];
121
- $ this ->moduleDataSetup ->getConnection ()->insertOnDuplicate (
122
- $ this ->moduleDataSetup ->getTable ('core_config_data ' ),
123
- [
124
- 'scope ' => 'default ' ,
125
- 'scope_id ' => 0 ,
126
- 'path ' => $ path ,
127
- 'value ' => $ value
128
- ]
129
- );
130
- if (array_key_exists ('requires ' , $ pageSetting )
131
- && array_key_exists ($ value , $ pageSetting ['requires ' ])
132
- ) {
133
- $ requiredPath = $ payLaterPath . '_ ' . $ pageSetting ['requires ' ][$ value ]['name ' ];
134
- $ requiredValue = $ pageSetting ['requires ' ][$ value ]['value ' ];
135
- $ this ->moduleDataSetup ->getConnection ()->insertOnDuplicate (
136
- $ this ->moduleDataSetup ->getTable ('core_config_data ' ),
137
- [
138
- 'scope ' => 'default ' ,
139
- 'scope_id ' => 0 ,
140
- 'path ' => $ requiredPath ,
141
- 'value ' => $ requiredValue
142
- ]
143
- );
144
- }
145
- }
107
+
108
+ $ this ->convertAndSaveConfigValues ($ bmlSettings , $ pageSetting , $ payLaterPath , $ page , $ bmlValue );
146
109
}
147
110
}
148
111
}
112
+
149
113
return $ this ->moduleDataSetup ->getConnection ()->endSetup ();
150
114
}
151
115
116
+ /**
117
+ * Convert BML settings to PayLater and save
118
+ *
119
+ * @param array $bmlSettings
120
+ * @param array $pageSetting
121
+ * @param string $payLaterPath
122
+ * @param string $page
123
+ * @param string $bmlValue
124
+ */
125
+ private function convertAndSaveConfigValues (
126
+ array $ bmlSettings ,
127
+ array $ pageSetting ,
128
+ string $ payLaterPath ,
129
+ string $ page ,
130
+ string $ bmlValue
131
+ ) {
132
+ $ dependsPath = isset ($ pageSetting ['depends ' ])
133
+ ? self ::BMLPATH . $ page . '_ ' . $ pageSetting ['depends ' ]['name ' ]
134
+ : '' ;
135
+
136
+ if (!array_key_exists ('depends ' , $ pageSetting )
137
+ || (array_key_exists ($ dependsPath , $ bmlSettings )
138
+ && $ bmlSettings [$ dependsPath ] === $ pageSetting ['depends ' ]['value ' ])
139
+ ) {
140
+ $ path = $ payLaterPath . '_ ' . $ pageSetting ['name ' ];
141
+ $ value = $ pageSetting ['values ' ][$ bmlValue ];
142
+ $ this ->moduleDataSetup ->getConnection ()->insertOnDuplicate (
143
+ $ this ->moduleDataSetup ->getTable ('core_config_data ' ),
144
+ [
145
+ 'scope ' => 'default ' ,
146
+ 'scope_id ' => 0 ,
147
+ 'path ' => $ path ,
148
+ 'value ' => $ value
149
+ ]
150
+ );
151
+ if (array_key_exists ('requires ' , $ pageSetting )
152
+ && array_key_exists ($ value , $ pageSetting ['requires ' ])
153
+ ) {
154
+ $ requiredPath = $ payLaterPath . '_ ' . $ pageSetting ['requires ' ][$ value ]['name ' ];
155
+ $ requiredValue = $ pageSetting ['requires ' ][$ value ]['value ' ];
156
+ $ this ->moduleDataSetup ->getConnection ()->insertOnDuplicate (
157
+ $ this ->moduleDataSetup ->getTable ('core_config_data ' ),
158
+ [
159
+ 'scope ' => 'default ' ,
160
+ 'scope_id ' => 0 ,
161
+ 'path ' => $ requiredPath ,
162
+ 'value ' => $ requiredValue
163
+ ]
164
+ );
165
+ }
166
+ }
167
+ }
168
+
152
169
/**
153
170
* @inheritdoc
154
171
*/
0 commit comments