bebeboutik/modules/privatesales_salemenu/privatesales_salemenu.php

88 lines
2.5 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
class PrivateSales_SaleMenu extends Module {
public function __construct() {
$this->name = 'privatesales_salemenu';
$this->tab = 'pricing_promotion';
$this->author = 'Antadis';
$this->version = '1.0';
parent::__construct();
$this->displayName = $this->l('Private Sales Sale menu');
$this->description = $this->l('Adds a list of the current private sales');
}
public function install() {
if(!Module::isInstalled('privatesales')) {
return FALSE;
}
return parent::install() && $this->registerHook('top');
}
2017-10-31 16:04:36 +01:00
2016-01-04 12:49:26 +01:00
public function hookSubTop($params) {
return $this->hookTop($params);
}
public function hookTop($params) {
2017-10-31 16:04:36 +01:00
global $cookie, $smarty, $site_version_front;
2016-01-04 12:49:26 +01:00
include_once dirname(__FILE__).'/../privatesales/Sale.php';
if(_PS_MOBILE_)
return false;
2017-10-31 16:04:36 +01:00
2016-01-04 12:49:26 +01:00
/*
if($cookie->isLogged()) {
*/
2017-10-31 16:04:36 +01:00
//$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`date_start` ASC');
$sales = Sale::getSales(TRUE, NULL, NULL, 'current', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $site_version_front, TRUE);
2016-01-04 12:49:26 +01:00
$sales_1 = array();
$sales_2 = array();
$sales_3 = array();
$sale_ids = array();
2017-10-31 16:04:36 +01:00
2016-01-04 12:49:26 +01:00
foreach($sales as $sale) {
if($sale->sale_type !== NULL) {
if($sale->sale_type == 1) {
$sales_1[] = $sale;
} elseif($sale->sale_type == 2) {
$sales_2[] = $sale;
} elseif($sale->sale_type == 3) {
$sales_3[] = $sale;
}
}
$sale_ids[] = (int) $sale->id;
}
2017-10-31 16:04:36 +01:00
$query = '
2016-01-04 12:49:26 +01:00
SELECT `id_sale`, `value`
FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
WHERE `id_sale` IN ('.implode(', ', $sale_ids).')
AND `id_lang` = '.(int) $cookie->id_lang.'
AND `id_field` = 1
2017-10-31 16:04:36 +01:00
';
if (false === ($extra_sale_fields = CacheRedis::getInstance()->getQuery($query, 'sale'))) {
$extra_sale_fields = array();
foreach(Db::getInstance()->ExecuteS($query) as $row) {
$extra_sale_fields[(int) $row['id_sale']] = $row['value'];
}
CacheRedis::getInstance()->setQuery($query, self::CONTROLLER_NAME, $extra_sale_fields);
}
2016-01-04 12:49:26 +01:00
$smarty->assign(array(
'menu_sales' => $sales,
'menu_sales_1' => $sales_1,
'menu_sales_2' => $sales_2,
'menu_sales_3' => $sales_3,
'extra_sale_fields' => $extra_sale_fields,
));
$smarty->assign('customer_groups', $cookie->isLogged()? Customer::getGroupsStatic((int) $cookie->id_customer): array(1));
return $this->display(__FILE__, 'menu.tpl');
/*}
*/
}
}