-
Notifications
You must be signed in to change notification settings - Fork 0
/
MagentoXMLCreator.php
54 lines (47 loc) · 1.92 KB
/
MagentoXMLCreator.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
<?php
/**
* This is a proof of concept and should not be used as it is
*/
if (file_exists("input/credentials.json")) {
// Get credentials file - for now it is considered to be json -
// credentials should be separated from the other config keys since this is our focus and those fields are
// consistent with the naming
$credentialsFile = file_get_contents("input/credentials.json");
$credentials = json_decode($credentialsFile, true);
} else {
echo "Can not load credentials. No credentials.json provided!";
return;
}
if (file_exists("input/config.xml")) {
$xml = simplexml_load_file("input/config.xml");
// Output of original config.xml
echo "Original config.xml: <br>";
print_r($xml);
echo "<br>";
echo "<br>";
$default = $xml->default;
$payment = $default->payment;
// Here we can then select the payments to add the specific data - for now we are not looping through the payments
// - we still would need to map the payment method names to the codes used within magento
$paypal = $payment->wirecard_elasticengine_paypal;
// Get the paypal credentials - we only want those for magento2
$paypalCredentials = $credentials['paypal']['credentials'];
// Add credential fields with defaultvalues
foreach ($paypalCredentials as $configKey => $defaultValue) {
$paypal->addChild($configKey, $defaultValue);
}
// Output of the adapted config.xml
echo "config.xml with added credentials: <br>";
print_r($xml);
// Save new config.xml to output
// $xml->asXML("output/config.xml");
// This way saves the xml unformatted - therefor we have to use something else
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->save("output/config.xml");
} else {
echo "Can not load Magento2 Schema based xml. No config.xml file provided";
return;
}