// Context in modules + Shop::sql* methods
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7648 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -59,12 +59,11 @@ class AdminReferrers extends AdminTab
|
|||||||
$this->edit = true;
|
$this->edit = true;
|
||||||
$this->delete = true;
|
$this->delete = true;
|
||||||
|
|
||||||
$this->_select = 'SUM(rs.cache_visitors) AS cache_visitors, SUM(rs.cache_visits) AS cache_visits, SUM(rs.cache_pages) AS cache_pages,
|
$this->_select = 'SUM(sa.cache_visitors) AS cache_visitors, SUM(sa.cache_visits) AS cache_visits, SUM(sa.cache_pages) AS cache_pages,
|
||||||
SUM(rs.cache_registrations) AS cache_registrations, SUM(rs.cache_orders) AS cache_orders, SUM(rs.cache_sales) AS cache_sales,
|
SUM(sa.cache_registrations) AS cache_registrations, SUM(sa.cache_orders) AS cache_orders, SUM(sa.cache_sales) AS cache_sales,
|
||||||
IF(rs.cache_orders > 0, ROUND(rs.cache_sales/rs.cache_orders, 2), 0) as cart, (rs.cache_visits*click_fee) as fee0,
|
IF(sa.cache_orders > 0, ROUND(sa.cache_sales/sa.cache_orders, 2), 0) as cart, (sa.cache_visits*click_fee) as fee0,
|
||||||
(rs.cache_orders*base_fee) as fee1, (rs.cache_sales*percent_fee/100) as fee2';
|
(sa.cache_orders*base_fee) as fee1, (sa.cache_sales*percent_fee/100) as fee2';
|
||||||
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON a.id_referrer = rs.id_referrer '.Shop::sqlRestriction(false, 'rs');
|
$this->_group = 'GROUP BY sa.id_referrer';
|
||||||
$this->_group = 'GROUP BY rs.id_referrer';
|
|
||||||
$this->fieldsDisplay = array(
|
$this->fieldsDisplay = array(
|
||||||
'id_referrer' => array('title' => $this->l('ID'), 'width' => 25, 'align' => 'center'),
|
'id_referrer' => array('title' => $this->l('ID'), 'width' => 25, 'align' => 'center'),
|
||||||
'name' => array('title' => $this->l('Name'), 'width' => 80),
|
'name' => array('title' => $this->l('Name'), 'width' => 80),
|
||||||
|
|||||||
+14
-17
@@ -1171,29 +1171,26 @@ abstract class AdminTabCore
|
|||||||
$whereShop = Shop::sqlRestriction($this->shopShareDatas, 'a', null, null, $this->shopLinkType);
|
$whereShop = Shop::sqlRestriction($this->shopShareDatas, 'a', null, null, $this->shopLinkType);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filterShop = '';
|
$assos = Shop::getAssoTables();
|
||||||
if (Context::shop() != Shop::CONTEXT_ALL)
|
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
|
||||||
{
|
{
|
||||||
$assos = Shop::getAssoTables();
|
$filterKey = $assos[$this->table]['type'];
|
||||||
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
|
$idenfierShop = Shop::getListFromContext();
|
||||||
|
}
|
||||||
|
else if (Context::shop() == Shop::CONTEXT_GROUP)
|
||||||
|
{
|
||||||
|
$assos = GroupShop::getAssoTables();
|
||||||
|
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop')
|
||||||
{
|
{
|
||||||
$filterKey = $assos[$this->table]['type'];
|
$filterKey = $assos[$this->table]['type'];
|
||||||
$idenfierShop = Shop::getListFromContext();
|
$idenfierShop = array($context->shop->getGroupID());
|
||||||
}
|
}
|
||||||
else if (Context::shop() == Shop::CONTEXT_GROUP)
|
|
||||||
{
|
|
||||||
$assos = GroupShop::getAssoTables();
|
|
||||||
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop')
|
|
||||||
{
|
|
||||||
$filterKey = $assos[$this->table]['type'];
|
|
||||||
$idenfierShop = array($context->shop->getGroupID());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($filterKey))
|
|
||||||
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filterShop = '';
|
||||||
|
if (isset($filterKey))
|
||||||
|
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))';
|
||||||
|
|
||||||
/* Query in order to get results with all fields */
|
/* Query in order to get results with all fields */
|
||||||
$sql = 'SELECT SQL_CALC_FOUND_ROWS
|
$sql = 'SELECT SQL_CALC_FOUND_ROWS
|
||||||
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
|
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ class CategoryCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
$sql = 'SELECT COUNT(cp.`id_product`) AS total
|
$sql = 'SELECT COUNT(cp.`id_product`) AS total
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
'.Shop::sqlAsso('product', 'p', $context).'
|
'.Shop::sqlAsso('product', 'p', true, $context).'
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`
|
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`
|
||||||
WHERE cp.`id_category` = '.(int)($this->id).
|
WHERE cp.`id_category` = '.(int)($this->id).
|
||||||
($active ? ' AND p.`active` = 1' : '').
|
($active ? ' AND p.`active` = 1' : '').
|
||||||
@@ -506,7 +506,7 @@ class CategoryCore extends ObjectModel
|
|||||||
FROM `'._DB_PREFIX_.'category_product` cp
|
FROM `'._DB_PREFIX_.'category_product` cp
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
|
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
|
||||||
'.Shop::sqlAsso('product', 'p', $context).'
|
'.Shop::sqlAsso('product', 'p', true, $context).'
|
||||||
'.Product::sqlStock('p', 'pa', false, $context).'
|
'.Product::sqlStock('p', 'pa', false, $context).'
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('cl', $context).')
|
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('cl', $context).')
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('pl', $context).')
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('pl', $context).')
|
||||||
|
|||||||
+10
-31
@@ -91,23 +91,18 @@ abstract class ModuleCore
|
|||||||
*/
|
*/
|
||||||
public static $classInModule = array();
|
public static $classInModule = array();
|
||||||
|
|
||||||
/** @var int */
|
/** @var Context */
|
||||||
protected $shopID;
|
protected $context;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $shopGroupID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string $name Module unique name
|
* @param string $name Module unique name
|
||||||
|
* @param Context $context
|
||||||
*/
|
*/
|
||||||
public function __construct($name = null)
|
public function __construct($name = null, Context $context = null)
|
||||||
{
|
{
|
||||||
// Search the module shop context
|
$this->context = ($context) ? $context : Context::getContext();
|
||||||
list($shopID, $shopGroupID) = Shop::getContext();
|
|
||||||
$this->setShopID($shopID);
|
|
||||||
$this->setShopGroupID($shopGroupID);
|
|
||||||
|
|
||||||
if ($this->name == NULL)
|
if ($this->name == NULL)
|
||||||
$this->name = $this->id;
|
$this->name = $this->id;
|
||||||
@@ -115,7 +110,7 @@ abstract class ModuleCore
|
|||||||
{
|
{
|
||||||
if (self::$modulesCache == NULL AND !is_array(self::$modulesCache))
|
if (self::$modulesCache == NULL AND !is_array(self::$modulesCache))
|
||||||
{
|
{
|
||||||
$list = Shop::getListOfID($this->shopID, $this->shopGroupID);
|
$list = Shop::getListOfID($this->context);
|
||||||
|
|
||||||
// Join clause is done to check if the module is activated in current shop context
|
// Join clause is done to check if the module is activated in current shop context
|
||||||
$sql = 'SELECT m.id_module, m.name, (
|
$sql = 'SELECT m.id_module, m.name, (
|
||||||
@@ -143,25 +138,9 @@ abstract class ModuleCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id Set shopID property
|
|
||||||
*/
|
|
||||||
public function setShopID($id)
|
|
||||||
{
|
|
||||||
$this->shopID = (int)$id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id Set shopGroupID property
|
|
||||||
*/
|
|
||||||
public function setShopGroupID($id)
|
|
||||||
{
|
|
||||||
$this->shopGroupID = (int)$id;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function sqlShopRestriction($share = false, $alias = null)
|
protected function sqlShopRestriction($share = false, $alias = null)
|
||||||
{
|
{
|
||||||
return Shop::sqlRestriction($share, $alias, $this->shopID, $this->shopGroupID, 'shop');
|
return Shop::sqlRestriction($share, $alias, $this->context, 'shop');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,7 +219,7 @@ abstract class ModuleCore
|
|||||||
*/
|
*/
|
||||||
public function enable($forceAll = false)
|
public function enable($forceAll = false)
|
||||||
{
|
{
|
||||||
$list = Shop::getListOfID($this->shopID, $this->shopGroupID);
|
$list = Shop::getListOfID($this->context);
|
||||||
$sql = 'SELECT id_shop
|
$sql = 'SELECT id_shop
|
||||||
FROM '._DB_PREFIX_.'module_shop
|
FROM '._DB_PREFIX_.'module_shop
|
||||||
WHERE id_module = '.$this->id.'
|
WHERE id_module = '.$this->id.'
|
||||||
@@ -288,7 +267,7 @@ abstract class ModuleCore
|
|||||||
{
|
{
|
||||||
$sql = 'DELETE FROM '._DB_PREFIX_.'module_shop
|
$sql = 'DELETE FROM '._DB_PREFIX_.'module_shop
|
||||||
WHERE id_module = '.$this->id.'
|
WHERE id_module = '.$this->id.'
|
||||||
'.((!$forceAll) ? ' AND id_shop IN('.implode(', ', Shop::getListOfID($this->shopID, $this->shopGroupID)).')' : '');
|
'.((!$forceAll) ? ' AND id_shop IN('.implode(', ', Shop::getListOfID($this->context)).')' : '');
|
||||||
Db::getInstance()->execute($sql);
|
Db::getInstance()->execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,7 +895,7 @@ abstract class ModuleCore
|
|||||||
*/
|
*/
|
||||||
public function updatePosition($id_hook, $way, $position = NULL)
|
public function updatePosition($id_hook, $way, $position = NULL)
|
||||||
{
|
{
|
||||||
$list = ShopCore::getListOfID($this->shopID, $this->shopGroupID);
|
$list = ShopCore::getListOfID($this->context);
|
||||||
foreach ($list as $shopID)
|
foreach ($list as $shopID)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT hm.`id_module`, hm.`position`, hm.`id_hook`
|
$sql = 'SELECT hm.`id_module`, hm.`position`, hm.`id_hook`
|
||||||
|
|||||||
+2
-2
@@ -1517,7 +1517,7 @@ class ProductCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
$sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb
|
$sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
'.Shop::sqlAsso('product', 'p', $context).'
|
'.Shop::sqlAsso('product', 'p', true, $context).'
|
||||||
WHERE p.`active` = 1
|
WHERE p.`active` = 1
|
||||||
AND p.`show_price` = 1
|
AND p.`show_price` = 1
|
||||||
'.((!$beginning AND !$ending) ? ' AND p.`id_product` IN('.((is_array($ids_product) AND sizeof($ids_product)) ? implode(', ', $ids_product) : 0).')' : '').'
|
'.((!$beginning AND !$ending) ? ' AND p.`id_product` IN('.((is_array($ids_product) AND sizeof($ids_product)) ? implode(', ', $ids_product) : 0).')' : '').'
|
||||||
@@ -1535,7 +1535,7 @@ class ProductCore extends ObjectModel
|
|||||||
pl.`name`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name,
|
pl.`name`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name,
|
||||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
'.Shop::sqlAsso('product', 'p', $context).'
|
'.Shop::sqlAsso('product', 'p', true, $context).'
|
||||||
'.Product::sqlStock('p', 0, false, $context).'
|
'.Product::sqlStock('p', 0, false, $context).'
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('pl', $context).')
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('pl', $context).')
|
||||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||||
|
|||||||
+21
-16
@@ -449,8 +449,11 @@ class ShopCore extends ObjectModel
|
|||||||
* @param bool $share If true and if $shopID is set, list shops with share data too
|
* @param bool $share If true and if $shopID is set, list shops with share data too
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getListOfID($shopID, $shopGroupID, $share = false)
|
public static function getListOfID(Context $context, $share = false)
|
||||||
{
|
{
|
||||||
|
$shopID = $context->shop->getID();
|
||||||
|
$shopGroupID = $context->shop->getGroupID();
|
||||||
|
|
||||||
if ($shopID)
|
if ($shopID)
|
||||||
$list = (!$share) ? array($shopID) : Shop::getSharedShops($shopID);
|
$list = (!$share) ? array($shopID) : Shop::getSharedShops($shopID);
|
||||||
else if ($shopGroupID)
|
else if ($shopGroupID)
|
||||||
@@ -531,14 +534,11 @@ class ShopCore extends ObjectModel
|
|||||||
/**
|
/**
|
||||||
* Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID)
|
* Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID)
|
||||||
*
|
*
|
||||||
* @param Context $context
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getListFromContext(Context $context = null)
|
public static function getListFromContext()
|
||||||
{
|
{
|
||||||
if (!$context)
|
return Shop::getListOfID(Context::getContext());
|
||||||
$context = Context::getContext();
|
|
||||||
return Shop::getListOfID($context->shop->getID(), $context->shop->getGroupID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -556,7 +556,7 @@ class ShopCore extends ObjectModel
|
|||||||
return Shop::CONTEXT_ALL;
|
return Shop::CONTEXT_ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function sqlRestriction($share = false, $alias = null, $shopID = null, $shopGroupID = null, $type = 'shop')
|
public static function sqlRestriction($share = false, $alias = null, Context $context = null, $type = 'shop')
|
||||||
{
|
{
|
||||||
if ($type != 'shop' && $type != 'group_shop')
|
if ($type != 'shop' && $type != 'group_shop')
|
||||||
$type = 'shop';
|
$type = 'shop';
|
||||||
@@ -565,10 +565,10 @@ class ShopCore extends ObjectModel
|
|||||||
$alias .= '.';
|
$alias .= '.';
|
||||||
|
|
||||||
$restriction = '';
|
$restriction = '';
|
||||||
if (is_null($shopID))
|
if (!$context)
|
||||||
$shopID = Shop::getContext('shop');
|
$context = Context::getContext();
|
||||||
if (is_null($shopGroupID))
|
$shopID = $context->shop->getID();
|
||||||
$shopGroupID = Shop::getContext('group');
|
$shopGroupID = $context->shop->getGroupID();
|
||||||
|
|
||||||
if ($type == 'group_shop')
|
if ($type == 'group_shop')
|
||||||
{
|
{
|
||||||
@@ -580,7 +580,7 @@ class ShopCore extends ObjectModel
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($shopID || $shopGroupID)
|
if ($shopID || $shopGroupID)
|
||||||
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', Shop::getListOfID($shopID, $shopGroupID, $share)).')';
|
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', Shop::getListOfID($context, $share)).')';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $restriction;
|
return $restriction;
|
||||||
@@ -610,21 +610,26 @@ class ShopCore extends ObjectModel
|
|||||||
*
|
*
|
||||||
* @param string $table Table name (E.g. product, module, etc.)
|
* @param string $table Table name (E.g. product, module, etc.)
|
||||||
* @param string $alias Alias of table
|
* @param string $alias Alias of table
|
||||||
|
* @param bool $innerJoin Use or not INNER JOIN
|
||||||
* @param Context $context
|
* @param Context $context
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function sqlAsso($table, $alias, Context $context = null)
|
public static function sqlAsso($table, $alias, $innerJoin = false, Context $context = null)
|
||||||
{
|
{
|
||||||
if (!$context)
|
if (!$context)
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
|
|
||||||
|
$tableAlias = ' asso_shop_'.$table;
|
||||||
|
if (strpos($table, '.') !== false)
|
||||||
|
list($tableAlias, $table) = explode('.', $table);
|
||||||
|
|
||||||
$assoTables = Shop::getAssoTables();
|
$assoTables = Shop::getAssoTables();
|
||||||
if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop')
|
if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop')
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
$sql = ' LEFT JOIN '._DB_PREFIX_.$table.'_shop asso_shop_'.$table.'
|
$sql = (($innerJoin) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$tableAlias.'
|
||||||
ON asso_shop_'.$table.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
ON '.$tableAlias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
||||||
AND asso_shop_'.$table.'.id_shop IN('.implode(', ', Shop::getListFromContext($context)).') ';
|
AND '.$tableAlias.'.id_shop IN('.implode(', ', Shop::getListFromContext($context)).') ';
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,15 +124,13 @@ class BlockCategories extends Module
|
|||||||
|
|
||||||
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
|
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
|
||||||
|
|
||||||
$children = array();
|
$children = array();
|
||||||
if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
|
if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
|
||||||
foreach ($resultParents[$id_category] as $subcat)
|
foreach ($resultParents[$id_category] as $subcat)
|
||||||
$children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
|
$children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
|
||||||
if (!isset($resultIds[$id_category]))
|
if (!isset($resultIds[$id_category]))
|
||||||
return false;
|
return false;
|
||||||
$return = array('id' => $id_category, 'link' => $context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
|
$return = array('id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']),
|
||||||
'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
|
'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'],
|
||||||
'children' => $children);
|
'children' => $children);
|
||||||
return $return;
|
return $return;
|
||||||
@@ -141,7 +139,7 @@ class BlockCategories extends Module
|
|||||||
public function hookLeftColumn($params)
|
public function hookLeftColumn($params)
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
$id_current_shop = $this->shopID;
|
$id_current_shop = $context->shop->getID();
|
||||||
|
|
||||||
$id_customer = (int)($params['cookie']->id_customer);
|
$id_customer = (int)($params['cookie']->id_customer);
|
||||||
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
|
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
|
||||||
@@ -220,8 +218,8 @@ class BlockCategories extends Module
|
|||||||
|
|
||||||
public function hookFooter($params)
|
public function hookFooter($params)
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
$context = $this->context;
|
||||||
$id_current_shop = $this->shopID;
|
$id_current_shop = $context->shop->getID();
|
||||||
|
|
||||||
$id_customer = (int)($params['cookie']->id_customer);
|
$id_customer = (int)($params['cookie']->id_customer);
|
||||||
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
|
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
|
||||||
@@ -321,9 +319,8 @@ class BlockCategories extends Module
|
|||||||
|
|
||||||
public function hookHeader()
|
public function hookHeader()
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
$this->context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js');
|
||||||
$context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js');
|
$this->context->controller->addCSS(($this->_path).'blockcategories.css', 'all');
|
||||||
$context->controller->addCSS(($this->_path).'blockcategories.css', 'all');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _clearBlockcategoriesCache()
|
private function _clearBlockcategoriesCache()
|
||||||
|
|||||||
@@ -60,13 +60,10 @@ class BlockCurrencies extends Module
|
|||||||
if (Configuration::get('PS_CATALOG_MODE'))
|
if (Configuration::get('PS_CATALOG_MODE'))
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
$context = Context::getContext();
|
$currencies = Currency::getCurrencies(false, 1, $this->context->shop->getID());
|
||||||
|
|
||||||
$id_current_shop = $this->shopID;
|
|
||||||
$currencies = Currency::getCurrencies(false, 1, $id_current_shop);
|
|
||||||
if (!sizeof($currencies))
|
if (!sizeof($currencies))
|
||||||
return '';
|
return '';
|
||||||
$context->controller->smarty->assign('currencies', $currencies);
|
$this->context->controller->smarty->assign('currencies', $currencies);
|
||||||
return $this->display(__FILE__, 'blockcurrencies.tpl');
|
return $this->display(__FILE__, 'blockcurrencies.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +71,7 @@ class BlockCurrencies extends Module
|
|||||||
{
|
{
|
||||||
if (Configuration::get('PS_CATALOG_MODE'))
|
if (Configuration::get('PS_CATALOG_MODE'))
|
||||||
return ;
|
return ;
|
||||||
$context = Context::getContext();
|
$this->context->controller->addCSS(($this->_path).'blockcurrencies.css', 'all');
|
||||||
$context->controller->addCSS(($this->_path).'blockcurrencies.css', 'all');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,19 +57,16 @@ class BlockLanguages extends Module
|
|||||||
*/
|
*/
|
||||||
function hookTop($params)
|
function hookTop($params)
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
$languages = Language::getLanguages(true, $this->context->shop->getID());
|
||||||
|
|
||||||
$languages = Language::getLanguages(true, $this->shopID);
|
|
||||||
if (!sizeof($languages))
|
if (!sizeof($languages))
|
||||||
return '';
|
return '';
|
||||||
$context->controller->smarty->assign('languages', $languages);
|
$this->context->controller->smarty->assign('languages', $languages);
|
||||||
return $this->display(__FILE__, 'blocklanguages.tpl');
|
return $this->display(__FILE__, 'blocklanguages.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
function hookHeader($params)
|
function hookHeader($params)
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
$this->context->controller->addCSS(($this->_path).'blocklanguages.css', 'all');
|
||||||
$context->controller->addCSS(($this->_path).'blocklanguages.css', 'all');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ class BlockLayered extends Module
|
|||||||
p.ean13, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, p.condition, p.id_manufacturer, stock.quantity,
|
p.ean13, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, p.condition, p.id_manufacturer, stock.quantity,
|
||||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
||||||
FROM '._DB_PREFIX_.'product p
|
FROM '._DB_PREFIX_.'product p
|
||||||
'.Shop::sqlAsso('product', 'p', $context).'
|
'.Shop::sqlAsso('product', 'p', true, $context).'
|
||||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::sqlLang('pl', $context).')
|
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::sqlLang('pl', $context).')
|
||||||
'.Product::sqlStock('p', 0).'
|
'.Product::sqlStock('p', 0).'
|
||||||
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product AND i.cover = 1)
|
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product AND i.cover = 1)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class BlockManufacturer extends Module
|
|||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
//$getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_shop = false
|
//$getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_shop = false
|
||||||
$context->controller->smarty->assign(array(
|
$context->controller->smarty->assign(array(
|
||||||
'manufacturers' => Manufacturer::getManufacturers(false, 0, true, false, false, false, $this->shopGroupID),
|
'manufacturers' => Manufacturer::getManufacturers(false, 0, true, false, false, false, $this->context->shop->getGroupID()),
|
||||||
'link' => $context->link,
|
'link' => $context->link,
|
||||||
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
|
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
|
||||||
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
|
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
|
||||||
|
|||||||
@@ -140,13 +140,13 @@ class Blocknewsletter extends Module
|
|||||||
{
|
{
|
||||||
$sql = 'SELECT `email` FROM '._DB_PREFIX_.'newsletter
|
$sql = 'SELECT `email` FROM '._DB_PREFIX_.'newsletter
|
||||||
WHERE `email` = \''.pSQL($customerEmail).'\'
|
WHERE `email` = \''.pSQL($customerEmail).'\'
|
||||||
AND id_shop = '.$this->shopID;
|
AND id_shop = '.$this->context->shop->getID();
|
||||||
if (Db::getInstance()->getRow($sql))
|
if (Db::getInstance()->getRow($sql))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
$sql = 'SELECT `newsletter` FROM '._DB_PREFIX_.'customer
|
$sql = 'SELECT `newsletter` FROM '._DB_PREFIX_.'customer
|
||||||
WHERE `email` = \''.pSQL($customerEmail).'\'
|
WHERE `email` = \''.pSQL($customerEmail).'\'
|
||||||
AND id_shop = '.$this->shopID;
|
AND id_shop = '.$this->context->shop->getID();
|
||||||
if (!$registered = Db::getInstance()->getRow($sql))
|
if (!$registered = Db::getInstance()->getRow($sql))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -160,7 +160,6 @@ class Blocknewsletter extends Module
|
|||||||
*/
|
*/
|
||||||
private function newsletterRegistration()
|
private function newsletterRegistration()
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
|
||||||
if (empty($_POST['email']) OR !Validate::isEmail($_POST['email']))
|
if (empty($_POST['email']) OR !Validate::isEmail($_POST['email']))
|
||||||
return $this->error = $this->l('Invalid e-mail address');
|
return $this->error = $this->l('Invalid e-mail address');
|
||||||
|
|
||||||
@@ -173,14 +172,14 @@ class Blocknewsletter extends Module
|
|||||||
/* If the user ins't a customer */
|
/* If the user ins't a customer */
|
||||||
elseif ($registerStatus == 1)
|
elseif ($registerStatus == 1)
|
||||||
{
|
{
|
||||||
if (!Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->shopID))
|
if (!Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->context->shop->getID()))
|
||||||
return $this->error = $this->l('Error during unsubscription');
|
return $this->error = $this->l('Error during unsubscription');
|
||||||
return $this->valid = $this->l('Unsubscription successful');
|
return $this->valid = $this->l('Unsubscription successful');
|
||||||
}
|
}
|
||||||
/* If the user is a customer */
|
/* If the user is a customer */
|
||||||
elseif ($registerStatus == 2)
|
elseif ($registerStatus == 2)
|
||||||
{
|
{
|
||||||
if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 0 WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->shopID))
|
if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 0 WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->context->shop->getID()))
|
||||||
return $this->error = $this->l('Error during unsubscription');
|
return $this->error = $this->l('Error during unsubscription');
|
||||||
return $this->valid = $this->l('Unsubscription successful');
|
return $this->valid = $this->l('Unsubscription successful');
|
||||||
}
|
}
|
||||||
@@ -196,8 +195,8 @@ class Blocknewsletter extends Module
|
|||||||
elseif ($registerStatus == -1)
|
elseif ($registerStatus == -1)
|
||||||
{
|
{
|
||||||
$sql = 'INSERT INTO '._DB_PREFIX_.'newsletter (id_shop, id_group_shop, email, newsletter_date_add, ip_registration_newsletter, http_referer)
|
$sql = 'INSERT INTO '._DB_PREFIX_.'newsletter (id_shop, id_group_shop, email, newsletter_date_add, ip_registration_newsletter, http_referer)
|
||||||
VALUES ('.$this->shopID.', '.$this->shopGroupID.', \''.pSQL($_POST['email']).'\', NOW(), \''.pSQL(Tools::getRemoteAddr()).'\',
|
VALUES ('.$this->context->shop->getID().', '.$this->context->shop->getGroupID().', \''.pSQL($_POST['email']).'\', NOW(), \''.pSQL(Tools::getRemoteAddr()).'\',
|
||||||
(SELECT c.http_referer FROM '._DB_PREFIX_.'connections c WHERE c.id_guest = '.(int)$context->customer->id.' ORDER BY c.date_add DESC LIMIT 1)
|
(SELECT c.http_referer FROM '._DB_PREFIX_.'connections c WHERE c.id_guest = '.(int)$this->context->customer->id.' ORDER BY c.date_add DESC LIMIT 1)
|
||||||
)';
|
)';
|
||||||
if (!Db::getInstance()->Execute($sql))
|
if (!Db::getInstance()->Execute($sql))
|
||||||
return $this->error = $this->l('Error during subscription');
|
return $this->error = $this->l('Error during subscription');
|
||||||
@@ -211,7 +210,7 @@ class Blocknewsletter extends Module
|
|||||||
$sql = 'UPDATE '._DB_PREFIX_.'customer
|
$sql = 'UPDATE '._DB_PREFIX_.'customer
|
||||||
SET `newsletter` = 1, newsletter_date_add = NOW(), `ip_registration_newsletter` = \''.pSQL(Tools::getRemoteAddr()).'\'
|
SET `newsletter` = 1, newsletter_date_add = NOW(), `ip_registration_newsletter` = \''.pSQL(Tools::getRemoteAddr()).'\'
|
||||||
WHERE `email` = \''.pSQL($_POST['email']).'\'
|
WHERE `email` = \''.pSQL($_POST['email']).'\'
|
||||||
AND id_shop = '.$this->shopID;
|
AND id_shop = '.$this->context->shop->getID();
|
||||||
if (!Db::getInstance()->Execute($sql))
|
if (!Db::getInstance()->Execute($sql))
|
||||||
return $this->error = $this->l('Error during subscription');
|
return $this->error = $this->l('Error during subscription');
|
||||||
$this->sendVoucher(pSQL($_POST['email']));
|
$this->sendVoucher(pSQL($_POST['email']));
|
||||||
|
|||||||
@@ -86,10 +86,9 @@ class BlockSpecials extends Module
|
|||||||
if (Configuration::get('PS_CATALOG_MODE'))
|
if (Configuration::get('PS_CATALOG_MODE'))
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
$context = Context::getContext();
|
if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang), false, false, $this->context->shop->getID()) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
|
||||||
if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang), false, false, $this->shopID) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
|
|
||||||
return;
|
return;
|
||||||
$context->controller->smarty->assign(array(
|
$this->context->controller->smarty->assign(array(
|
||||||
'special' => $special,
|
'special' => $special,
|
||||||
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
|
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
|
||||||
'mediumSize' => Image::getSize('medium')
|
'mediumSize' => Image::getSize('medium')
|
||||||
@@ -107,8 +106,7 @@ class BlockSpecials extends Module
|
|||||||
{
|
{
|
||||||
if (Configuration::get('PS_CATALOG_MODE'))
|
if (Configuration::get('PS_CATALOG_MODE'))
|
||||||
return ;
|
return ;
|
||||||
$context = Context::getContext();
|
$this->context->controller->addCSS(($this->_path).'blockspecials.css', 'all');
|
||||||
$context->controller->addCSS(($this->_path).'blockspecials.css', 'all');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class Pagesnotfound extends Module
|
|||||||
{
|
{
|
||||||
$http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
|
$http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
|
||||||
if (empty($http_referer) OR Validate::isAbsoluteUrl($http_referer))
|
if (empty($http_referer) OR Validate::isAbsoluteUrl($http_referer))
|
||||||
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_group_shop`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->shopID.', '.$this->shopGroupID.')');
|
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_group_shop`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ class ReferralProgram extends Module
|
|||||||
if (!Validate::isLoadedObject($discount))
|
if (!Validate::isLoadedObject($discount))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ($params['cart']->checkDiscountValidity($discount, $params['cart']->getDiscounts(), $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), $params['cart']->getProducts(), false, $this->shopID, $this->shopGroupID)===false)
|
if ($params['cart']->checkDiscountValidity($discount, $params['cart']->getDiscounts(), $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), $params['cart']->getProducts(), false, $this->context->shop->getID(), $this->context->shop->getGroupID())===false)
|
||||||
{
|
{
|
||||||
global $smarty;
|
global $smarty;
|
||||||
$smarty->assign(array('discount_display' => Discount::display($discount->value, $discount->id_discount_type, new Currency($params['cookie']->id_currency)), 'discount' => $discount));
|
$smarty->assign(array('discount_display' => Discount::display($discount->value, $discount->id_discount_type, new Currency($params['cookie']->id_currency)), 'discount' => $discount));
|
||||||
@@ -438,7 +438,7 @@ class ReferralProgram extends Module
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
$sponsor = new Customer();
|
$sponsor = new Customer();
|
||||||
if ($sponsor = $sponsor->getByEmail($sponsorEmail, NULL, $this->shopGroupID, $this->shopID))
|
if ($sponsor = $sponsor->getByEmail($sponsorEmail, NULL, $this->context->shop->getGroupID(), $this->context->shop->getID()))
|
||||||
{
|
{
|
||||||
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
|
include_once(dirname(__FILE__).'/ReferralProgramModule.php');
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class SEKeywords extends ModuleGraph
|
|||||||
|
|
||||||
if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER']))
|
if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER']))
|
||||||
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'sekeyword` (`keyword`, `date_add`, `id_shop`, `id_group_shop`)
|
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'sekeyword` (`keyword`, `date_add`, `id_shop`, `id_group_shop`)
|
||||||
VALUES (\''.pSQL(Tools::strtolower(trim($keywords))).'\', NOW(), '.$this->shopID.', '.$this->shopGroupID.')');
|
VALUES (\''.pSQL(Tools::strtolower(trim($keywords))).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookAdminStatsModules()
|
public function hookAdminStatsModules()
|
||||||
|
|||||||
@@ -123,14 +123,14 @@ class StatsBestCategories extends ModuleGrid
|
|||||||
|
|
||||||
// If a shop is selected, get all children categories for the shop
|
// If a shop is selected, get all children categories for the shop
|
||||||
$categories = array();
|
$categories = array();
|
||||||
if ($this->shopID || $this->shopGroupID)
|
if ($this->context->shop->getContextType() != Shop::CONTEXT_ALL)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT c.nleft, c.nright
|
$sql = 'SELECT c.nleft, c.nright
|
||||||
FROM '._DB_PREFIX_.'category c
|
FROM '._DB_PREFIX_.'category c
|
||||||
WHERE c.id_category IN (
|
WHERE c.id_category IN (
|
||||||
SELECT s.id_category
|
SELECT s.id_category
|
||||||
FROM '._DB_PREFIX_.'shop s
|
FROM '._DB_PREFIX_.'shop s
|
||||||
WHERE s.id_shop IN ('.(($this->shopID) ? $this->shopID : 'SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID).')
|
WHERE s.id_shop IN ('.implode(', ', Shop::getListOfID($this->context)).')
|
||||||
)';
|
)';
|
||||||
if ($result = Db::getInstance()->executeS($sql))
|
if ($result = Db::getInstance()->executeS($sql))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -149,16 +149,6 @@ class StatsBestProducts extends ModuleGrid
|
|||||||
$dateBetween = $this->getDate();
|
$dateBetween = $this->getDate();
|
||||||
$arrayDateBetween = explode(' AND ', $dateBetween);
|
$arrayDateBetween = explode(' AND ', $dateBetween);
|
||||||
|
|
||||||
$joinShop = $whereShop = '';
|
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
$joinShop = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product ';
|
|
||||||
if ($this->shopID)
|
|
||||||
$whereShop = ' ps.id_shop = '.$this->shopID.' AND ';
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
$whereShop = 'ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.') AND';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name, ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold,
|
$this->_query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name, ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold,
|
||||||
IFNULL((SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product GROUP BY pa.id_product), p.quantity) as quantity,
|
IFNULL((SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product GROUP BY pa.id_product), p.quantity) as quantity,
|
||||||
IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold,
|
IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold,
|
||||||
@@ -174,12 +164,11 @@ class StatsBestProducts extends ModuleGrid
|
|||||||
AND dr.time_end BETWEEN '.$dateBetween.'
|
AND dr.time_end BETWEEN '.$dateBetween.'
|
||||||
) AS totalPageViewed
|
) AS totalPageViewed
|
||||||
FROM '._DB_PREFIX_.'product p
|
FROM '._DB_PREFIX_.'product p
|
||||||
'.$joinShop.'
|
'.Shop::sqlAsso('product', 'p', true, $this->context).'
|
||||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)($this->getLang()).')
|
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)($this->getLang()).')
|
||||||
LEFT JOIN '._DB_PREFIX_.'order_detail od ON od.product_id = p.id_product
|
LEFT JOIN '._DB_PREFIX_.'order_detail od ON od.product_id = p.id_product
|
||||||
LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order
|
LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order
|
||||||
WHERE '.$whereShop.'
|
WHERE p.active = 1
|
||||||
p.active = 1
|
|
||||||
AND o.valid = 1
|
AND o.valid = 1
|
||||||
AND o.invoice_date BETWEEN '.$dateBetween.'
|
AND o.invoice_date BETWEEN '.$dateBetween.'
|
||||||
GROUP BY od.product_id';
|
GROUP BY od.product_id';
|
||||||
|
|||||||
@@ -147,15 +147,7 @@ class StatsCatalog extends Module
|
|||||||
$this->_join = ' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)';
|
$this->_join = ' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)';
|
||||||
$this->_where = ' AND cp.`id_category` = '.$id_category;
|
$this->_where = ' AND cp.`id_category` = '.$id_category;
|
||||||
}
|
}
|
||||||
|
$this->_join .= Shop::sqlAsso('product', 'p', true, $this->context);
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
$this->_join .= ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product';
|
|
||||||
if ($this->shopID)
|
|
||||||
$this->_where .= ' AND ps.id_shop = ' . $this->shopID;
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
$this->_where .= ' AND ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')';
|
|
||||||
}
|
|
||||||
|
|
||||||
$result1 = $this->getQuery1(true);
|
$result1 = $this->getQuery1(true);
|
||||||
$total = $result1['total'];
|
$total = $result1['total'];
|
||||||
|
|||||||
@@ -76,17 +76,13 @@ class StatsCheckUp extends Module
|
|||||||
$employee = new Employee((int)($cookie->id_employee));
|
$employee = new Employee((int)($cookie->id_employee));
|
||||||
$prop30 = ((strtotime($employee->stats_date_to.' 23:59:59') - strtotime($employee->stats_date_from.' 00:00:00')) / 60 / 60 / 24) / 30;
|
$prop30 = ((strtotime($employee->stats_date_to.' 23:59:59') - strtotime($employee->stats_date_from.' 00:00:00')) / 60 / 60 / 24) / 30;
|
||||||
|
|
||||||
|
$shopID = $this->context->shop->getID();
|
||||||
|
$shopGroupID = $this->context->shop->getGroupID();
|
||||||
|
|
||||||
// Get languages
|
// Get languages
|
||||||
$sql = 'SELECT l.*
|
$sql = 'SELECT l.*
|
||||||
FROM '._DB_PREFIX_.'lang l';
|
FROM '._DB_PREFIX_.'lang l'
|
||||||
if ($this->shopID || $this->shopGroupID)
|
.Shop::sqlAsso('lang', 'l', true, $this->context);
|
||||||
{
|
|
||||||
$sql .= ' LEFT JOIN '._DB_PREFIX_.'lang_shop ls ON ls.id_lang = l.id_lang';
|
|
||||||
if ($this->shopID)
|
|
||||||
$sql .= ' WHERE ls.id_shop = ' . $this->shopID;
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
$sql .= ' WHERE ls.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')';
|
|
||||||
}
|
|
||||||
$languages = $db->ExecuteS($sql);
|
$languages = $db->ExecuteS($sql);
|
||||||
|
|
||||||
$arrayColors = array(
|
$arrayColors = array(
|
||||||
@@ -109,40 +105,19 @@ class StatsCheckUp extends Module
|
|||||||
elseif ($cookie->checkup_order == 3)
|
elseif ($cookie->checkup_order == 3)
|
||||||
$orderBy = 'nbSales DESC';
|
$orderBy = 'nbSales DESC';
|
||||||
|
|
||||||
// Generate SQL restrictions for products stats per shop
|
|
||||||
$joinProduct = $joinImage = $whereProduct = $whereImage = $whereOrder = '';
|
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
$joinProduct = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product ';
|
|
||||||
$joinImage = ' LEFT JOIN '._DB_PREFIX_.'image_shop ishop ON ishop.id_image = i.id_image ';
|
|
||||||
if ($this->shopID)
|
|
||||||
{
|
|
||||||
$whereProduct = ' WHERE ps.id_shop = '.$this->shopID;
|
|
||||||
$whereImage = ' AND ishop.id_shop = '.$this->shopID;
|
|
||||||
$whereOrder = ' AND o.id_shop = '.$this->shopID;
|
|
||||||
}
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
{
|
|
||||||
$whereProduct = ' WHERE ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')';
|
|
||||||
$whereImage = ' AND ishop.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')';
|
|
||||||
$whereOrder = ' AND o.id_group_shop = '.$this->shopGroupID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get products stats
|
// Get products stats
|
||||||
$sql = 'SELECT p.id_product, p.active, pl.name, (
|
$sql = 'SELECT p.id_product, p.active, pl.name, (
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM '._DB_PREFIX_.'image i
|
FROM '._DB_PREFIX_.'image i
|
||||||
'.$joinImage.'
|
'.Shop::sqlAsso('image', 'i', true, $this->context).'
|
||||||
WHERE i.id_product = p.id_product
|
WHERE i.id_product = p.id_product
|
||||||
'.$whereImage.'
|
|
||||||
) as nbImages, (
|
) as nbImages, (
|
||||||
SELECT SUM(od.product_quantity)
|
SELECT SUM(od.product_quantity)
|
||||||
FROM '._DB_PREFIX_.'orders o
|
FROM '._DB_PREFIX_.'orders o
|
||||||
LEFT JOIN '._DB_PREFIX_.'order_detail od ON o.id_order = od.id_order
|
LEFT JOIN '._DB_PREFIX_.'order_detail od ON o.id_order = od.id_order
|
||||||
WHERE od.product_id = p.id_product
|
WHERE od.product_id = p.id_product
|
||||||
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction().'
|
||||||
) as nbSales, IFNULL((
|
) as nbSales, IFNULL((
|
||||||
SELECT SUM(pa.quantity)
|
SELECT SUM(pa.quantity)
|
||||||
FROM '._DB_PREFIX_.'product_attribute pa
|
FROM '._DB_PREFIX_.'product_attribute pa
|
||||||
@@ -150,8 +125,7 @@ class StatsCheckUp extends Module
|
|||||||
), p.quantity) as stock
|
), p.quantity) as stock
|
||||||
FROM '._DB_PREFIX_.'product p
|
FROM '._DB_PREFIX_.'product p
|
||||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.')
|
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.')
|
||||||
'.$joinProduct.'
|
'.Shop::sqlAsso('product', 'p', true, $this->context).'
|
||||||
'.$whereProduct.'
|
|
||||||
ORDER BY '.$orderBy;
|
ORDER BY '.$orderBy;
|
||||||
$result = $db->ExecuteS($sql);
|
$result = $db->ExecuteS($sql);
|
||||||
|
|
||||||
|
|||||||
@@ -80,26 +80,6 @@ class StatsForecast extends Module
|
|||||||
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||||
$employee = new Employee((int)($cookie->id_employee));
|
$employee = new Employee((int)($cookie->id_employee));
|
||||||
|
|
||||||
// Prepare SQL clause to filter per shop
|
|
||||||
$whereOrder = $whereConnection = $whereCustomer = $whereCart = '';
|
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
if ($this->shopID)
|
|
||||||
{
|
|
||||||
$whereOrder = ' AND o.id_shop = '.$this->shopID;
|
|
||||||
$whereConnection = ' AND c.id_shop = '.$this->shopID;
|
|
||||||
$whereCustomer = ' AND id_shop = '.$this->shopID;
|
|
||||||
$whereCart = ' AND id_shop = '.$this->shopID;
|
|
||||||
}
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
{
|
|
||||||
$whereOrder = ' AND o.id_group_shop = '.$this->shopGroupID;
|
|
||||||
$whereConnection = ' AND c.id_group_shop = '.$this->shopGroupID;
|
|
||||||
$whereCustomer = ' AND id_group_shop = '.$this->shopGroupID;
|
|
||||||
$whereCart = ' AND id_group_shop = '.$this->shopGroupID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo use PHP functions to get timestamp ...
|
// @todo use PHP functions to get timestamp ...
|
||||||
$result = $db->getRow('SELECT UNIX_TIMESTAMP(\'2009-06-05 00:00:00\') as t1, UNIX_TIMESTAMP(\''.$employee->stats_date_from.' 00:00:00\') as t2');
|
$result = $db->getRow('SELECT UNIX_TIMESTAMP(\'2009-06-05 00:00:00\') as t1, UNIX_TIMESTAMP(\''.$employee->stats_date_from.' 00:00:00\') as t2');
|
||||||
$from = max($result['t1'], $result['t2']);
|
$from = max($result['t1'], $result['t2']);
|
||||||
@@ -141,7 +121,7 @@ class StatsForecast extends Module
|
|||||||
LEFT JOIN '._DB_PREFIX_.'product p ON od.product_id = p.id_product
|
LEFT JOIN '._DB_PREFIX_.'product p ON od.product_id = p.id_product
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY '.$dateFromGInvoice.'
|
GROUP BY '.$dateFromGInvoice.'
|
||||||
ORDER BY fix_date';
|
ORDER BY fix_date';
|
||||||
$result = $db->ExecuteS($sql, false);
|
$result = $db->ExecuteS($sql, false);
|
||||||
@@ -188,7 +168,7 @@ class StatsForecast extends Module
|
|||||||
$sql = 'SELECT '.$dateFromGAdd.' as fix_date, COUNT(*) as visits
|
$sql = 'SELECT '.$dateFromGAdd.' as fix_date, COUNT(*) as visits
|
||||||
FROM '._DB_PREFIX_.'connections c
|
FROM '._DB_PREFIX_.'connections c
|
||||||
WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween().'
|
WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereConnection.'
|
'.$this->sqlShopRestriction(false, 'c').'
|
||||||
GROUP BY '.$dateFromGAdd;
|
GROUP BY '.$dateFromGAdd;
|
||||||
$visits = Db::getInstance()->ExecuteS($sql, false);
|
$visits = Db::getInstance()->ExecuteS($sql, false);
|
||||||
while ($row = $db->nextRow($visits))
|
while ($row = $db->nextRow($visits))
|
||||||
@@ -201,7 +181,7 @@ class StatsForecast extends Module
|
|||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.total_paid_real > 0
|
AND o.total_paid_real > 0
|
||||||
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween()
|
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween()
|
||||||
.$whereOrder.'
|
.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY '.$dateFromGInvoice;
|
GROUP BY '.$dateFromGInvoice;
|
||||||
$discounts = Db::getInstance()->ExecuteS($sql, false);
|
$discounts = Db::getInstance()->ExecuteS($sql, false);
|
||||||
while ($row = $db->nextRow($discounts))
|
while ($row = $db->nextRow($discounts))
|
||||||
@@ -219,7 +199,7 @@ class StatsForecast extends Module
|
|||||||
$sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'customer
|
$sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'customer
|
||||||
WHERE date_add BETWEEN '.ModuleGraph::getDateBetween().'
|
WHERE date_add BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
AND date_add '.$dateFromGReg
|
AND date_add '.$dateFromGReg
|
||||||
.$whereCustomer;
|
.$this->sqlShopRestriction(true);
|
||||||
$row['registrations'] = Db::getInstance()->getValue($sql);
|
$row['registrations'] = Db::getInstance()->getValue($sql);
|
||||||
$totalHT = $row['totalProducts'] - $discountToday;
|
$totalHT = $row['totalProducts'] - $discountToday;
|
||||||
|
|
||||||
@@ -297,7 +277,7 @@ class StatsForecast extends Module
|
|||||||
$sql = 'SELECT COUNT(DISTINCT c.id_guest)
|
$sql = 'SELECT COUNT(DISTINCT c.id_guest)
|
||||||
FROM '._DB_PREFIX_.'connections c
|
FROM '._DB_PREFIX_.'connections c
|
||||||
WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
||||||
.$whereConnection;
|
.$this->sqlShopRestriction(false, 'c');
|
||||||
$visitors = Db::getInstance()->getValue($sql);
|
$visitors = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(DISTINCT id_customer)
|
$sql = 'SELECT COUNT(DISTINCT id_customer)
|
||||||
@@ -305,7 +285,7 @@ class StatsForecast extends Module
|
|||||||
INNER JOIN '._DB_PREFIX_.'guest g ON c.id_guest = g.id_guest
|
INNER JOIN '._DB_PREFIX_.'guest g ON c.id_guest = g.id_guest
|
||||||
WHERE c.id_customer != 0
|
WHERE c.id_customer != 0
|
||||||
AND c.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
AND c.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
||||||
.$whereConnection;
|
.$this->sqlShopRestriction(false, 'c');
|
||||||
$customers = Db::getInstance()->getValue($sql);
|
$customers = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*)
|
$sql = 'SELECT COUNT(*)
|
||||||
@@ -314,7 +294,7 @@ class StatsForecast extends Module
|
|||||||
SELECT id_cart FROM '._DB_PREFIX_.'cart_product
|
SELECT id_cart FROM '._DB_PREFIX_.'cart_product
|
||||||
) AND (
|
) AND (
|
||||||
date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().'
|
date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
)'.$whereCart;
|
)'.$this->sqlShopRestriction();
|
||||||
$carts = Db::getInstance()->getValue($sql);
|
$carts = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*)
|
$sql = 'SELECT COUNT(*)
|
||||||
@@ -324,14 +304,14 @@ class StatsForecast extends Module
|
|||||||
) AND id_address_invoice != 0
|
) AND id_address_invoice != 0
|
||||||
AND (
|
AND (
|
||||||
date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().'
|
date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
)'.$whereCart;
|
)'.$this->sqlShopRestriction();
|
||||||
$fullcarts = Db::getInstance()->getValue($sql);
|
$fullcarts = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*)
|
$sql = 'SELECT COUNT(*)
|
||||||
FROM '._DB_PREFIX_.'orders o
|
FROM '._DB_PREFIX_.'orders o
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
AND o.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
||||||
.$whereOrder;
|
.$this->sqlShopRestriction(false, 'o');
|
||||||
$orders = Db::getInstance()->getValue($sql);
|
$orders = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
$this->_html .= '<div class="clear"> </div>
|
$this->_html .= '<div class="clear"> </div>
|
||||||
@@ -508,23 +488,7 @@ class StatsForecast extends Module
|
|||||||
$employee = new Employee($cookie->id_employee);
|
$employee = new Employee($cookie->id_employee);
|
||||||
$ca = array();
|
$ca = array();
|
||||||
|
|
||||||
// Prepare SQL clause to filter per shop
|
$where = $join = '';
|
||||||
$whereOrder = $where = $join = $joinLang = $whereLang = '';
|
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
$joinLang = ' LEFT JOIN '._DB_PREFIX_.'lang_shop ls ON ls.id_lang = l.id_lang ';
|
|
||||||
if ($this->shopID)
|
|
||||||
{
|
|
||||||
$whereOrder = ' AND o.id_shop = '.$this->shopID;
|
|
||||||
$whereLang = ' AND ls.id_shop = '.$this->shopID;
|
|
||||||
}
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
{
|
|
||||||
$whereOrder = ' AND o.id_group_shop = '.$this->shopGroupID;
|
|
||||||
$whereLang = ' AND ls.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((int)$cookie->stats_id_zone)
|
if ((int)$cookie->stats_id_zone)
|
||||||
{
|
{
|
||||||
$join = ' LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_invoice = a.id_address LEFT JOIN `'._DB_PREFIX_.'country` co ON co.id_country = a.id_country';
|
$join = ' LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_invoice = a.id_address LEFT JOIN `'._DB_PREFIX_.'country` co ON co.id_country = a.id_country';
|
||||||
@@ -540,7 +504,7 @@ class StatsForecast extends Module
|
|||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$where.'
|
'.$where.'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY p.id_category_default';
|
GROUP BY p.id_category_default';
|
||||||
$ca['cat'] = Db::getInstance()->ExecuteS($sql);
|
$ca['cat'] = Db::getInstance()->ExecuteS($sql);
|
||||||
uasort($ca['cat'], 'statsforecast_sort');
|
uasort($ca['cat'], 'statsforecast_sort');
|
||||||
@@ -548,9 +512,8 @@ class StatsForecast extends Module
|
|||||||
$langValues = '';
|
$langValues = '';
|
||||||
$sql = 'SELECT l.id_lang, l.iso_code
|
$sql = 'SELECT l.id_lang, l.iso_code
|
||||||
FROM `'._DB_PREFIX_.'lang` l
|
FROM `'._DB_PREFIX_.'lang` l
|
||||||
'.$joinLang.'
|
'.Shop::sqlAsso('lang', 'l', true, $this->context).'
|
||||||
WHERE l.active = 1
|
WHERE l.active = 1';
|
||||||
'.$whereLang;
|
|
||||||
$languages = Db::getInstance()->ExecuteS($sql);
|
$languages = Db::getInstance()->ExecuteS($sql);
|
||||||
foreach ($languages as $language)
|
foreach ($languages as $language)
|
||||||
$langValues .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_products / o.conversion_rate, 0)) as '.pSQL($language['iso_code']).',';
|
$langValues .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_products / o.conversion_rate, 0)) as '.pSQL($language['iso_code']).',';
|
||||||
@@ -562,7 +525,7 @@ class StatsForecast extends Module
|
|||||||
FROM `'._DB_PREFIX_.'orders` o
|
FROM `'._DB_PREFIX_.'orders` o
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereOrder;
|
'.$this->sqlShopRestriction(false, 'o');
|
||||||
$ca['lang'] = Db::getInstance()->getRow($sql);
|
$ca['lang'] = Db::getInstance()->getRow($sql);
|
||||||
arsort($ca['lang']);
|
arsort($ca['lang']);
|
||||||
|
|
||||||
@@ -570,7 +533,7 @@ class StatsForecast extends Module
|
|||||||
FROM `'._DB_PREFIX_.'orders` o
|
FROM `'._DB_PREFIX_.'orders` o
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND ADDDATE(o.`invoice_date`, interval 30 day) BETWEEN \''.$employee->stats_date_from.' 00:00:00\' AND \''.min(date('Y-m-d H:i:s'), $employee->stats_date_to.' 23:59:59').'\'
|
AND ADDDATE(o.`invoice_date`, interval 30 day) BETWEEN \''.$employee->stats_date_from.' 00:00:00\' AND \''.min(date('Y-m-d H:i:s'), $employee->stats_date_to.' 23:59:59').'\'
|
||||||
'.$whereOrder;
|
'.$this->sqlShopRestriction(false, 'o');
|
||||||
$ca['langprev'] = Db::getInstance()->getRow($sql);
|
$ca['langprev'] = Db::getInstance()->getRow($sql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -585,7 +548,7 @@ class StatsForecast extends Module
|
|||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$where.'
|
'.$where.'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY o.module
|
GROUP BY o.module
|
||||||
ORDER BY total DESC';
|
ORDER BY total DESC';
|
||||||
$ca['payment'] = Db::getInstance()->ExecuteS($sql);
|
$ca['payment'] = Db::getInstance()->ExecuteS($sql);
|
||||||
@@ -597,7 +560,7 @@ class StatsForecast extends Module
|
|||||||
LEFT JOIN `'._DB_PREFIX_.'zone` z ON z.id_zone = c.id_zone
|
LEFT JOIN `'._DB_PREFIX_.'zone` z ON z.id_zone = c.id_zone
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY c.id_zone
|
GROUP BY c.id_zone
|
||||||
ORDER BY total DESC';
|
ORDER BY total DESC';
|
||||||
$ca['zones'] = Db::getInstance()->ExecuteS($sql);
|
$ca['zones'] = Db::getInstance()->ExecuteS($sql);
|
||||||
@@ -609,7 +572,7 @@ class StatsForecast extends Module
|
|||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$where.'
|
'.$where.'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY o.id_currency
|
GROUP BY o.id_currency
|
||||||
ORDER BY total DESC';
|
ORDER BY total DESC';
|
||||||
$ca['currencies'] = Db::getInstance()->ExecuteS($sql);
|
$ca['currencies'] = Db::getInstance()->ExecuteS($sql);
|
||||||
@@ -618,7 +581,7 @@ class StatsForecast extends Module
|
|||||||
FROM `'._DB_PREFIX_.'orders` o
|
FROM `'._DB_PREFIX_.'orders` o
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereOrder;
|
'.$this->sqlShopRestriction(false, 'o');
|
||||||
$ca['ventil'] = Db::getInstance()->getRow($sql);
|
$ca['ventil'] = Db::getInstance()->getRow($sql);
|
||||||
|
|
||||||
$sql = 'SELECT /*pac.id_attribute,*/ agl.name as gname, al.name as aname, COUNT(*) as total
|
$sql = 'SELECT /*pac.id_attribute,*/ agl.name as gname, al.name as aname, COUNT(*) as total
|
||||||
@@ -630,7 +593,7 @@ class StatsForecast extends Module
|
|||||||
INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (a.id_attribute = al.id_attribute AND al.id_lang = '.(int)($cookie->id_lang).')
|
INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (a.id_attribute = al.id_attribute AND al.id_lang = '.(int)($cookie->id_lang).')
|
||||||
WHERE o.valid = 1
|
WHERE o.valid = 1
|
||||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||||
'.$whereOrder.'
|
'.$this->sqlShopRestriction(false, 'o').'
|
||||||
GROUP BY pac.id_attribute';
|
GROUP BY pac.id_attribute';
|
||||||
$ca['attributes'] = Db::getInstance()->ExecuteS($sql);
|
$ca['attributes'] = Db::getInstance()->ExecuteS($sql);
|
||||||
|
|
||||||
|
|||||||
@@ -99,24 +99,13 @@ class StatsProduct extends ModuleGraph
|
|||||||
|
|
||||||
private function getProducts($id_lang)
|
private function getProducts($id_lang)
|
||||||
{
|
{
|
||||||
$joinShop = $whereShop = '';
|
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
$joinShop = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product ';
|
|
||||||
if ($this->shopID)
|
|
||||||
$whereShop = ' ps.id_shop = '.$this->shopID.' AND ';
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
$whereShop = 'ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.') AND';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = 'SELECT p.`id_product`, p.reference, pl.`name`, IFNULL(
|
$sql = 'SELECT p.`id_product`, p.reference, pl.`name`, IFNULL(
|
||||||
(SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product), p.quantity) as quantity
|
(SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product), p.quantity) as quantity
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product`
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product`
|
||||||
'.$joinShop.'
|
'.Shop::sqlAsso('product', 'p', true, $this->context).'
|
||||||
'.(Tools::getValue('id_category') ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`' : '').'
|
'.(Tools::getValue('id_category') ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`' : '').'
|
||||||
WHERE '.$whereShop.'
|
WHERE pl.`id_lang` = '.(int)($id_lang).'
|
||||||
pl.`id_lang` = '.(int)($id_lang).'
|
|
||||||
'.(Tools::getValue('id_category') ? 'AND cp.id_category = '.(int)(Tools::getValue('id_category')) : '').'
|
'.(Tools::getValue('id_category') ? 'AND cp.id_category = '.(int)(Tools::getValue('id_category')) : '').'
|
||||||
ORDER BY pl.`name`';
|
ORDER BY pl.`name`';
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class StatsSearch extends ModuleGraph
|
|||||||
function hookSearch($params)
|
function hookSearch($params)
|
||||||
{
|
{
|
||||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'statssearch` (`id_shop`, `id_group_shop`, `keywords`, `results`, `date_add`)
|
$sql = 'INSERT INTO `'._DB_PREFIX_.'statssearch` (`id_shop`, `id_group_shop`, `keywords`, `results`, `date_add`)
|
||||||
VALUES ('.$this->shopID.', '.$this->shopGroupID.', \''.pSQL($params['expr']).'\', '.(int)($params['total']).', NOW())';
|
VALUES ('.$this->context->shop->getID().', '.$this->context->shop->getGroupID().', \''.pSQL($params['expr']).'\', '.(int)($params['total']).', NOW())';
|
||||||
Db::getInstance()->Execute($sql);
|
Db::getInstance()->Execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,16 +60,6 @@ class StatsStock extends Module
|
|||||||
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||||
$filter = ((int)$cookie->statsstock_id_category ? ' AND p.id_product IN (SELECT cp.id_product FROM '._DB_PREFIX_.'category_product cp WHERE cp.id_category = '.(int)$cookie->statsstock_id_category.')' : '');
|
$filter = ((int)$cookie->statsstock_id_category ? ' AND p.id_product IN (SELECT cp.id_product FROM '._DB_PREFIX_.'category_product cp WHERE cp.id_category = '.(int)$cookie->statsstock_id_category.')' : '');
|
||||||
|
|
||||||
$joinProduct = $whereProduct = '';
|
|
||||||
if ($this->shopID || $this->shopGroupID)
|
|
||||||
{
|
|
||||||
$joinProduct = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product ';
|
|
||||||
if ($this->shopID)
|
|
||||||
$whereProduct = ' AND ps.id_shop = '.$this->shopID;
|
|
||||||
else if ($this->shopGroupID)
|
|
||||||
$whereProduct = ' AND ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = 'SELECT p.id_product, p.reference, pl.name,
|
$sql = 'SELECT p.id_product, p.reference, pl.name,
|
||||||
IFNULL((
|
IFNULL((
|
||||||
SELECT AVG(pa.wholesale_price)
|
SELECT AVG(pa.wholesale_price)
|
||||||
@@ -85,10 +75,10 @@ class StatsStock extends Module
|
|||||||
FROM '._DB_PREFIX_.'product_attribute pa WHERE p.id_product = pa.id_product
|
FROM '._DB_PREFIX_.'product_attribute pa WHERE p.id_product = pa.id_product
|
||||||
), p.wholesale_price * p.quantity) as stockvalue
|
), p.wholesale_price * p.quantity) as stockvalue
|
||||||
FROM '._DB_PREFIX_.'product p
|
FROM '._DB_PREFIX_.'product p
|
||||||
'.$joinProduct.'
|
'.Shop::sqlAsso('product', 'p', true, $this->context).'
|
||||||
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.')
|
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.')
|
||||||
WHERE 1 = 1
|
WHERE 1 = 1
|
||||||
'.$filter.$whereProduct;
|
'.$filter;
|
||||||
$products = Db::getInstance()->ExecuteS($sql);
|
$products = Db::getInstance()->ExecuteS($sql);
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ XML;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$quantityDiscounts = SpecificPrice::getQuantityDiscounts((int)$sqlProduct['id_product'], $this->shopID, 0, 0, 0);
|
$quantityDiscounts = SpecificPrice::getQuantityDiscounts((int)$sqlProduct['id_product'], $this->context->shop->getGroupID(), 0, 0, 0);
|
||||||
|
|
||||||
foreach ($quantityDiscounts AS $quantityDiscount)
|
foreach ($quantityDiscounts AS $quantityDiscount)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user