- Kód: Vybrat vše
<?php
$shopUrl = 'www.vasedomena.cz';
$langCz = 10;
$cfgFile = dirname(__FILE__) . '/../config/settings.inc.php';
if (!file_exists($cfgFile))
{
die('Skript musi byt umisten v rootu prestashopu v config/settings.inc.php musi byt nastaveni databaze.');
}
require_once($cfgFile);
$db = @MySQL_Connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_);
if (!$db)
{
die('Nemohu se spojit s databazi.');
}
MySQL_Select_DB(_DB_NAME_, $db);
MySQL_Query("SET NAMES 'utf8'");
$res = MySQL_Query("
SELECT
c.id_category,
c.id_parent,
c.level_depth,
l.name
FROM ps_category c
JOIN ps_category_lang l ON l.id_category = c.id_category AND l.id_lang = {$langCz}
WHERE active = 1 AND level_depth > 0
ORDER BY level_depth, id_category
");
$categories = array();
while ($row = MySQL_Fetch_Assoc($res))
{
if ($row['level_depth'] == 1)
{
$categories[$row['id_category']] = $row['name'];
}
else
{
$categories[$row['id_category']] = $categories[$row['id_parent']] . " > " . $row['name'];
}
}
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<products>\n";
$res = MySQL_Query("
SELECT
p.id_product,
p.quantity,
p.price,
p.reduction_price,
p.reduction_percent,
p.reduction_from,
p.reduction_to,
pl.name,
pl.description_short,
pl.link_rewrite,
i.id_image,
cp.id_category,
m.name AS manufacturer
FROM ps_product p
JOIN ps_product_lang pl USING(id_product)
JOIN ps_image i USING(id_product)
JOIN ps_category_product cp USING(id_product)
JOIN ps_category c USING(id_category)
JOIN ps_manufacturer m USING(id_manufacturer)
WHERE p.active = 1
AND i.cover = 1
AND cp.id_category > 1
AND c.level_depth > 1
ORDER BY p.id_product", $db);
$currentDate = date('Y-m-d');
while ($row = MySQL_Fetch_Assoc($res))
{
$desc = strip_tags(html_entity_decode($row['description_short'], ENT_COMPAT, 'utf-8'));
if ($result['reduction_from'] == $result['reduction_to']
|| ($result['reduction_from'] <= $currentDate
&& $currentDate <= $result['reduction_to']))
{
if ($row['reduction_price'] && $row['reduction_price'] > 0)
{
if ($row['reduction_price'] >= $row['price'])
{
$reduction = $row['price'];
}
else
{
$reduction = $row['reduction_price'];
}
}
elseif ($row['reduction_percent'] && $row['reduction_percent'] > 0)
{
if ($row['reduction_percent'] >= 100)
{
$reduction = $row['price'];
}
else
{
$reduction = $row['price'] * $row['reduction_percent'] / 100;
}
}
}
echo "<product>\n";
echo "\t<code>" . $row['id_product'] . "</code>\n";
echo "\t<category>" . $categories[$row['id_category']] . "</category>\n";
echo "\t<manufacturer>" . $row['manufacturer'] . "</manufacturer>\n";
echo "\t<name>" . $row['name'] . "</name>\n";
echo "\t<description>" . mb_substr($desc, 0, 512, 'utf-8') . "</description>\n";
echo "\t<price>" . round($row['price']*1.19-$reduction) . "</price>\n";
echo "\t<image_url>http://" . $shopUrl . "/img/p/" .$row['id_product'] .
"-" . $row['id_image'] . "-large.jpg</image_url>\n";
echo "\t<product_url>http://" . $shopUrl . "/" . $row['id_product'] .
"-" . $row['link_rewrite'] . ".html</product_url>\n";
echo "</product>\n";
}
echo "</products>\n";
?>
