bebeboutik/modules/fluxcatalogue/rss.php
2016-05-03 12:20:54 +02:00

103 lines
3.1 KiB
PHP

<?php
require_once('../../config/config.inc.php');
require_once('../privatesales/Sale.php');
if (!defined('_PS_BASE_URL_'))
define('_PS_BASE_URL_', Tools::getShopDomain(true));
$id_lang = Tools::getValue('id_lang');
if (!$id_lang
|| !in_array($id_lang, array(2,3))
) {
$id_lang = 2;
}
$catalog = new Catalog();
$catalog->displayContent($id_lang);
// $catalog->debug();
class Catalog
{
private $_xml;
private $_debug;
public $id_lang;
public $currentTime;
public function __construct(){
$this->_xml ="";
}
public function setContent($id_lang)
{
global $cookie;
$dom = new DomDocument();
if ($id_lang == 2) {
$site_version = 'fr';
} else if ($id_lang == 3) {
$site_version = 'es';
}
if (Tools::getValue('future') && Tools::getValue('future') == 1)
$sales = Sale::getSales(TRUE, NULL, NULL, TRUE, FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`date_start` DESC', NULL, $filter_type, $site_version);
else
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`date_start` DESC', NULL, $filter_type, $site_version);
foreach ($sales as $sale) {
$sql = 'SELECT value FROM '._DB_PREFIX_.'privatesale_extrafield_sale WHERE id_field = 2 AND id_lang = '.(int) $id_lang.' AND id_sale = ' . $sale->id;
if ($value = Db::getInstance()->getValue($sql)){
$sale->reduction = $value;
}else{
$sale->reduction = "Non défini";
}
}
$this->setXml($sales, false, $id_lang);
}
public function displayContent($id_lang)
{
$this->setContent($id_lang);
header('Content-Type: text/xml');
echo $this->_xml;
}
public function setXml($items, $rss=false, $id_lang){
$this->_xml = '<?xml version="1.0" encoding="UTF-8" ?>';
// Catalog
$this->_xml .= '<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><catalogue>';
//Shop details
$this->_xml .= '<infos_boutique>';
$this->_xml .= '<logo>http://www.bebeboutik.com/img/logo.png</logo>';
$this->_xml .= '<nom>bebeboutik.com</nom>';
if (Tools::getValue('partenaire')
&& Tools::getValue('partenaire') == "family_deal") {
$this->_xml .= '<url><![CDATA[http://www.bebeboutik.com/invite/MjAxMy0xMC0y=02bj5yapRXdvJWZiVmYAxWYlRWL5xWatFmZ&lp=mosaique-enfant]]></url>';
} else {
$this->_xml .= '<url>www.bebeboutik.com</url>';
}
$this->_xml .= '</infos_boutique>';
foreach ($items as $item) {
$this->_xml.='<vente>';
// $this->_xml .= '<id_vente>'.$item->id.'</id_vente>';
$this->_xml .= '<nom_vente><![CDATA['.$item->title[(int) $id_lang].']]></nom_vente>';
$this->_xml .= '<description><![CDATA['.$item->description[(int) $id_lang].']]></description>';
$this->_xml .= '<date_debut>'.$item->date_start.'</date_debut>';
$this->_xml .= '<date_fin>'.$item->date_end.'</date_fin>';
$this->_xml .= '<reduction>'.$item->reduction.'</reduction>';
$this->_xml .= '<image_vente>http://www.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg</image_vente>';
$this->_xml.='</vente>';
}
$this->_xml .= '</catalogue></rss>';
}
}