Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Converter.php
Go to the documentation of this file.
1 <?php
9 
11 {
15  public function convert($source)
16  {
17  $xpath = new \DOMXPath($source);
18  return [
19  'credit_cards' => $this->convertCreditCards($xpath),
20  'groups' => $this->convertGroups($xpath),
21  'methods' => $this->convertMethods($xpath)
22  ];
23  }
24 
31  protected function convertCreditCards(\DOMXPath $xpath)
32  {
33  $creditCards = [];
35  foreach ($xpath->query('/payment/credit_cards/type') as $type) {
36  $typeArray = [];
37 
39  foreach ($type->childNodes as $typeSubNode) {
40  switch ($typeSubNode->nodeName) {
41  case 'label':
42  $typeArray['name'] = $typeSubNode->nodeValue;
43  break;
44  default:
45  break;
46  }
47  }
48 
49  $typeAttributes = $type->attributes;
50  $typeArray['order'] = $typeAttributes->getNamedItem('order')->nodeValue;
51  $ccId = $typeAttributes->getNamedItem('id')->nodeValue;
52  $creditCards[$ccId] = $typeArray;
53  }
54  uasort($creditCards, [$this, '_compareCcTypes']);
55  $config = [];
56  foreach ($creditCards as $code => $data) {
57  $config[$code] = $data['name'];
58  }
59  return $config;
60  }
61 
71  private function _compareCcTypes($left, $right)
72  {
73  return $left['order'] - $right['order'];
74  }
75 
82  protected function convertGroups(\DOMXPath $xpath)
83  {
84  $config = [];
86  foreach ($xpath->query('/payment/groups/group') as $group) {
87  $groupAttributes = $group->attributes;
88  $id = $groupAttributes->getNamedItem('id')->nodeValue;
89 
91  foreach ($group->childNodes as $groupSubNode) {
92  switch ($groupSubNode->nodeName) {
93  case 'label':
94  $config[$id] = $groupSubNode->nodeValue;
95  break;
96  default:
97  break;
98  }
99  }
100  }
101  return $config;
102  }
103 
110  protected function convertMethods(\DOMXPath $xpath)
111  {
112  $config = [];
114  foreach ($xpath->query('/payment/methods/method') as $method) {
115  $name = $method->attributes->getNamedItem('name')->nodeValue;
117  foreach ($method->childNodes as $methodSubNode) {
118  if ($methodSubNode->nodeType != XML_ELEMENT_NODE) {
119  continue;
120  }
121  $config[$name][$methodSubNode->nodeName] = $methodSubNode->nodeValue;
122  }
123  }
124  return $config;
125  }
126 }
$config
Definition: fraud_order.php:17
$id
Definition: fieldset.phtml:14
$source
Definition: source.php:23
$group
Definition: sections.phtml:16
$type
Definition: item.phtml:13
$method
Definition: info.phtml:13
$code
Definition: info.phtml:12
if(!isset($_GET['name'])) $name
Definition: log.php:14