338 lines
12 KiB
PHP
Executable File
338 lines
12 KiB
PHP
Executable File
<?php
|
|
require_once('../../config/config.inc.php');
|
|
require_once('../privatesales/Sale.php');
|
|
require_once('html2text.php');
|
|
|
|
if (!defined('_PS_BASE_URL_'))
|
|
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
|
|
|
$catalog = new Catalog();
|
|
$catalog->displayContent();
|
|
|
|
class Catalog
|
|
{
|
|
private $_xml;
|
|
private $_debug;
|
|
public $id_lang;
|
|
public $currentTime;
|
|
|
|
public $versions;
|
|
|
|
const FIELD_EXTRA = 2;
|
|
|
|
public function __construct() {
|
|
$this->_xml ="";
|
|
$this->versions = array(
|
|
'es' => 3,
|
|
'fr' => 2
|
|
);
|
|
}
|
|
|
|
public function setContent($version = 'fr')
|
|
{
|
|
$sales_today = array();
|
|
$sales_last_day = array();
|
|
$sale_current = array();
|
|
$id_lang = (int) $this->versions[$version];
|
|
|
|
$sales_today = Sale::getSales(TRUE, NULL, NULL, 'today', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version);
|
|
$sales_last_day = Sale::getSales(TRUE, NULL, NULL, 'last', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version);
|
|
$sale_current = self::getSales(TRUE, NULL, NULL, 'forward', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version);
|
|
|
|
foreach ($sales_today as &$sale) {
|
|
$sql = '
|
|
SELECT `value`
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
|
|
WHERE `id_field` = '.(int) self::FIELD_EXTRA .'
|
|
AND `id_lang` = '.(int) $id_lang.'
|
|
AND id_sale = '.(int) $sale->id
|
|
;
|
|
|
|
if ($value = Db::getInstance()->getValue($sql)) {
|
|
$sale->reduction = $value;
|
|
} else {
|
|
$sale->reduction = 'Non défini';
|
|
}
|
|
$desc = new html2text($sale->description[(int) $id_lang]);
|
|
$sale->description[(int) $id_lang] = $desc->get_text();
|
|
}
|
|
foreach ($sales_last_day as &$sale) {
|
|
$sql = '
|
|
SELECT `value`
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
|
|
WHERE `id_field` = '.(int) self::FIELD_EXTRA .'
|
|
AND `id_lang` ='.(int) $id_lang.'
|
|
AND `id_sale` ='.(int) $sale->id
|
|
;
|
|
if ($value = Db::getInstance()->getValue($sql)) {
|
|
$sale->reduction = $value;
|
|
} else {
|
|
$sale->reduction = 'Non défini';
|
|
}
|
|
$desc = new html2text($sale->description[(int) $id_lang]);
|
|
$sale->description[(int) $id_lang] = $desc->get_text();
|
|
}
|
|
foreach ($sale_current as &$sale) {
|
|
$sql = '
|
|
SELECT `value`
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
|
|
WHERE `id_field` = '.(int) self::FIELD_EXTRA .'
|
|
AND `id_lang` = '.(int) $id_lang.'
|
|
AND `id_sale` = ' . (int) $sale->id
|
|
;
|
|
if ($value = Db::getInstance()->getValue($sql)) {
|
|
$sale->reduction = $value;
|
|
} else {
|
|
$sale->reduction = 'Non défini';
|
|
}
|
|
$desc = new html2text($sale->description[(int) $id_lang]);
|
|
$sale->description[(int) $id_lang] = $desc->get_text();
|
|
}
|
|
|
|
$this->setXml($sales_today, $sales_last_day, $sale_current, false, $version);
|
|
}
|
|
|
|
|
|
public function displayContent()
|
|
{
|
|
foreach ($this->versions as $version => $id_lang) {
|
|
$this->setContent($version);
|
|
}
|
|
echo 'Fichier généré';
|
|
}
|
|
|
|
public function setXml($sales_today, $sales_last_day, $sale_current, $rss=false, $version)
|
|
{
|
|
$id_lang = (int) $this->versions[$version];
|
|
|
|
$this->_xml = '<?xml version="1.0" encoding="utf-8"?>';
|
|
$this->_xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
|
|
|
|
if ($version == 'es') {
|
|
$flux = fopen("flux_".$version.".xml", "w");
|
|
// Catalog
|
|
$this->_xml .= '<channel>';
|
|
//Shop details
|
|
$this->_xml .= '<title>Bebeboutik.es</title>';
|
|
$this->_xml .= '<link>www.bebeboutik.es</link>';
|
|
$this->_xml .= '<description>Bebeboutik.es</description>';
|
|
$this->_xml .= '<logo>http://www.bebeboutik.es/img/logo_3.png</logo>';
|
|
|
|
$title_sunday = Configuration::get('TITLE_NEWS_DIMANCHE_ES');
|
|
$link_sale = 'http://www.bebeboutik.es';
|
|
} else {
|
|
$flux = fopen("flux.xml", "w");
|
|
// Catalog
|
|
$this->_xml .= '<channel>';
|
|
//Shop details
|
|
$this->_xml .= '<title>Bebeboutik.com</title>';
|
|
$this->_xml .= '<link>www.bebeboutik.com</link>';
|
|
$this->_xml .= '<description>Bebeboutik.com</description>';
|
|
$this->_xml .= '<logo>http://www.bebeboutik.com/img/logo.png</logo>';
|
|
|
|
$title_sunday = Configuration::get('TITLE_NEWS_DIMANCHE');
|
|
$link_sale = 'http://www.bebeboutik.com';
|
|
}
|
|
|
|
$sql_title = '
|
|
SELECT `title`, `preheader`
|
|
FROM `ps_privatesale_newsletter`
|
|
WHERE `date_pub` = CURDATE()
|
|
AND `version` = "'.$version.'"'
|
|
;
|
|
$info_newsletter = Db::getInstance()->getRow($sql_title);
|
|
if (empty($info_newsletter)) {
|
|
$info_newsletter['title'] = Configuration::get('PRIVATESALES_TITLE_NEWSLETTER');
|
|
$info_newsletter['preheader'] = '';
|
|
}
|
|
|
|
$this->_xml.='<sect_00>';
|
|
$this->_xml .= '<titre><![CDATA['.$info_newsletter['title'].']]></titre>';
|
|
$this->_xml .= '<description><![CDATA['.$info_newsletter['preheader'].']]></description>';
|
|
$this->_xml .= '<titre_sunday><![CDATA['.$title_sunday.']]></titre_sunday>';
|
|
$this->_xml.='</sect_00>';
|
|
|
|
foreach ($sales_today as $item) {
|
|
$link = new Link();
|
|
$category = new Category($item->id_category);
|
|
$sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]);
|
|
$this->_xml.='<sect_01>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]></title>';
|
|
$this->_xml .= '<description><![CDATA['.$item->description[(int) $id_lang].']]></description>';
|
|
$this->_xml .= '<category><![CDATA['.$category->name[(int) $id_lang].']]></category>';
|
|
$this->_xml .= '<link>'.$link_sale.'</link>';
|
|
$this->_xml .= '<reduction><![CDATA['.$item->reduction.']]></reduction>';
|
|
$this->_xml .= '<image>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]></title>';
|
|
$this->_xml .= '<url>http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg</url>';
|
|
$this->_xml .= '</image>';
|
|
|
|
$this->_xml.='</sect_01>';
|
|
}
|
|
foreach ($sales_last_day as $item) {
|
|
$link = new Link();
|
|
$category = new Category($item->id_category);
|
|
$sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]);
|
|
|
|
$sql = '
|
|
SELECT `value`
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
|
|
WHERE `id_field` = 1
|
|
AND `id_lang` = '.(int) $id_lang.'
|
|
AND `id_sale` = '.(int) $item->id
|
|
;
|
|
if ($value = Db::getInstance()->getValue($sql)) {
|
|
$item->small_title = $value;
|
|
} else {
|
|
$item->small_title = 'Non défini';
|
|
}
|
|
|
|
|
|
$this->_xml.='<sect_02>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]></title>';
|
|
$this->_xml .= '<description><![CDATA['.$item->small_title.']]></description>';
|
|
$this->_xml .= '<category><![CDATA['.$category->name[(int) $id_lang].']]></category>';
|
|
$this->_xml .= '<link>'.$link_sale.'</link>';
|
|
$this->_xml .= '<reduction><![CDATA['.$item->reduction.']]></reduction>';
|
|
$this->_xml .= '<image>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]></title>';
|
|
$this->_xml .= '<url>http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg</url>';
|
|
$this->_xml .= '</image>';
|
|
|
|
$this->_xml.='</sect_02>';
|
|
}
|
|
|
|
foreach ($sale_current as $item) {
|
|
$link = new Link();
|
|
$category = new Category($item->id_category);
|
|
$sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]);
|
|
|
|
$sql = '
|
|
SELECT `value`
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
|
|
WHERE `id_field` = 1
|
|
AND `id_lang` = '.(int) $id_lang.'
|
|
AND `id_sale` = '. (int)$item->id
|
|
;
|
|
if ($value = Db::getInstance()->getValue($sql)) {
|
|
$item->small_title = $value;
|
|
} else {
|
|
$item->small_title = 'Non défini';
|
|
}
|
|
|
|
$this->_xml.='<sect_04>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]></title>';
|
|
$this->_xml .= '<description><![CDATA['.$item->small_title.']]></description>';
|
|
$this->_xml .= '<category><![CDATA['.$category->name[(int) $id_lang].']]></category>';
|
|
$this->_xml .= '<link>'.$link_sale.'</link>';
|
|
$this->_xml .= '<reduction><![CDATA['.$item->reduction.']]></reduction>';
|
|
$this->_xml .= '<image>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]></title>';
|
|
$this->_xml .= '<url>http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg</url>';
|
|
$this->_xml .= '</image>';
|
|
|
|
$this->_xml.='</sect_04>';
|
|
}
|
|
|
|
foreach ($sales_last_day as $item) {
|
|
$link = new Link();
|
|
$category = new Category($item->id_category);
|
|
$sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]);
|
|
|
|
$this->_xml.='<sect_03>';
|
|
// $this->_xml .= '<id_vente>'.$item->id.'</id_vente>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]></title>';
|
|
$this->_xml .= '<description><![CDATA['.$item->description[(int) $id_lang].']]></description>';
|
|
$this->_xml .= '<category><![CDATA['.$category->name[(int) $id_lang].']]></category>';
|
|
$this->_xml .= '<link>'.$link_sale.'</link>';
|
|
$this->_xml .= '<reduction><![CDATA['.$item->reduction.']]></reduction>';
|
|
$this->_xml .= '<image>';
|
|
$this->_xml .= '<title><![CDATA['.$item->title[(int) $id_lang].']]></title>';
|
|
$this->_xml .= '<url>http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg</url>';
|
|
$this->_xml .= '</image>';
|
|
|
|
$this->_xml.='</sect_03>';
|
|
}
|
|
|
|
$this->_xml .= '</channel>';
|
|
$this->_xml .= '</rss>';
|
|
|
|
fwrite($flux, $this->_xml);
|
|
fclose($flux);
|
|
}
|
|
|
|
public static function getSales($enabled=NULL, $logout=NULL, $featured=NULL, $future=NULL, $lite=FALSE, $pub=FALSE, $order_by='`date_end` ASC', $limit=NULL, $sale_type=NULL, $site_version=FALSE)
|
|
{
|
|
$result = array();
|
|
$where = array();
|
|
|
|
$query = '
|
|
SELECT p.`id_sale`
|
|
FROM `'._DB_PREFIX_.'privatesale` p
|
|
';
|
|
if($sale_type !== NULL){
|
|
$query.= ' LEFT JOIN `'._DB_PREFIX_.'privatesale_type` pt ON(pt.id_sale = p.id_sale AND pt.id_sale_type = '. $sale_type.')';
|
|
}
|
|
|
|
if($site_version !== FALSE) {
|
|
$query .= '
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_site_version` sv
|
|
ON p.`id_sale` = sv.`id_sale`
|
|
';
|
|
$where[] = 'sv.`version` = "'.pSQL($site_version).'"';
|
|
}
|
|
|
|
if($enabled !== NULL OR $logout !== NULL OR $featured !== NULL OR $future !== NULL) {
|
|
$enabled !== null? $where[] = '`enabled` = '.(int) $enabled: TRUE;
|
|
$logout !== null? $where[] = '`logout` = '.(int) $logout: TRUE;
|
|
$pub != FALSE? '': $where[] = '`public` = 0';
|
|
$featured !== null? $where[] = '`featured` = '.(int) $featured: TRUE;
|
|
// $sale_type !== NULL? $where[] = '`sale_type` = '.(int) $sale_type: TRUE;
|
|
|
|
if($future === 'current') {
|
|
$where[] = '`date_start` < NOW() AND `date_end` > NOW()';
|
|
} elseif($future === 'not_ended') {
|
|
$where[] = '`date_end` > NOW()';
|
|
} elseif($future === 'forward') {
|
|
$where[] = '`date_start` < NOW() AND `date_end` > NOW() AND forward_news = 1';
|
|
} elseif($future === 'all') {
|
|
$where[] = ' 1 = 1';
|
|
} elseif ($future === 'today') {
|
|
$where[] = 'CAST(`date_start` AS DATE) = CAST(NOW() AS DATE)';
|
|
} elseif ($future === 'last') {
|
|
$where[] = 'CAST(`date_end` AS DATE) = CAST(NOW() AS DATE)';
|
|
} elseif(is_int($future)) {
|
|
$where[] = '(`date_start` > NOW() AND `date_start` < DATE_ADD(NOW(), INTERVAL '.$future.' DAY))';
|
|
} elseif($future === TRUE) {
|
|
$where[] = '`date_start` > NOW()';
|
|
} elseif($future === FALSE) {
|
|
$where[] = '`date_start` < NOW() AND `date_end` < NOW()';
|
|
}
|
|
$query.= 'WHERE '.implode(' AND ', $where);
|
|
}
|
|
|
|
if($sale_type !== NULL){
|
|
$query.= ' AND pt.id_sale_type = '. $sale_type;
|
|
}
|
|
|
|
$query .= ' ORDER BY '.$order_by;
|
|
|
|
if($limit !== NULL) {
|
|
$query .= ' LIMIT '.$limit;
|
|
}
|
|
|
|
if($sales = Db::getInstance()->ExecuteS($query)) {
|
|
if($lite) {
|
|
foreach($sales AS $sale) {
|
|
$result[] = $sale['id_sale'];
|
|
}
|
|
} else {
|
|
foreach($sales AS $sale) {
|
|
$result[] = new Sale($sale['id_sale']);
|
|
}
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|