// 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:
@@ -124,15 +124,13 @@ class BlockCategories extends Module
|
||||
|
||||
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
$children = array();
|
||||
if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
|
||||
foreach ($resultParents[$id_category] as $subcat)
|
||||
$children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
|
||||
if (!isset($resultIds[$id_category]))
|
||||
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'],
|
||||
'children' => $children);
|
||||
return $return;
|
||||
@@ -141,7 +139,7 @@ class BlockCategories extends Module
|
||||
public function hookLeftColumn($params)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$id_current_shop = $this->shopID;
|
||||
$id_current_shop = $context->shop->getID();
|
||||
|
||||
$id_customer = (int)($params['cookie']->id_customer);
|
||||
// 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)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$id_current_shop = $this->shopID;
|
||||
$context = $this->context;
|
||||
$id_current_shop = $context->shop->getID();
|
||||
|
||||
$id_customer = (int)($params['cookie']->id_customer);
|
||||
// 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()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js');
|
||||
$context->controller->addCSS(($this->_path).'blockcategories.css', 'all');
|
||||
$this->context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js');
|
||||
$this->context->controller->addCSS(($this->_path).'blockcategories.css', 'all');
|
||||
}
|
||||
|
||||
private function _clearBlockcategoriesCache()
|
||||
|
||||
@@ -59,14 +59,11 @@ class BlockCurrencies extends Module
|
||||
{
|
||||
if (Configuration::get('PS_CATALOG_MODE'))
|
||||
return ;
|
||||
|
||||
$context = Context::getContext();
|
||||
|
||||
$id_current_shop = $this->shopID;
|
||||
$currencies = Currency::getCurrencies(false, 1, $id_current_shop);
|
||||
|
||||
$currencies = Currency::getCurrencies(false, 1, $this->context->shop->getID());
|
||||
if (!sizeof($currencies))
|
||||
return '';
|
||||
$context->controller->smarty->assign('currencies', $currencies);
|
||||
$this->context->controller->smarty->assign('currencies', $currencies);
|
||||
return $this->display(__FILE__, 'blockcurrencies.tpl');
|
||||
}
|
||||
|
||||
@@ -74,8 +71,7 @@ class BlockCurrencies extends Module
|
||||
{
|
||||
if (Configuration::get('PS_CATALOG_MODE'))
|
||||
return ;
|
||||
$context = Context::getContext();
|
||||
$context->controller->addCSS(($this->_path).'blockcurrencies.css', 'all');
|
||||
$this->context->controller->addCSS(($this->_path).'blockcurrencies.css', 'all');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,19 +57,16 @@ class BlockLanguages extends Module
|
||||
*/
|
||||
function hookTop($params)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
$languages = Language::getLanguages(true, $this->shopID);
|
||||
$languages = Language::getLanguages(true, $this->context->shop->getID());
|
||||
if (!sizeof($languages))
|
||||
return '';
|
||||
$context->controller->smarty->assign('languages', $languages);
|
||||
$this->context->controller->smarty->assign('languages', $languages);
|
||||
return $this->display(__FILE__, 'blocklanguages.tpl');
|
||||
}
|
||||
|
||||
function hookHeader($params)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$context->controller->addCSS(($this->_path).'blocklanguages.css', 'all');
|
||||
$this->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,
|
||||
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
|
||||
'.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).')
|
||||
'.Product::sqlStock('p', 0).'
|
||||
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();
|
||||
//$getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_shop = false
|
||||
$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,
|
||||
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
|
||||
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
|
||||
|
||||
@@ -140,13 +140,13 @@ class Blocknewsletter extends Module
|
||||
{
|
||||
$sql = 'SELECT `email` FROM '._DB_PREFIX_.'newsletter
|
||||
WHERE `email` = \''.pSQL($customerEmail).'\'
|
||||
AND id_shop = '.$this->shopID;
|
||||
AND id_shop = '.$this->context->shop->getID();
|
||||
if (Db::getInstance()->getRow($sql))
|
||||
return 1;
|
||||
|
||||
$sql = 'SELECT `newsletter` FROM '._DB_PREFIX_.'customer
|
||||
WHERE `email` = \''.pSQL($customerEmail).'\'
|
||||
AND id_shop = '.$this->shopID;
|
||||
AND id_shop = '.$this->context->shop->getID();
|
||||
if (!$registered = Db::getInstance()->getRow($sql))
|
||||
return -1;
|
||||
|
||||
@@ -160,7 +160,6 @@ class Blocknewsletter extends Module
|
||||
*/
|
||||
private function newsletterRegistration()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
if (empty($_POST['email']) OR !Validate::isEmail($_POST['email']))
|
||||
return $this->error = $this->l('Invalid e-mail address');
|
||||
|
||||
@@ -173,14 +172,14 @@ class Blocknewsletter extends Module
|
||||
/* If the user ins't a customer */
|
||||
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->valid = $this->l('Unsubscription successful');
|
||||
}
|
||||
/* If the user is a customer */
|
||||
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->valid = $this->l('Unsubscription successful');
|
||||
}
|
||||
@@ -196,8 +195,8 @@ class Blocknewsletter extends Module
|
||||
elseif ($registerStatus == -1)
|
||||
{
|
||||
$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()).'\',
|
||||
(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)
|
||||
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)$this->context->customer->id.' ORDER BY c.date_add DESC LIMIT 1)
|
||||
)';
|
||||
if (!Db::getInstance()->Execute($sql))
|
||||
return $this->error = $this->l('Error during subscription');
|
||||
@@ -211,7 +210,7 @@ class Blocknewsletter extends Module
|
||||
$sql = 'UPDATE '._DB_PREFIX_.'customer
|
||||
SET `newsletter` = 1, newsletter_date_add = NOW(), `ip_registration_newsletter` = \''.pSQL(Tools::getRemoteAddr()).'\'
|
||||
WHERE `email` = \''.pSQL($_POST['email']).'\'
|
||||
AND id_shop = '.$this->shopID;
|
||||
AND id_shop = '.$this->context->shop->getID();
|
||||
if (!Db::getInstance()->Execute($sql))
|
||||
return $this->error = $this->l('Error during subscription');
|
||||
$this->sendVoucher(pSQL($_POST['email']));
|
||||
|
||||
@@ -85,11 +85,10 @@ class BlockSpecials extends Module
|
||||
{
|
||||
if (Configuration::get('PS_CATALOG_MODE'))
|
||||
return ;
|
||||
|
||||
$context = Context::getContext();
|
||||
if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang), false, false, $this->shopID) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
|
||||
|
||||
if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang), false, false, $this->context->shop->getID()) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY'))
|
||||
return;
|
||||
$context->controller->smarty->assign(array(
|
||||
$this->context->controller->smarty->assign(array(
|
||||
'special' => $special,
|
||||
'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),
|
||||
'mediumSize' => Image::getSize('medium')
|
||||
@@ -107,8 +106,7 @@ class BlockSpecials extends Module
|
||||
{
|
||||
if (Configuration::get('PS_CATALOG_MODE'))
|
||||
return ;
|
||||
$context = Context::getContext();
|
||||
$context->controller->addCSS(($this->_path).'blockspecials.css', 'all');
|
||||
$this->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'] : '';
|
||||
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))
|
||||
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;
|
||||
$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;
|
||||
|
||||
$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');
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class SEKeywords extends ModuleGraph
|
||||
|
||||
if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER']))
|
||||
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()
|
||||
|
||||
@@ -123,14 +123,14 @@ class StatsBestCategories extends ModuleGrid
|
||||
|
||||
// If a shop is selected, get all children categories for the shop
|
||||
$categories = array();
|
||||
if ($this->shopID || $this->shopGroupID)
|
||||
if ($this->context->shop->getContextType() != Shop::CONTEXT_ALL)
|
||||
{
|
||||
$sql = 'SELECT c.nleft, c.nright
|
||||
FROM '._DB_PREFIX_.'category c
|
||||
WHERE c.id_category IN (
|
||||
SELECT s.id_category
|
||||
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))
|
||||
{
|
||||
|
||||
@@ -149,16 +149,6 @@ class StatsBestProducts extends ModuleGrid
|
||||
$dateBetween = $this->getDate();
|
||||
$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,
|
||||
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,
|
||||
@@ -174,12 +164,11 @@ class StatsBestProducts extends ModuleGrid
|
||||
AND dr.time_end BETWEEN '.$dateBetween.'
|
||||
) AS totalPageViewed
|
||||
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_.'order_detail od ON od.product_id = p.id_product
|
||||
LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order
|
||||
WHERE '.$whereShop.'
|
||||
p.active = 1
|
||||
WHERE p.active = 1
|
||||
AND o.valid = 1
|
||||
AND o.invoice_date BETWEEN '.$dateBetween.'
|
||||
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->_where = ' AND cp.`id_category` = '.$id_category;
|
||||
}
|
||||
|
||||
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.')';
|
||||
}
|
||||
$this->_join .= Shop::sqlAsso('product', 'p', true, $this->context);
|
||||
|
||||
$result1 = $this->getQuery1(true);
|
||||
$total = $result1['total'];
|
||||
|
||||
@@ -75,18 +75,14 @@ class StatsCheckUp extends Module
|
||||
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
|
||||
$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;
|
||||
|
||||
$shopID = $this->context->shop->getID();
|
||||
$shopGroupID = $this->context->shop->getGroupID();
|
||||
|
||||
// Get languages
|
||||
$sql = 'SELECT l.*
|
||||
FROM '._DB_PREFIX_.'lang l';
|
||||
if ($this->shopID || $this->shopGroupID)
|
||||
{
|
||||
$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.')';
|
||||
}
|
||||
FROM '._DB_PREFIX_.'lang l'
|
||||
.Shop::sqlAsso('lang', 'l', true, $this->context);
|
||||
$languages = $db->ExecuteS($sql);
|
||||
|
||||
$arrayColors = array(
|
||||
@@ -109,40 +105,19 @@ class StatsCheckUp extends Module
|
||||
elseif ($cookie->checkup_order == 3)
|
||||
$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
|
||||
$sql = 'SELECT p.id_product, p.active, pl.name, (
|
||||
SELECT COUNT(*)
|
||||
FROM '._DB_PREFIX_.'image i
|
||||
'.$joinImage.'
|
||||
'.Shop::sqlAsso('image', 'i', true, $this->context).'
|
||||
WHERE i.id_product = p.id_product
|
||||
'.$whereImage.'
|
||||
) as nbImages, (
|
||||
SELECT SUM(od.product_quantity)
|
||||
FROM '._DB_PREFIX_.'orders o
|
||||
LEFT JOIN '._DB_PREFIX_.'order_detail od ON o.id_order = od.id_order
|
||||
WHERE od.product_id = p.id_product
|
||||
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction().'
|
||||
) as nbSales, IFNULL((
|
||||
SELECT SUM(pa.quantity)
|
||||
FROM '._DB_PREFIX_.'product_attribute pa
|
||||
@@ -150,8 +125,7 @@ class StatsCheckUp extends Module
|
||||
), p.quantity) as stock
|
||||
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.')
|
||||
'.$joinProduct.'
|
||||
'.$whereProduct.'
|
||||
'.Shop::sqlAsso('product', 'p', true, $this->context).'
|
||||
ORDER BY '.$orderBy;
|
||||
$result = $db->ExecuteS($sql);
|
||||
|
||||
|
||||
@@ -79,27 +79,7 @@ class StatsForecast extends Module
|
||||
|
||||
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||
$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 ...
|
||||
$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']);
|
||||
@@ -141,7 +121,7 @@ class StatsForecast extends Module
|
||||
LEFT JOIN '._DB_PREFIX_.'product p ON od.product_id = p.id_product
|
||||
WHERE o.valid = 1
|
||||
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY '.$dateFromGInvoice.'
|
||||
ORDER BY fix_date';
|
||||
$result = $db->ExecuteS($sql, false);
|
||||
@@ -188,7 +168,7 @@ class StatsForecast extends Module
|
||||
$sql = 'SELECT '.$dateFromGAdd.' as fix_date, COUNT(*) as visits
|
||||
FROM '._DB_PREFIX_.'connections c
|
||||
WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereConnection.'
|
||||
'.$this->sqlShopRestriction(false, 'c').'
|
||||
GROUP BY '.$dateFromGAdd;
|
||||
$visits = Db::getInstance()->ExecuteS($sql, false);
|
||||
while ($row = $db->nextRow($visits))
|
||||
@@ -201,7 +181,7 @@ class StatsForecast extends Module
|
||||
WHERE o.valid = 1
|
||||
AND o.total_paid_real > 0
|
||||
AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween()
|
||||
.$whereOrder.'
|
||||
.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY '.$dateFromGInvoice;
|
||||
$discounts = Db::getInstance()->ExecuteS($sql, false);
|
||||
while ($row = $db->nextRow($discounts))
|
||||
@@ -219,7 +199,7 @@ class StatsForecast extends Module
|
||||
$sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'customer
|
||||
WHERE date_add BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
AND date_add '.$dateFromGReg
|
||||
.$whereCustomer;
|
||||
.$this->sqlShopRestriction(true);
|
||||
$row['registrations'] = Db::getInstance()->getValue($sql);
|
||||
$totalHT = $row['totalProducts'] - $discountToday;
|
||||
|
||||
@@ -297,7 +277,7 @@ class StatsForecast extends Module
|
||||
$sql = 'SELECT COUNT(DISTINCT c.id_guest)
|
||||
FROM '._DB_PREFIX_.'connections c
|
||||
WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
||||
.$whereConnection;
|
||||
.$this->sqlShopRestriction(false, 'c');
|
||||
$visitors = Db::getInstance()->getValue($sql);
|
||||
|
||||
$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
|
||||
WHERE c.id_customer != 0
|
||||
AND c.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
||||
.$whereConnection;
|
||||
.$this->sqlShopRestriction(false, 'c');
|
||||
$customers = Db::getInstance()->getValue($sql);
|
||||
|
||||
$sql = 'SELECT COUNT(*)
|
||||
@@ -314,7 +294,7 @@ class StatsForecast extends Module
|
||||
SELECT id_cart FROM '._DB_PREFIX_.'cart_product
|
||||
) AND (
|
||||
date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
)'.$whereCart;
|
||||
)'.$this->sqlShopRestriction();
|
||||
$carts = Db::getInstance()->getValue($sql);
|
||||
|
||||
$sql = 'SELECT COUNT(*)
|
||||
@@ -324,14 +304,14 @@ class StatsForecast extends Module
|
||||
) AND id_address_invoice != 0
|
||||
AND (
|
||||
date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
)'.$whereCart;
|
||||
)'.$this->sqlShopRestriction();
|
||||
$fullcarts = Db::getInstance()->getValue($sql);
|
||||
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM '._DB_PREFIX_.'orders o
|
||||
WHERE o.valid = 1
|
||||
AND o.date_add BETWEEN '.ModuleGraph::getDateBetween()
|
||||
.$whereOrder;
|
||||
.$this->sqlShopRestriction(false, 'o');
|
||||
$orders = Db::getInstance()->getValue($sql);
|
||||
|
||||
$this->_html .= '<div class="clear"> </div>
|
||||
@@ -508,23 +488,7 @@ class StatsForecast extends Module
|
||||
$employee = new Employee($cookie->id_employee);
|
||||
$ca = array();
|
||||
|
||||
// Prepare SQL clause to filter per shop
|
||||
$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.')';
|
||||
}
|
||||
}
|
||||
|
||||
$where = $join = '';
|
||||
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';
|
||||
@@ -540,7 +504,7 @@ class StatsForecast extends Module
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$where.'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY p.id_category_default';
|
||||
$ca['cat'] = Db::getInstance()->ExecuteS($sql);
|
||||
uasort($ca['cat'], 'statsforecast_sort');
|
||||
@@ -548,9 +512,8 @@ class StatsForecast extends Module
|
||||
$langValues = '';
|
||||
$sql = 'SELECT l.id_lang, l.iso_code
|
||||
FROM `'._DB_PREFIX_.'lang` l
|
||||
'.$joinLang.'
|
||||
WHERE l.active = 1
|
||||
'.$whereLang;
|
||||
'.Shop::sqlAsso('lang', 'l', true, $this->context).'
|
||||
WHERE l.active = 1';
|
||||
$languages = Db::getInstance()->ExecuteS($sql);
|
||||
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']).',';
|
||||
@@ -562,7 +525,7 @@ class StatsForecast extends Module
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereOrder;
|
||||
'.$this->sqlShopRestriction(false, 'o');
|
||||
$ca['lang'] = Db::getInstance()->getRow($sql);
|
||||
arsort($ca['lang']);
|
||||
|
||||
@@ -570,7 +533,7 @@ class StatsForecast extends Module
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
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').'\'
|
||||
'.$whereOrder;
|
||||
'.$this->sqlShopRestriction(false, 'o');
|
||||
$ca['langprev'] = Db::getInstance()->getRow($sql);
|
||||
}
|
||||
else
|
||||
@@ -585,7 +548,7 @@ class StatsForecast extends Module
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$where.'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY o.module
|
||||
ORDER BY total DESC';
|
||||
$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
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY c.id_zone
|
||||
ORDER BY total DESC';
|
||||
$ca['zones'] = Db::getInstance()->ExecuteS($sql);
|
||||
@@ -609,7 +572,7 @@ class StatsForecast extends Module
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$where.'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY o.id_currency
|
||||
ORDER BY total DESC';
|
||||
$ca['currencies'] = Db::getInstance()->ExecuteS($sql);
|
||||
@@ -618,7 +581,7 @@ class StatsForecast extends Module
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereOrder;
|
||||
'.$this->sqlShopRestriction(false, 'o');
|
||||
$ca['ventil'] = Db::getInstance()->getRow($sql);
|
||||
|
||||
$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).')
|
||||
WHERE o.valid = 1
|
||||
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
|
||||
'.$whereOrder.'
|
||||
'.$this->sqlShopRestriction(false, 'o').'
|
||||
GROUP BY pac.id_attribute';
|
||||
$ca['attributes'] = Db::getInstance()->ExecuteS($sql);
|
||||
|
||||
|
||||
@@ -99,24 +99,13 @@ class StatsProduct extends ModuleGraph
|
||||
|
||||
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(
|
||||
(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
|
||||
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`' : '').'
|
||||
WHERE '.$whereShop.'
|
||||
pl.`id_lang` = '.(int)($id_lang).'
|
||||
WHERE pl.`id_lang` = '.(int)($id_lang).'
|
||||
'.(Tools::getValue('id_category') ? 'AND cp.id_category = '.(int)(Tools::getValue('id_category')) : '').'
|
||||
ORDER BY pl.`name`';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
|
||||
@@ -87,7 +87,7 @@ class StatsSearch extends ModuleGraph
|
||||
function hookSearch($params)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,7 @@ class StatsStock extends Module
|
||||
$ru = $currentIndex.'&module='.$this->name.'&token='.Tools::getValue('token');
|
||||
$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.')' : '');
|
||||
|
||||
$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,
|
||||
IFNULL((
|
||||
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
|
||||
), p.wholesale_price * p.quantity) as stockvalue
|
||||
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.')
|
||||
WHERE 1 = 1
|
||||
'.$filter.$whereProduct;
|
||||
'.$filter;
|
||||
$products = Db::getInstance()->ExecuteS($sql);
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user