650 lines
27 KiB
PHP
650 lines
27 KiB
PHP
<?php
|
|
|
|
class SenseFuelFluxExport
|
|
{
|
|
const ADD_LINE_BREAKS_IN_XML = true;
|
|
const SENSEFUEL_MAX_CAT_DEPTH = 4;
|
|
const IN_STOCK_STRING = 'in stock';
|
|
const OUT_OF_STOCK_STRING = 'out of stock';
|
|
const EXPORT_FILENAME = 'export_product_flux_';
|
|
const EXPORT_FILENAME_CONSOMMABLE = 'export_product_conso_only_';
|
|
const EXPORT_EXTENSION = '.xml';
|
|
const EXPORT_SUB_DIR = '/export/';
|
|
const SALE_TYPE_CONSO = 'conso';
|
|
const SALE_TYPE_GLOBAL = 'global';
|
|
const GENERIC_BRAND = 'generique';
|
|
|
|
public $products;
|
|
public $xml;
|
|
|
|
private $content;
|
|
|
|
public static $enabledLanguageArray = array(2, 3);
|
|
|
|
public function __construct($module)
|
|
{
|
|
global $cart, $cookie;
|
|
if (null === $cookie) {
|
|
$cookie = new Cookie('ps');
|
|
}
|
|
$cookie->id_lang = (int)Language::getIdByIso('fr');
|
|
$this->module = $module;
|
|
$this->products = array();
|
|
$this->xml = '';
|
|
$cart = new Cart();
|
|
$cart->id_lang = (int)Language::getIdByIso('fr');
|
|
}
|
|
|
|
private static function isShopConsoProduct($currentProduct)
|
|
{
|
|
return (int)$currentProduct['id_category'] === (int)_SHOP_CATEGORY_ROOT_;
|
|
}
|
|
|
|
private static function convertWrongChars($value)
|
|
{
|
|
$replaced = array(
|
|
0 => '/&/',
|
|
1 => '/>/',
|
|
2 => '/</',
|
|
3 => '/\'/',
|
|
4 => '/"/'
|
|
);
|
|
$replacement = array(
|
|
0 => '&',
|
|
1 => '>',
|
|
2 => '<',
|
|
3 => ''',
|
|
4 => '"'
|
|
);
|
|
|
|
return preg_replace($replaced, $replacement, $value);
|
|
}
|
|
|
|
public function writeXml()
|
|
{
|
|
foreach (self::$enabledLanguageArray as $idLang) {
|
|
$language = new Language((int)$idLang);
|
|
$files = array(
|
|
self::SALE_TYPE_GLOBAL => self::getFilePath($language->iso_code, self::SALE_TYPE_GLOBAL),
|
|
//self::SALE_TYPE_CONSO => self::getFilePath($language->iso_code, self::SALE_TYPE_CONSO),
|
|
);
|
|
foreach ($files as $type => $currentFile) {
|
|
if (file_exists($currentFile)) {
|
|
unlink($currentFile);
|
|
}
|
|
echo 'Getting products' . "\n";
|
|
$this->hydrateProducts($type, $language);
|
|
echo 'Getting categories' . "\n";
|
|
$this->hydrateProductCategories($language);
|
|
//echo 'Getting brands' . "\n";
|
|
//$this->hydrateProductBrands();
|
|
//echo 'Getting menu tags' . "\n";
|
|
//$this->hydrateTagCategories($language);
|
|
echo "Getting family\n";
|
|
$this->hydrateProductFamily($language);
|
|
echo 'Getting availability' . "\n";
|
|
$this->hydrateProductStock();
|
|
try {
|
|
echo 'Creating XML' . "\n";
|
|
file_put_contents($currentFile, $this->buildXML($language));
|
|
$this->xml = "";
|
|
} catch (Exception $ex) {
|
|
Logger::AddLog("file SenseFuelFluxExport.php - " . $ex->getMessage(), 4, '0000001', 'Product', '0');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private function hydrateProducts($type, $language)
|
|
{
|
|
$this->products = array();
|
|
if ($type === self::SALE_TYPE_GLOBAL) {
|
|
$sql = '
|
|
SELECT p.`id_product`,
|
|
p.`reference`,
|
|
p.`id_manufacturer`,
|
|
pl.`name`,
|
|
pl.`description_short` AS description,
|
|
pl.`link_rewrite`,
|
|
p.`ean13`,
|
|
p.`ecotax`,
|
|
i.`id_image`,
|
|
cl.`name` AS catname,
|
|
cl.`id_category`,
|
|
cl.`link_rewrite` AS cat_link_rewrite,
|
|
ps.`id_sale`,
|
|
ps.`date_start`,
|
|
ps.`date_end`,
|
|
pdl.`name` AS `delay`,
|
|
/*pcl.id_corner*/
|
|
0 AS id_corner
|
|
FROM `' . _DB_PREFIX_ . 'product` p
|
|
JOIN `' . _DB_PREFIX_ . 'product_lang` pl
|
|
ON (pl.id_product = p.id_product AND pl.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'product_ps_cache` ppc
|
|
ON ppc.id_product = p.id_product
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale` ps
|
|
ON ps.id_sale = ppc.id_sale
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_site_version` pssv
|
|
ON ps.id_sale = pssv.id_sale
|
|
JOIN `' . _DB_PREFIX_ . 'category_lang` cl
|
|
ON (cl.id_category = ps.id_category AND cl.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'image` i
|
|
ON (i.id_product = p.id_product AND i.cover = 1)
|
|
/*JOIN `' . _DB_PREFIX_ . 'privatesale_delay_sale` pds
|
|
ON (pds.id_sale = ps.id_sale AND pds.id_lang = ' . $language->id . ')*/
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_delay_lang` pdl
|
|
ON (pdl.id_delay = ps.delivery_delay AND pdl.id_lang = ' . $language->id . ')
|
|
/*LEFT JOIN `' . _DB_PREFIX_ . 'product_corner_lang` pcl
|
|
ON (pcl.id_product = p.id_product AND pcl.id_lang = ' . $language->id . ')*/
|
|
WHERE ps.date_start < NOW() /*maybe a larger scope could be required here*/
|
|
AND ps.date_end > NOW()
|
|
AND ps.enabled = TRUE
|
|
AND p.available_for_order = 1
|
|
AND p.active = 1
|
|
AND pssv.version = \'' . $language->iso_code . '\'
|
|
LIMIT 20000';
|
|
$this->products = Db::getInstance()->ExecuteQ($sql);
|
|
} elseif ($type === self::SALE_TYPE_CONSO) {
|
|
$sql = '
|
|
SELECT p.`id_product`,
|
|
p.`reference`,
|
|
p.`id_manufacturer`,
|
|
pl.`name`,
|
|
pl.`description_short` AS description
|
|
pl.`link_rewrite`,
|
|
p.`ean13`,
|
|
p.`ecotax`,
|
|
i.`id_image`,
|
|
cl.`name` AS catname,
|
|
cl.`id_category`,
|
|
cl.`link_rewrite` AS cat_link_rewrite,
|
|
ps.`id_sale`,
|
|
ps.`date_start`,
|
|
ps.`date_end`,
|
|
pdl.`name` AS `delay`,
|
|
pcl.id_corner
|
|
FROM `' . _DB_PREFIX_ . 'product` p
|
|
JOIN `' . _DB_PREFIX_ . 'product_lang` pl
|
|
ON (pl.id_product = p.id_product AND pl.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'product_ps_cache` ppc
|
|
ON ppc.id_product = p.id_product
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale` ps
|
|
ON ps.id_sale = ppc.id_sale
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_site_version` pssv
|
|
ON ps.id_sale = pssv.id_sale
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_category` psc
|
|
ON (psc.id_category = ' . _SHOP_CATEGORY_ROOT_ . ' AND ps.id_sale = psc.id_sale)
|
|
JOIN `' . _DB_PREFIX_ . 'category_lang` cl
|
|
ON (cl.id_category = psc.id_category AND cl.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'image` i
|
|
ON (i.id_product = p.id_product AND i.cover = 1)
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_delay_sale` pds
|
|
ON (pds.id_sale = ps.id_sale AND pds.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_delay_lang` pdl
|
|
ON (pdl.id_delay = pds.id_delay AND pdl.id_lang = ' . $language->id . ')
|
|
LEFT JOIN `' . _DB_PREFIX_ . 'product_corner_lang` pcl
|
|
ON (pcl.id_product = p.id_product AND pcl.id_lang = ' . $language->id . ')
|
|
WHERE ps.date_start < NOW() /*maybe a larger scope could be required here*/
|
|
AND ps.date_end > NOW()
|
|
AND ps.enabled = TRUE
|
|
AND p.available_for_order = 1
|
|
AND p.active = 1
|
|
AND pssv.version = \'' . $language->iso_code . '\'
|
|
LIMIT 20000';
|
|
$this->products = Db::getInstance()->ExecuteQ($sql);
|
|
}
|
|
}
|
|
|
|
private function hydrateProductStock()
|
|
{
|
|
$productIdArray = array();
|
|
$productIdArrayResult = array();
|
|
foreach ($this->products as $currentProduct) {
|
|
$productIdArray[] = $currentProduct['id_product'];
|
|
}
|
|
$sql = 'SELECT p.`id_product`, IF(COUNT(id_product_attribute), SUM(pa.`quantity`), p.`quantity`) AS total
|
|
FROM `' . _DB_PREFIX_ . 'product` p
|
|
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` AS pa ON pa.`id_product` = p.`id_product`
|
|
WHERE p.`id_product` IN (' . implode(',', $productIdArray) . ')
|
|
GROUP BY p.`id_product`';
|
|
unset($productIdArray);
|
|
$results = Db::getInstance()->ExecuteS($sql);
|
|
if ($results) {
|
|
foreach ($results as $result) {
|
|
$productIdArrayResult[(int)$result['id_product']] = $result['total'];
|
|
}
|
|
}
|
|
$iMax = count($this->products);
|
|
for ($i = 0; $i < $iMax; $i++) {
|
|
if ($productIdArrayResult[(int)$this->products[$i]['id_product']] > 0) {
|
|
$this->products[$i]['available'] = self::IN_STOCK_STRING;
|
|
} else {
|
|
$this->products[$i]['available'] = self::OUT_OF_STOCK_STRING;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function hydrateProductCategories($language)
|
|
{
|
|
$iMax = count($this->products);
|
|
for ($i = 0; $i < $iMax; $i++) {
|
|
$sql = '
|
|
SELECT cp.id_category, cl.name, c.level_depth, c.id_parent
|
|
FROM `' . _DB_PREFIX_ . 'category_product` cp
|
|
JOIN `' . _DB_PREFIX_ . 'category_lang` cl
|
|
ON (cl.id_category = cp.id_category AND cl.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'category` c
|
|
ON c.id_category = cl.id_category
|
|
WHERE cp.id_product = ' . $this->products[$i]['id_product'] . '
|
|
ORDER BY cp.id_category';
|
|
$categories = Db::getInstance()->ExecuteQ($sql);
|
|
$tmpArray = array();
|
|
$this->products[$i]['classic_categories'] = array();
|
|
$this->products[$i]['categories_id'] = array();
|
|
foreach ($categories as $currentEnrichingCategory) {
|
|
$id = (int)$currentEnrichingCategory['id_category'];
|
|
$tmpArray[$id] = $currentEnrichingCategory;
|
|
$this->products[$i]['classic_categories'][(int)$currentEnrichingCategory['level_depth']] = $currentEnrichingCategory['name'];
|
|
$this->products[$i]['categories_id'][(int)$currentEnrichingCategory['level_depth']] = $currentEnrichingCategory['id_category'];
|
|
}
|
|
$categoryTree = $this->parseTree($tmpArray, 1);
|
|
if (is_array($categoryTree)) {
|
|
$this->products[$i]['conso_categories'] = $this->displayAllPaths($categoryTree);
|
|
}
|
|
unset($tmpArray);
|
|
}
|
|
}
|
|
|
|
private function hydrateTagCategories($language)
|
|
{
|
|
$sql = '
|
|
SELECT psts.id_sale,
|
|
ptl.value AS tag_name,
|
|
pstl.value AS sub_tag_name
|
|
FROM `' . _DB_PREFIX_ . 'privatesale_sub_tag_sale` psts
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_sub_tag` pst
|
|
ON pst.id_sub_tag = psts.id_sub_tag
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_tag_lang` ptl
|
|
ON (pst.id_tag_parent = ptl.id_tag AND ptl.id_lang = ' . $language->id . ')
|
|
JOIN `' . _DB_PREFIX_ . 'privatesale_sub_tag_lang` pstl
|
|
ON (psts.id_sub_tag = pstl.id_sub_tag AND pstl.id_lang = ' . $language->id . ')
|
|
WHERE 1';
|
|
$saleTags = Db::getInstance()->ExecuteQ($sql);
|
|
$tmpArray = array();
|
|
foreach ($saleTags as $saleTag) {
|
|
if (!isset($tmpArray[(int)$saleTag['id_sale']])) {
|
|
$tmpArray[(int)$saleTag['id_sale']] = array();
|
|
}
|
|
$tmpArray[(int)$saleTag['id_sale']][] = $saleTag['tag_name'] . ' > ' . $saleTag['sub_tag_name'];
|
|
}
|
|
$iMax = count($this->products);
|
|
for ($i = 0; $i < $iMax; $i++) {
|
|
if (array_key_exists($this->products[$i]['id_sale'], $tmpArray)) {
|
|
$this->products[$i]['tags'] = $tmpArray[(int)$this->products[$i]['id_sale']];
|
|
}
|
|
}
|
|
unset($tmpArray);
|
|
}
|
|
|
|
private function hydrateProductBrands()
|
|
{
|
|
$sql = '
|
|
SELECT m.name, m.id_manufacturer
|
|
FROM `' . _DB_PREFIX_ . 'manufacturer` m
|
|
WHERE m.`active` = 1';
|
|
$brands = Db::getInstance()->ExecuteQ($sql);
|
|
$tmpArray = array();
|
|
foreach ($brands as $brand) {
|
|
$tmpArray[(int)$brand['id_manufacturer']] = $brand['name'];
|
|
}
|
|
$iMax = count($this->products);
|
|
for ($i = 0; $i < $iMax; $i++) {
|
|
if (isset($this->products[$i]['id_manufacturer'])
|
|
&& (int)$this->products[$i]['id_manufacturer'] !== 0) {
|
|
if(array_key_exists((int)$this->products[$i]['id_manufacturer'],$tmpArray)){
|
|
$this->products[$i]['brand'] = $tmpArray[(int)$this->products[$i]['id_manufacturer']];
|
|
} else {
|
|
$this->products[$i]['brand'] = self::GENERIC_BRAND;
|
|
}
|
|
}
|
|
}
|
|
unset($tmpArray);
|
|
}
|
|
|
|
private function hydrateProductFamily($language)
|
|
{
|
|
//$familyTree = $this->getFamilyTree($language->id);
|
|
$familyFlat = $this->getFamilyAll($language->id);
|
|
// Get all family tree
|
|
$iMax = count($this->products);
|
|
for ($i = 0; $i < $iMax; $i++) {
|
|
$this->products[$i]['family'] = 'Not found';
|
|
if (count($this->products[$i]['categories_id']) > 0) {
|
|
// Family
|
|
$categoryR = array_reverse($this->products[$i]['categories_id']);
|
|
foreach($categoryR as $c) {
|
|
$sql = "SELECT id_category_family FROM `"._DB_PREFIX_."category_family_association`
|
|
WHERE id_category = ".$c;
|
|
$id_category_family = Db::getInstance()->getValue($sql);
|
|
if (!empty($id_category_family)) {
|
|
break;
|
|
}
|
|
}
|
|
if (!empty($id_category_family) && array_key_exists($id_category_family, $familyFlat)) {
|
|
$get = $this->parseForParent($id_category_family, $familyFlat);
|
|
if ($get !== false) {
|
|
$familyPath = $get;
|
|
}
|
|
$this->products[$i]['family'] = $familyPath;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private function parseForParent($id_category_family, $family)
|
|
{
|
|
$name = '';
|
|
|
|
if (!array_key_exists($id_category_family, $family)) {
|
|
return false;
|
|
}
|
|
|
|
$name = $family[$id_category_family]['name'];
|
|
$id_category_family = $family[$id_category_family]['id_parent'];
|
|
|
|
if ($id_category_family == 0) {
|
|
return $name;
|
|
}
|
|
|
|
$get = $this->parseForParent($id_category_family, $family);
|
|
if ($get !== false) {
|
|
$name = $get.' > '.$name;
|
|
}
|
|
|
|
return $name;
|
|
}
|
|
|
|
private function getFamilyAll($id_lang)
|
|
{
|
|
$sql = "SELECT cf.`id_category_family`, cf.`id_parent`, cf.`position`, cfl.`name`
|
|
FROM `"._DB_PREFIX_."category_family` cf, `"._DB_PREFIX_."category_family_lang` cfl
|
|
WHERE cf.id_category_family=cfl.id_category_family AND cfl.id_lang=".$id_lang;
|
|
$result = Db::getInstance()->ExecuteS($sql);
|
|
$family = array();
|
|
if (count($result)) {
|
|
foreach ($result as $r) {
|
|
$family[$r['id_category_family']] = $r;
|
|
}
|
|
}
|
|
|
|
return $family;
|
|
}
|
|
|
|
private function getFamilyTree($id_lang)
|
|
{
|
|
return $this->recurseFamily(0, $id_lang);
|
|
}
|
|
|
|
private function recurseFamily($id_family, $id_lang)
|
|
{
|
|
$data = array();
|
|
$sql = "SELECT *
|
|
FROM `"._DB_PREFIX_."category_family` cf, `"._DB_PREFIX_."category_family_lang` cfl
|
|
WHERE cf.id_category_family=cfl.id_category_family AND cfl.id_lang=".$id_lang.
|
|
" AND cf.id_parent=".$id_family." ORDER BY cf.position ASC";
|
|
$result = Db::getInstance()->ExecuteS($sql);
|
|
if (count($result) > 0) {
|
|
foreach ($result as $c) {
|
|
$item = array(
|
|
'id_category_family' => $c['id_category_family'],
|
|
'name' => $c['name'],
|
|
'children' => $this->recurseFamily($c['id_category_family'], $id_lang),
|
|
);
|
|
$data[] = $item;
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
private function buildXML($language)
|
|
{
|
|
$this->buildXMLHeader($language);
|
|
$this->generateProductXML($language);
|
|
$this->buildXMLFooter();
|
|
|
|
return $this->xml;
|
|
}
|
|
|
|
private function generateProductXML($language)
|
|
{
|
|
$link = new Link();
|
|
$counter = 1;
|
|
$maxCounter = count($this->products);
|
|
$corner_list = array(
|
|
0 => $this->module->l('Aucun corner', 'sensefuelfluxexport', $language->id),
|
|
1 => $this->module->l('nouveauté', 'sensefuelfluxexport', $language->id),
|
|
2 => $this->module->l('destockage', 'sensefuelfluxexport', $language->id),
|
|
3 => $this->module->l('prix choc', 'sensefuelfluxexport', $language->id),
|
|
4 => $this->module->l('soldes', 'sensefuelfluxexport', $language->id),
|
|
);
|
|
|
|
foreach ($this->products as $currentProduct) {
|
|
echo 'Treating product ' . $counter . ' / ' . $maxCounter . "\n";
|
|
$counter++;
|
|
$this->initContent();
|
|
$this->content .= "<item>\n";
|
|
$this->addContentLine($currentProduct['id_product'], 'g:id');
|
|
$this->addContentLine($currentProduct['name'], 'g:title');
|
|
$this->addContentLine($this->applyDescriptionCleanup($currentProduct['description']), 'g:description', true);
|
|
$this->addContentLine(
|
|
$this->createProductUrl(
|
|
(int)$currentProduct['id_product'],
|
|
$currentProduct['link_rewrite'],
|
|
$currentProduct['cat_link_rewrite'],
|
|
$currentProduct['ean13'],
|
|
$language)
|
|
, 'g:link');
|
|
$this->addContentLine(
|
|
$link->getImageLink($currentProduct['link_rewrite'],
|
|
$currentProduct['id_product'] . '-' . $currentProduct['id_image'],
|
|
'large',
|
|
false)
|
|
, 'g:image_link');
|
|
$this->addContentLine(
|
|
Tools::getCurrentUrlProtocolPrefix() . 'm.' . Environment::DOMAIN_NAME . '.' . Environment::getDomainForLangId($language->id, true) . '/' .
|
|
$currentProduct['id_product'] . '-' . $currentProduct['link_rewrite'] . '.html'
|
|
, 'g:mobile_link');
|
|
$this->addContentLine($currentProduct['available'], 'g:availability');
|
|
$sale = round(Product::getPriceStatic((int)$currentProduct['id_product'], true, null, 6, null, false, false), 2);
|
|
$this->addContentLine($sale, 'g:price');
|
|
$salePrice = round(Product::getPriceStatic((int)$currentProduct['id_product'], true, null, 6, null, false, true), 2);
|
|
if ($salePrice < $sale) {
|
|
$this->addContentLine($salePrice, 'g:sale_price');
|
|
}
|
|
if (isset($currentProduct['brand'])) {
|
|
$this->addContentLine($currentProduct['brand'], 'g:brand');
|
|
}
|
|
$this->addContentLine($currentProduct['ean13'], 'g:gtin');
|
|
$this->addContentLine($currentProduct['reference'], "g:mpn");
|
|
//$this->content .= "<g:size>" . "https://support.google.com/merchants/answer/6324492" . "</g:size>";
|
|
$this->addContentLine("new", 'g:condition');
|
|
//$this->addContentLine("no", 'g:adult');
|
|
//specifics for conso shop
|
|
if (self::isShopConsoProduct($currentProduct)) {
|
|
$this->addContentLine('Consommables', 'c:sale_type');
|
|
foreach ($currentProduct['conso_categories'] as $currentCategory) {
|
|
$this->addContentLine($currentCategory, 'g:product_type');
|
|
}
|
|
} else {
|
|
//classic products in sales
|
|
if (isset($currentProduct['classic_categories'])) {
|
|
// Bebeboutik : brand
|
|
$firstKey = key($currentProduct['classic_categories']);
|
|
if ($firstKey !== null) {
|
|
$this->addContentLine($currentProduct['classic_categories'][$firstKey], 'g:brand');
|
|
}
|
|
foreach ($currentProduct['classic_categories'] as $depth => $name) {
|
|
if ($depth > 1) {
|
|
$this->addContentLine($name, 'c:category' . ($depth - 2));
|
|
}
|
|
}
|
|
}
|
|
/*if (isset($currentProduct['tags'])) {
|
|
foreach ($currentProduct['tags'] as $product_type) {
|
|
$this->addContentLine($product_type . ' > ' . $currentProduct['catname'],
|
|
'g:product_type');
|
|
}
|
|
}*/
|
|
|
|
// Bebeboutik : Add Family as product_type
|
|
$this->addContentLine($currentProduct['family'], 'g:product_type');
|
|
|
|
// Bebeboutik : Force categories
|
|
/*if (isset($currentProduct['conso_categories'])) {
|
|
foreach ($currentProduct['conso_categories'] as $currentCategory) {
|
|
$this->addContentLine($currentCategory, 'g:product_type');
|
|
}
|
|
}*/
|
|
|
|
$this->addContentLine('Ventes privées', 'c:sale_type');
|
|
$this->addContentLine($currentProduct['catname'], 'c:private_sale_name');
|
|
}
|
|
|
|
$this->addContentLine(round((float)$currentProduct['ecotax'], 2), 'c:eco_tax');
|
|
$this->addContentLine($currentProduct['date_start'], 'c:private_sale_start');
|
|
$this->addContentLine($currentProduct['date_end'], 'c:private_sale_end');
|
|
$this->addContentLine($currentProduct['delay'], 'c:shipping_delay');
|
|
if (array_key_exists((int)$currentProduct['id_corner'], $corner_list) &&
|
|
(int)$currentProduct['id_corner'] > 0) {
|
|
$this->addContentLine($corner_list[(int)$currentProduct['id_corner']], 'g:custom_label_0');
|
|
}
|
|
$this->addContentLine('', 'c:shipping_cost');
|
|
|
|
$this->content .= "</item>\n";
|
|
$this->xml .= $this->content;
|
|
}
|
|
}
|
|
|
|
private function initContent()
|
|
{
|
|
$this->content = '';
|
|
}
|
|
|
|
private function createProductUrl($idProduct, $linkRewrite, $category, $ean13, $language)
|
|
{
|
|
|
|
$link = Tools::getCurrentUrlProtocolPrefix() . 'www.' . Environment::DOMAIN_NAME . '.' . Environment::getDomainForLangId($language->id, true) . '/';
|
|
if ($category && $category !== 'home') {
|
|
$link .= $category . '/';
|
|
} else {
|
|
$link .= '';
|
|
}
|
|
|
|
$link .= (int)$idProduct . '-' . $linkRewrite;
|
|
|
|
if ($ean13) {
|
|
$link .= '-' . $ean13;
|
|
}
|
|
|
|
$link .= '.html';
|
|
|
|
return $link;
|
|
}
|
|
|
|
private function addContentLine($value, $tagName, $addCData = false)
|
|
{
|
|
if (isset($value) && $value !== '') {
|
|
$this->content .= '<' . $tagName . '>' . self::convertWrongChars($value) . '</' . $tagName . '>';
|
|
if (self::ADD_LINE_BREAKS_IN_XML) {
|
|
$this->content .= "\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
private function buildXMLHeader($language)
|
|
{
|
|
$meta = Meta::getMetaByPage('index', (int)($language->id));
|
|
$content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
|
'<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0">' . "\n\n" .
|
|
'<channel>' . "\n" .
|
|
'<title><![CDATA[' . stripslashes(Configuration::get('PS_SHOP_NAME')) . ']]></title>' . "\n" .
|
|
'<description><![CDATA[' . stripslashes($meta['description']) . ']]></description>' . "\n" .
|
|
'<link>' . Tools::getProtocol() . Tools::getShopDomain() . '</link>' . "\n\n";
|
|
$this->xml .= $content;
|
|
|
|
return $content;
|
|
}
|
|
|
|
private function buildXMLFooter()
|
|
{
|
|
$content = '</channel>' . "\n" .
|
|
'</rss>';
|
|
$this->xml .= $content;
|
|
|
|
return $content;
|
|
}
|
|
|
|
private function applyDescriptionCleanup($description)
|
|
{
|
|
return trim(preg_replace('!\s+!', ' ', preg_replace("/\r|\n/", ' ', strip_tags($description))));
|
|
}
|
|
|
|
private function parseTree($categoryArray, $root = null)
|
|
{
|
|
$return = array();
|
|
# Traverse the tree and search for direct children of the root
|
|
foreach ($categoryArray as $id => $item) {
|
|
# A direct child is found
|
|
if ((int)$item['id_parent'] === (int)$root) {
|
|
# Remove item from tree (we don't need to traverse this again)
|
|
unset($categoryArray[$id]);
|
|
# Append the child into result array and parse its children
|
|
$return[] = array(
|
|
'name' => $item['name'],
|
|
'children' => $this->parseTree($categoryArray, $item['id_category'])
|
|
);
|
|
}
|
|
}
|
|
|
|
return empty($return) ? null : $return;
|
|
}
|
|
|
|
private function displayAllPaths($categoryArray, $currentPath = null)
|
|
{
|
|
$return = array();
|
|
foreach ($categoryArray as $category) {
|
|
if ($category['children'] !== null) {
|
|
if ($currentPath === null) {
|
|
$currentPath = array();
|
|
}
|
|
$currentPath[] = $category['name'];
|
|
$return = array_merge($return, $this->displayAllPaths($category['children'], $currentPath));
|
|
} else {
|
|
if ($currentPath !== null && is_array($currentPath)) {
|
|
$return[] = implode(' > ', $currentPath) . ' > ' . $category['name'];
|
|
} else {
|
|
$return[] = $category['name'];
|
|
}
|
|
}
|
|
}
|
|
|
|
return empty($return) ? null : $return;
|
|
}
|
|
|
|
public static function getFilePath($language, $type)
|
|
{
|
|
$path = _PS_MODULE_DIR_ .
|
|
'sensefuel' . self::EXPORT_SUB_DIR;
|
|
if ($type === self::SALE_TYPE_GLOBAL) {
|
|
$path .= self::EXPORT_FILENAME . $language . self::EXPORT_EXTENSION;
|
|
} elseif ($type === self::SALE_TYPE_CONSO) {
|
|
$path .= self::EXPORT_FILENAME_CONSOMMABLE . $language . self::EXPORT_EXTENSION;
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
} |