Intégration sensefuel

This commit is contained in:
Michael RICOIS 2017-11-15 17:31:44 +01:00
parent 5e678c403a
commit 98f7319989
6 changed files with 277 additions and 12 deletions

View File

@ -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);
}

View File

@ -4,6 +4,8 @@ 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;

View File

@ -2,7 +2,6 @@
class SenseFuelFluxExport
{
const ADD_LINE_BREAKS_IN_XML = true;
const SENSEFUEL_MAX_CAT_DEPTH = 4;
const IN_STOCK_STRING = 'in stock';
@ -20,7 +19,7 @@ class SenseFuelFluxExport
private $content;
public static $enabledLanguageArray = array(2, 3, 5);
public static $enabledLanguageArray = array(2, 3);
public function __construct($module)
{
@ -67,7 +66,7 @@ class SenseFuelFluxExport
$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),
//self::SALE_TYPE_CONSO => self::getFilePath($language->iso_code, self::SALE_TYPE_CONSO),
);
foreach ($files as $type => $currentFile) {
if (file_exists($currentFile)) {
@ -115,7 +114,8 @@ class SenseFuelFluxExport
ps.`date_start`,
ps.`date_end`,
pdl.`name` AS `delay`,
pcl.id_corner
/*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 . ')
@ -129,12 +129,12 @@ class SenseFuelFluxExport
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_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 . ')
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
@ -245,7 +245,9 @@ class SenseFuelFluxExport
$this->products[$i]['classic_categories'][(int)$currentEnrichingCategory['level_depth']] = $currentEnrichingCategory['name'];
}
$categoryTree = $this->parseTree($tmpArray, 1);
$this->products[$i]['conso_categories'] = $this->displayAllPaths($categoryTree);
if (is_array($categoryTree)) {
$this->products[$i]['conso_categories'] = $this->displayAllPaths($categoryTree);
}
unset($tmpArray);
}
}
@ -320,7 +322,7 @@ class SenseFuelFluxExport
private function generateProductXML($language)
{
$link = new Link();
$counter = 0;
$counter = 1;
$maxCounter = count($this->products);
$corner_list = array(
0 => $this->module->l('Aucun corner', 'sensefuelfluxexport', $language->id),
@ -353,7 +355,7 @@ class SenseFuelFluxExport
false)
, 'g:image_link');
$this->addContentLine(
Tools::getCurrentUrlProtocolPrefix() . 'm.' . Environment::DOMAIN_NAME . '.' . Environment::getDomainForLangId($language->id, true) . '/' .
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');

View 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;
}
}

View File

@ -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

View File

@ -138,4 +138,9 @@ class Tools extends ToolsCore {
return false;
}
public static function isCli()
{
return (PHP_SAPI === 'cli');
}
}