|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Yandex export controller |
|
5
|
|
|
* @author Alexey Krupskiy <[email protected]> |
|
6
|
|
|
* @link http://inji.ru/ |
|
7
|
|
|
* @copyright 2016 Alexey Krupskiy |
|
8
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
|
9
|
|
|
*/ |
|
10
|
|
|
class YandexExportController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
function indexAction() |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
function addToXml($xml, $parent, $nodeName, $text) |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
$node = $parent->appendChild($xml->createElement($nodeName)); |
|
17
|
|
|
$node->appendChild($xml->createTextNode($text)); |
|
18
|
|
|
return $node; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$imp = new DOMImplementation; |
|
22
|
|
|
|
|
23
|
|
|
$dtd = $imp->createDocumentType('yml_catalog', '', 'shops.dtd'); |
|
24
|
|
|
|
|
25
|
|
|
$xml = $imp->createDocument('', '', $dtd); |
|
26
|
|
|
|
|
27
|
|
|
$xml->encoding = 'UTF-8'; |
|
28
|
|
|
|
|
29
|
|
|
$xml->formatOutput = true; |
|
30
|
|
|
|
|
31
|
|
|
$root = $xml->createElement('yml_catalog'); |
|
32
|
|
|
$root->setAttribute("date", date('Y-m-d H:i')); |
|
33
|
|
|
$root = $xml->appendChild($root); |
|
34
|
|
|
|
|
35
|
|
|
$shop = $xml->createElement('shop'); |
|
36
|
|
|
|
|
37
|
|
|
addToXml($xml, $shop, 'name', \App::$cur->config['site']['name']); |
|
38
|
|
|
addToXml($xml, $shop, 'company', \App::$cur->config['site']['company_name']); |
|
39
|
|
|
addToXml($xml, $shop, 'url', 'http://' . INJI_DOMAIN_NAME); |
|
40
|
|
|
|
|
41
|
|
|
$currencies = $xml->createElement('currencies'); |
|
42
|
|
|
$currency = $currencies->appendChild($xml->createElement('currency')); |
|
43
|
|
|
$currency->setAttribute('id', 'RUR'); |
|
44
|
|
|
$currency->setAttribute('rate', '1'); |
|
45
|
|
|
$currency->setAttribute('plus', ''); |
|
46
|
|
|
$shop->appendChild($currencies); |
|
47
|
|
|
|
|
48
|
|
|
$categories = $xml->createElement('categories'); |
|
49
|
|
|
foreach (Ecommerce\Category::getList() as $category) { |
|
50
|
|
|
$xmlCategory = addToXml($xml, $categories, 'category', $category->name); |
|
51
|
|
|
$xmlCategory->setAttribute('id', $category->id); |
|
52
|
|
|
if ($category->parent_id) { |
|
53
|
|
|
$xmlCategory->setAttribute('parentId', $category->parent_id); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
$shop->appendChild($categories); |
|
57
|
|
|
|
|
58
|
|
|
addToXml($xml, $shop, 'local_delivery_cost', '300'); |
|
59
|
|
|
|
|
60
|
|
|
$offers = $xml->createElement('offers'); |
|
61
|
|
|
foreach (App::$cur->ecommerce->getItems() as $item) { |
|
62
|
|
|
$offer = $offers->appendChild($xml->createElement('offer')); |
|
63
|
|
|
addToXml($xml, $offer, 'url', 'http://' . INJI_DOMAIN_NAME . '/ecommerce/view/' . $item->id); |
|
64
|
|
|
addToXml($xml, $offer, 'price', $item->getPrice()->price); |
|
65
|
|
|
addToXml($xml, $offer, 'currencyId', 'RUR'); |
|
66
|
|
|
addToXml($xml, $offer, 'categoryId', $item->category_id); |
|
67
|
|
|
addToXml($xml, $offer, 'delivery', 'true'); |
|
68
|
|
|
addToXml($xml, $offer, 'local_delivery_cost', '300'); |
|
69
|
|
|
addToXml($xml, $offer, 'vendor', 'vendor'); |
|
70
|
|
|
addToXml($xml, $offer, 'model', 'model'); |
|
71
|
|
|
addToXml($xml, $offer, 'description', $item->description); |
|
72
|
|
|
addToXml($xml, $offer, 'manufacturer_warranty', 'true'); |
|
73
|
|
|
addToXml($xml, $offer, 'country_of_origin', 'Китай'); |
|
74
|
|
|
|
|
75
|
|
|
foreach ($item->options as $option) { |
|
76
|
|
|
$param = addToXml($xml, $offer, 'param', $option->value); |
|
77
|
|
|
$param->setAttribute('name', $option->item_option_name); |
|
78
|
|
|
if ($option->item_option_postfix) { |
|
79
|
|
|
$param->setAttribute('unit', $option->item_option_postfix); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
$shop->appendChild($offers); |
|
84
|
|
|
|
|
85
|
|
|
$root->appendChild($shop); |
|
86
|
|
|
|
|
87
|
|
|
header("Content-Type: text/xml"); |
|
88
|
|
|
header("Expires: Thu, 19 Feb 1998 13:24:18 GMT"); |
|
89
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
90
|
|
|
header("Cache-Control: no-cache, must-revalidate"); |
|
91
|
|
|
header("Cache-Control: post-check=0,pre-check=0"); |
|
92
|
|
|
header("Cache-Control: max-age=0"); |
|
93
|
|
|
header("Pragma: no-cache"); |
|
94
|
|
|
echo $xml->saveXML(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.