-
Notifications
You must be signed in to change notification settings - Fork 0
/
srkoutz_xml.php
144 lines (126 loc) · 4.88 KB
/
srkoutz_xml.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(_PS_ROOT_DIR_.'/init.php');
header("Content-Type:text/xml; charset=utf-8");
$store_name = "www.STORE_NAME.gr";
$configuration = Configuration::getMultiple(array(
'PS_LANG_DEFAULT',
'PS_SHIPPING_FREE_PRICE',
'PS_SHIPPING_HANDLING',
'PS_SHIPPING_METHOD',
'PS_SHIPPING_FREE_WEIGHT',
'PS_CARRIER_DEFAULT'));
$id_lang = intval($configuration['PS_LANG_DEFAULT']);
$link = new Link();
/**
* Return available categories.
*
* @param bool|int $idLang Language ID
* @param bool $active Only return active categories
* @param bool $order Order the results
* @param string $sqlFilter Additional SQL clause(s) to filter results
* @param string $orderBy Change the default order by
* @param string $limit Set the limit
* Both the offset and limit can be given
*
* @return array Categories
*
* public static function getCategories($idLang = false, $active = true, $order = true, $sqlFilter = '', $orderBy = '', $limit = '')
*
*/
$categories = Category::getCategories($id_lang, false, false);
/**
* Get all available products.
*
* @param int $id_lang Language id
* @param int $start Start number
* @param int $limit Number of products to return
* @param string $order_by Field for ordering
* @param string $order_way Way for ordering (ASC or DESC)
*
* @return array Products details
*
* public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false, $only_active = false, Context $context = null)
*
*/
$products = Product::getProducts($id_lang, 0, 0, 'price', 'ASC', false, true);
$allCategories = array();
foreach ($categories as $category) {
$allCategories[$category['id_category']] = $category;
}
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
print "<".$store_name.">";
print "<created_at>".date('Y-m-d G:i:s')."</created_at>";
print "<products>";
foreach ($products as $product){
$quantity = Product::getQuantity($product['id_product']);
//Export only active product with quantity
if($product['active'] == 1 && $quantity > 0)
{
$product['link'] = $link->getProductLink($product['id_product']);
$product['price_inc'] = $product['price'];
$product['price_inc'] = number_format(round($product['price_inc'], 2), 2);
$cover = Product::getCover($product['id_product']);
$product['imageUrl'] = 'https://'.$link->getImageLink($product['link_rewrite'], $cover['id_image'], 'full_default');
print "<product>";
print "<id>".$product['id_product']."</id>";
print "<name><![CDATA[".$product['manufacturer_name']." ".$product['name']." ".$product["reference"]."]]></name>";
print "<link><![CDATA[".$product['link']."]]></link>";
print "<image><![CDATA[". $product['imageUrl']."]]></image>";
//Start Categories
$categoryTree = "";
$currentCategory = $allCategories[$product['id_category_default']];
while($currentCategory['id_category'] > 2)
{
$categoryTree.= $currentCategory['name'].'|';
$currentCategory = $allCategories[$currentCategory['id_parent']];
}
$FullCategoryPath = implode(' > ', array_reverse(explode('|', substr($categoryTree, 0, -1))));
echo "<category><![CDATA[".$FullCategoryPath."]]></category>";
//End Categories
//Start Price
$price = Product::getPriceStatic($product['id_product'],true,null,2);
print "<price><![CDATA[".$price."]]></price>";
//End Price
//Start Manufacturer
if($product['manufacturer_name']=='')
{
$product['manufacturer_name'] = "OEM";
}
print "<manufacturer><![CDATA[".$product['manufacturer_name']."]]></manufacturer>";
//End Manufacturer
//Start Availability
$quantity = Product::getQuantity($product['id_product']);
$out_of_stock = StockAvailable::outOfStock($product['id_product']);
if($out_of_stock == 1)
{
print "<instock>Y</instock>";
}
else
{
$instock = ($quantity>=1)? 'Y' :'N' ;
print "<instock>".$instock."</instock>";
}
if ($quantity >= 1)
{
$availability = 'Διαθέσιμο';
}
else if ($out_of_stock==1)
{
$availability = ($product['available_later']!='') ? $product['available_later'] :'Διαθέσιμο';
}
else
{
$availability = ($product['available_later']!='') ? $product['available_later'] :'Μη διαθέσιμο';
}
print "<availability>".$availability."</availability>";
//End Availability
print "<weight>".ltrim(substr(str_replace(".","",$product["weight"]), 0, -3), '0')."</weight>";
print "<mpn>".$product["reference"]."</mpn>";
print "<ean>".$product["ean13"]."</ean>";
print "</product>";
}
}
print "</products>";
print "</".$store_name.">";
?>