Merge branch 'ticket-14698-sensefuel' into develop
This commit is contained in:
commit
be2fff2665
@ -164,3 +164,6 @@ if (!defined('_SHOP_CATEGORYENABLED'))
|
||||
define('_SHOP_CATEGORYENABLED', 1);
|
||||
if (!defined('_SHOP_PRIVATESALES_CONSUMABLE'))
|
||||
define('_SHOP_PRIVATESALES_CONSUMABLE', 5158);
|
||||
if (!defined('_SHOP_CATEGORY_ROOT_')) {
|
||||
define('_SHOP_CATEGORY_ROOT_', 8720307);
|
||||
}
|
3
modules/sensefuel/README.md
Normal file
3
modules/sensefuel/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
https://support.google.com/merchants/answer/7052112?hl=en
|
31
modules/sensefuel/export/download.php
Normal file
31
modules/sensefuel/export/download.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
include __DIR__ . '/../../../config/settings.inc.php';
|
||||
include __DIR__ . '/../../../config/config.inc.php';
|
||||
include __DIR__ . '/../sensefuel.php';
|
||||
|
||||
// {DOMAIN}/module/sensefuel/download.php?language=(fr,es)[&conso_only=1]
|
||||
|
||||
if (Tools::getValue('language')) {
|
||||
if (Tools::getValue('conso_only') && (int)Tools::getValue('conso_only') === 1) {
|
||||
$type = SenseFuelFluxExport::SALE_TYPE_CONSO;
|
||||
} else {
|
||||
$type = SenseFuelFluxExport::SALE_TYPE_GLOBAL;
|
||||
}
|
||||
$language = Tools::getValue('language');
|
||||
|
||||
$file = SenseFuelFluxExport::getFilePath($language, $type);
|
||||
|
||||
if (file_exists($file)) {
|
||||
$fp = fopen($file, 'rb');
|
||||
header('Content-Type: text/xml');
|
||||
header('Content-Disposition: attachment; filename=xml_data_' . $type . '_' .$language . '.xml');
|
||||
header('Content-Length: ' . filesize($file));
|
||||
fpassthru($fp);
|
||||
} else {
|
||||
echo 'false';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
36
modules/sensefuel/export/index.php
Normal file
36
modules/sensefuel/export/index.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7233 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
36
modules/sensefuel/index.php
Normal file
36
modules/sensefuel/index.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7233 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
11
modules/sensefuel/it.php
Normal file
11
modules/sensefuel/it.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['*_9af50f05441f3f608861ce2766c9ce7d'] = 'Cercare una marca, un prodotto';
|
||||
$_MODULE['*_3a8a7a8a2dbbd97c1c1519c74198112d'] = 'Cercare';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_578a0b756115fca8ed7b36423bf498eb'] = 'Aucun corner';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_ebcb38322e19ddd14dd47e3be1e4d96e'] = 'Nuovo';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_483687f76734feab12ff9691a63d5f46'] = 'Destocking';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_fc13d6b9aa0fb46eaf249a7cf2acc229'] = 'Prezzo shock';
|
||||
|
BIN
modules/sensefuel/logo.gif
Normal file
BIN
modules/sensefuel/logo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 266 B |
535
modules/sensefuel/models/SenseFuelFluxExport.php
Normal file
535
modules/sensefuel/models/SenseFuelFluxExport.php
Normal file
@ -0,0 +1,535 @@
|
||||
<?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 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`,
|
||||
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`,
|
||||
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();
|
||||
foreach ($categories as $currentEnrichingCategory) {
|
||||
$id = (int)$currentEnrichingCategory['id_category'];
|
||||
$tmpArray[$id] = $currentEnrichingCategory;
|
||||
$this->products[$i]['classic_categories'][(int)$currentEnrichingCategory['level_depth']] = $currentEnrichingCategory['name'];
|
||||
}
|
||||
$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 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'])) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
11
modules/sensefuel/pt.php
Normal file
11
modules/sensefuel/pt.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['*_9af50f05441f3f608861ce2766c9ce7d'] = 'Pesquisar uma marca, um produto';
|
||||
$_MODULE['*_3a8a7a8a2dbbd97c1c1519c74198112d'] = 'Pesquisar';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_578a0b756115fca8ed7b36423bf498eb'] = 'Aucun corner';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_ebcb38322e19ddd14dd47e3be1e4d96e'] = 'Nouveauté';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_483687f76734feab12ff9691a63d5f46'] = 'Destockage';
|
||||
$_MODULE['<{sensefuel}prestashop>sensefuelfluxexport_fc13d6b9aa0fb46eaf249a7cf2acc229'] = 'Prix Choc';
|
||||
|
36
modules/sensefuel/scripts/index.php
Normal file
36
modules/sensefuel/scripts/index.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7233 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
30
modules/sensefuel/scripts/sensefuelcron.php
Normal file
30
modules/sensefuel/scripts/sensefuelcron.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['HTTP_PORT'] = 443;
|
||||
$_SERVER['HTTP_X_FORWARDED_PORT'] = 443;
|
||||
|
||||
$_SERVER['SERVER_PORT'] = 443;
|
||||
|
||||
global $protocol_content;
|
||||
include __DIR__ . '/../../../config/settings.inc.php';
|
||||
include __DIR__ . '/../../../config/config.inc.php';
|
||||
|
||||
if(!Tools::isCli()){
|
||||
exit();
|
||||
}
|
||||
|
||||
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
||||
|
||||
$protocol_content = Tools::getProtocol();
|
||||
|
||||
include __DIR__ . '/../sensefuel.php';
|
||||
|
||||
$module_instance = new sensefuel();
|
||||
|
||||
if ($module_instance->active) {
|
||||
$senseFuelFluxExport = new SenseFuelFluxExport($module_instance);
|
||||
$senseFuelFluxExport->writeXml();
|
||||
}
|
106
modules/sensefuel/sensefuel.php
Normal file
106
modules/sensefuel/sensefuel.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
include_once _PS_MODULE_DIR_ . 'sensefuel/models/SenseFuelFluxExport.php';
|
||||
|
||||
class SenseFuel extends Module
|
||||
{
|
||||
|
||||
public static $ACTIVE_VERSION_ARRAY = array('fr', 'com', 'es', 'it');
|
||||
public static $SETUP_VERSION_ARRAY = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'sensefuel';
|
||||
$this->tab = 'shipping_logistics';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Create Sensefuel flux');
|
||||
$this->description = $this->l('Allows the creation of a google shopping flux for indexing motor sensefuel');
|
||||
|
||||
$this->version = '1.0';
|
||||
$this->author = 'Antadis';
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install()
|
||||
|| !$this->registerHook('footer')
|
||||
|| !$this->registerHook('top')
|
||||
|| !$this->registerHook('subtop')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hookTop($params)
|
||||
{
|
||||
if(_PS_MOBILE_){
|
||||
return false;
|
||||
}
|
||||
global $site_version, $page_name;
|
||||
if (null !== $site_version &&
|
||||
null !== $page_name &&
|
||||
in_array($site_version, self::$ACTIVE_VERSION_ARRAY, true) &&
|
||||
in_array($page_name, array('index', 'category', 'product'), true)
|
||||
) {
|
||||
return self::display(__FILE__, 'views/top-sensefuel.tpl');
|
||||
}
|
||||
|
||||
if (null !== $site_version &&
|
||||
null !== $page_name &&
|
||||
in_array($site_version, self::$SETUP_VERSION_ARRAY, true) &&
|
||||
in_array($page_name, array('index', 'category', 'product'), true) &&
|
||||
Tools::isConnectedToBackOffice()
|
||||
) {
|
||||
return self::display(__FILE__, 'views/top-sensefuel.tpl');
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function hookSubTop($params)
|
||||
{
|
||||
if(!_PS_MOBILE_){
|
||||
return false;
|
||||
}
|
||||
global $site_version, $page_name;
|
||||
if (null !== $site_version &&
|
||||
null !== $page_name &&
|
||||
in_array($site_version, self::$ACTIVE_VERSION_ARRAY , true) &&
|
||||
in_array($page_name, array('index', 'category', 'product'), true)
|
||||
) {
|
||||
return self::display(__FILE__, 'views/top-sensefuel.tpl');
|
||||
}
|
||||
|
||||
if (null !== $site_version &&
|
||||
null !== $page_name &&
|
||||
in_array($site_version, self::$SETUP_VERSION_ARRAY , true) &&
|
||||
in_array($page_name, array('index', 'category', 'product'), true) &&
|
||||
Tools::isConnectedToBackOffice()
|
||||
) {
|
||||
return self::display(__FILE__, 'views/top-sensefuel.tpl');
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function hookFooter($params)
|
||||
{
|
||||
global $site_version, $smarty;
|
||||
if (null !== $site_version &&
|
||||
( in_array($site_version, self::$ACTIVE_VERSION_ARRAY, true)
|
||||
|| in_array($site_version, self::$SETUP_VERSION_ARRAY, true))) {
|
||||
$smarty->assign(array('sensefuelversion' => $site_version));
|
||||
return self::display(__FILE__, 'views/footer.tpl');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
20
modules/sensefuel/views/footer.tpl
Normal file
20
modules/sensefuel/views/footer.tpl
Normal file
@ -0,0 +1,20 @@
|
||||
{if isset($sensefuelversion)}
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
(function () {
|
||||
var sf = document.createElement('script');
|
||||
sf.type = 'text/javascript';
|
||||
{/literal}
|
||||
{if $sensefuelversion == 'com' OR $sensefuelversion == 'fr'}
|
||||
{literal}sf.src = "https://tag.search.sensefuel.com/tag/bab23365-19ed-4d52-b99e-7a1fc1788a29/tag.js";{/literal}
|
||||
{elseif $sensefuelversion == 'es'}
|
||||
{literal}sf.src = "https://tag.search.sensefuel.com/tag/0bed0f6f-0ee4-48f0-b857-ce10d0462381/tagp.js";{/literal}
|
||||
{elseif $sensefuelversion == 'it'}
|
||||
{literal}sf.src = "https://tag.search.sensefuel.com/tag/c778abdd-1066-4344-b4e9-76601a55f02a/tagp.js";{/literal}
|
||||
{/if}
|
||||
{literal}
|
||||
document.body.appendChild(sf);
|
||||
})();
|
||||
</script>
|
||||
{/literal}
|
||||
{/if}
|
19
modules/sensefuel/views/top-sensefuel.tpl
Normal file
19
modules/sensefuel/views/top-sensefuel.tpl
Normal file
@ -0,0 +1,19 @@
|
||||
{if null !== $cookie && $cookie->isLogged()}
|
||||
<div id="sensefuel">
|
||||
<form action="{$base_dir_ssl}search.php" id="search" role="search">
|
||||
<div class="search">
|
||||
<div class="search_form">
|
||||
<input id="global_search" class="search_input" type="text" placeholder="{l s='Rechercher une marque, un produit' mod='sensefuel'}">
|
||||
<a title="{l s='Rechercher' mod='sensefuel'}" class="search_submit" href="#"><span class="picto"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<style>
|
||||
|
||||
#category #shop_category .shop_category_filter.horizontal .search {
|
||||
display: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
{/if}
|
211
override/classes/Environment.php
Normal file
211
override/classes/Environment.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
class Environment
|
||||
{
|
||||
const PRODUCTION = 'production';
|
||||
const DEV = 'development';
|
||||
const BACKOFFICE = 'backoffice';
|
||||
const UNDEFINED = 'unknown';
|
||||
const DOMAIN_NAME = 'bebeboutik';
|
||||
const DEFAULT_SUB_DOMAIN = 'www';
|
||||
const DEFAULT_VERSION = 'com';
|
||||
|
||||
private $envt;
|
||||
private $subDomain;
|
||||
private $topLevelDomain;
|
||||
private $version;
|
||||
private $iso_lang;
|
||||
|
||||
private static $paymentSubDomain = array(
|
||||
self::DEV => 'pp',
|
||||
self::PRODUCTION => 'payment',
|
||||
self::BACKOFFICE => 'payment',
|
||||
);
|
||||
|
||||
private static $subDomains = array(
|
||||
self::DEV => array(
|
||||
'local',
|
||||
'm.local',
|
||||
'pp',
|
||||
'm.pp',
|
||||
'292567.srv',
|
||||
'dev',
|
||||
'api.pp'
|
||||
),
|
||||
self::PRODUCTION => array(
|
||||
'payment',
|
||||
'www',
|
||||
'm',
|
||||
'api',
|
||||
),
|
||||
self::BACKOFFICE => array(
|
||||
'bo',
|
||||
'bo2',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getIsoLang()
|
||||
{
|
||||
return $this->iso_lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isProduction()
|
||||
{
|
||||
return $this->envt === Environment::PRODUCTION || $this->envt === Environment::BACKOFFICE ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBackOffice()
|
||||
{
|
||||
return $this->envt === Environment::BACKOFFICE ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDev()
|
||||
{
|
||||
return $this->envt === Environment::DEV;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUnknown()
|
||||
{
|
||||
return $this->envt === Environment::UNDEFINED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
if (!$this->version) {
|
||||
$this->topLevelDomain = self::DEFAULT_VERSION;
|
||||
$this->qualifyExtension();
|
||||
}
|
||||
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* In this case backoffice is never returned and considered as production
|
||||
* Use isBackOffice() to make the distinction
|
||||
* @return string Environment name in full string
|
||||
*/
|
||||
public function getEnvironmentName()
|
||||
{
|
||||
if ($this->envt === self::BACKOFFICE) {
|
||||
return self::PRODUCTION;
|
||||
}
|
||||
return $this->envt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getSubDomain()
|
||||
{
|
||||
return $this->subDomain;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$domain = Tools::getHttpHost();
|
||||
|
||||
if (substr_count($domain, '.')) {
|
||||
$this->subDomain = substr($domain, 0, strpos($domain, '.' . self::DOMAIN_NAME));
|
||||
$this->topLevelDomain = substr($domain, strpos($domain, self::DOMAIN_NAME) + strlen(self::DOMAIN_NAME) + 1);
|
||||
|
||||
$this->qualifySubDomain();
|
||||
|
||||
$this->qualifyExtension();
|
||||
|
||||
$this->qualifyLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default domain
|
||||
* @return string default domain
|
||||
*/
|
||||
public function getDefaultDomain()
|
||||
{
|
||||
return Tools::getCurrentUrlProtocolPrefix() . self::DEFAULT_SUB_DOMAIN . '.' . self::DOMAIN_NAME . '.' . $this->getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get domain for lang ID
|
||||
* @param int $id_lang Lang ID
|
||||
* @param bool $extension_only return domain extension only
|
||||
* @return string
|
||||
*/
|
||||
public static function getDomainForLangId($id_lang, $extension_only = false)
|
||||
{
|
||||
$returnedValue = '';
|
||||
if (!$extension_only) {
|
||||
$returnedValue .= Tools::getCurrentUrlProtocolPrefix() . 'www.' . self::DOMAIN_NAME . '.' ;
|
||||
}
|
||||
switch ($id_lang) {
|
||||
case 2:
|
||||
default:
|
||||
$returnedValue.= 'com';
|
||||
break;
|
||||
case 3:
|
||||
$returnedValue.= 'es';
|
||||
break;
|
||||
}
|
||||
return $returnedValue;
|
||||
}
|
||||
|
||||
|
||||
private function qualifySubDomain()
|
||||
{
|
||||
$productionSubDomainArray = self::$subDomains[self::PRODUCTION];
|
||||
$backOfficeSubDomainArray = self::$subDomains[self::BACKOFFICE];
|
||||
$developmentSubDomainArray = self::$subDomains[self::DEV];
|
||||
|
||||
if (in_array($this->subDomain, $productionSubDomainArray, true)) {
|
||||
$this->envt = Environment::PRODUCTION;
|
||||
} elseif (in_array($this->subDomain, $backOfficeSubDomainArray, true)) {
|
||||
$this->envt = Environment::BACKOFFICE;
|
||||
} elseif (in_array($this->subDomain, $developmentSubDomainArray, true)) {
|
||||
$this->envt = Environment::DEV;
|
||||
} else {
|
||||
$this->envt = Environment::UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
private function qualifyExtension()
|
||||
{
|
||||
return $this->version = Tools::getIsoVersion($this->topLevelDomain);
|
||||
}
|
||||
|
||||
private function qualifyLanguage()
|
||||
{
|
||||
$this->iso_lang = Tools::getVersionIso($this->topLevelDomain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment domain url
|
||||
* @return string payment domain url
|
||||
*/
|
||||
public function getPaymentDomain($http = false)
|
||||
{
|
||||
$url = '';
|
||||
if ($http) {
|
||||
$url = Tools::getCurrentUrlProtocolPrefix();
|
||||
}
|
||||
$sub_domain = self::$paymentSubDomain[$this->envt];
|
||||
return $url . $sub_domain . '.' . self::DOMAIN_NAME . '.' . self::DEFAULT_VERSION;
|
||||
}
|
||||
}
|
@ -6,6 +6,48 @@ class MySQL extends MySQLCore
|
||||
const REDIS_CONTROLLER_KEY_MAX_LENGTH = 16;
|
||||
const DEFAULT_SLICE_QUERY_STEP = 1000;
|
||||
|
||||
/*
|
||||
* Simpler version of MySQL::ExecuteS that always returns
|
||||
* an array even if there is an error, so it doesn't raise
|
||||
* a notice when used directly in a foreach.
|
||||
*/
|
||||
public function ExecuteQ($query, $use_cache = FALSE, $controller = FALSE, $cache_expire = null)
|
||||
{
|
||||
$this->_result = FALSE;
|
||||
$this->_lastQuery = $query;
|
||||
if ($controller) {
|
||||
$controller = strtoupper(substr($controller, 0, self::REDIS_CONTROLLER_KEY_MAX_LENGTH));
|
||||
}
|
||||
if ($use_cache && $controller && class_exists('CacheRedis')) {
|
||||
if (FALSE !== ($result = CacheRedis::getInstance()->getQuery($query, $controller))) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
if ($this->_link && $this->_result = mysql_query($query, $this->_link)) {
|
||||
$this->_lastCached = FALSE;
|
||||
if (_PS_DEBUG_SQL_) {
|
||||
$this->displayMySQLError($query);
|
||||
}
|
||||
$resultArray = array();
|
||||
// Only SELECT queries and a few others return a valid resource usable with mysql_fetch_assoc
|
||||
if ($this->_result !== TRUE) {
|
||||
while ($row = mysql_fetch_assoc($this->_result)) {
|
||||
$resultArray[] = $row;
|
||||
}
|
||||
}
|
||||
if ($use_cache && $controller && class_exists('CacheRedis')) {
|
||||
CacheRedis::getInstance()->setQuery($query, $controller, $resultArray, $cache_expire);
|
||||
}
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
if (_PS_DEBUG_SQL_) {
|
||||
$this->displayMySQLError($query);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* ExecuteS return the result of $query as array,
|
||||
* or as mysqli_result if $array set to FALSE
|
||||
|
@ -138,4 +138,9 @@ class Tools extends ToolsCore {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isCli()
|
||||
{
|
||||
return (PHP_SAPI === 'cli');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user