Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ebayxmler.php
1<?php
3
5{
6 protected $fieldsMap = array(
7 "NAME" => array(
8 "PATH" => "ProductInformation/Title"
9 ),
10 "CATEGORIES" => array(
11 "PATH" => "ProductInformation/Categories/Category",
12 "TYPE" => "eBayLeafCategory"
13 )
14 );
15
16 public function makeProductNode($product)
17 {
18 $dom = new \DOMDocument('1.0', 'utf-8');
19
20 $productNode = $dom->createElement('Product');
21
22 foreach($this->fieldsMap as $bitrixFieldId => $ebayFieldPath)
23 {
24 if(isset($product[$bitrixFieldId]))
25 {
26 $arPath = $this->parsePath($ebayFieldPath);
27
28 $newNode = $oldNewNode = null;
29
30 foreach($arPath as $pathItem)
31 {
32 if(!$this->isChildExist($productNode, $pathItem))
33 {
34 $newNode = $dom->createElement($pathItem);
35
36 if($oldNewNode)
37 $oldNewNode->appendChild($newNode);
38 else
39 $productNode->appendChild($newNode);
40
41 $oldNewNode = $newNode;
42 }
43 }
44
45 if($newNode)
46 $newNode->nodeValue = $product[$bitrixFieldId];
47 }
48 }
49
50 return $dom->saveXML($productNode);
51 }
52
53 public function isChildExist(\DOMNode $node, $childName)
54 {
55 $result = false;
56 $children = $node->childNodes;
57
58 foreach($children as $childNode)
59 {
60 if($childNode->nodeName == $childName)
61 {
62 $result = true;
63 break;
64 }
65 }
66
67 return $result;
68 }
69
70 protected function parsePath($path)
71 {
72 return explode("/", $path);
73 }
74}
isChildExist(\DOMNode $node, $childName)
Definition ebayxmler.php:53