2017-05-30 15:54:01 +02:00

730 lines
24 KiB
PHP

<?php
/**
* Description of PrivateSales
*
* @company Antadis
*/
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCore.php');
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleAlertMail.php');
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleAlertMailCat.php');
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCategory.php');
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleHistorique.php');
include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCache.php');
class Privatesales extends Module {
/**
*
* @param type $name
* @param Context $context
*/
public function __construct() {
$this->name = 'privatesales';
$this->tab = 'pricing_promotion';
$this->version = '1';
$this->author = 'Antadis';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Private Sales Pro');
$this->description = $this->l('Private sales management for your online shop');
$this->confirmUninstall = $this->l('Are you sure you want to delete Private Sales Pro?');
}
/***********************/
/******* Install *******/
/***********************/
/**
*
* @return boolean
*/
public function install() {
$this->createTab();
if ( !parent::install()
|| !$this->installDb()
|| !$this->registerHook('displayHeader')
|| !$this->registerHook('displayHomeTab')
|| !$this->registerHook('displayBackOfficeHeader')
|| !$this->registerHook('RightColumn')
|| !$this->registerHook('LeftColumn')
|| !$this->registerHook('DisplayTopColumn')
|| !$this->registerHook('ModuleRoutes')
|| !$this->registerHook('displayCategoryFooter')
){
$this->uninstall();
$this->deleteTab();
$this->uninstallDb();
return false;
}
Configuration::updateValue('PRIVATESALES_ROOT', 0);
Configuration::updateValue('PRIVATESALES_POPUP_CONNECTION', 0);
Configuration::updateValue('PRIVATESALES_FUTURELIMIT', 30);
Configuration::updateValue('PRIVATESALES_PASTLIMIT', 30);
Configuration::updateValue('PRIVATESALES_SEO_FR', 'ventes-privees');
Configuration::updateValue('PRIVATESALES_SEO_EN', 'privates-sales');
Configuration::updateValue('PRIVATESALES_SEOTRAILER_FR', 'bande-annonce');
Configuration::updateValue('PRIVATESALES_SEOTRAILER_EN', 'teaser');
Configuration::updateValue('PRIVATESALES_LISTING_PUBLIC', 0);
Configuration::updateValue('PRIVATESALES_HOTSPOT', 1);
Configuration::updateValue('PRIVATESALES_FLASH', 0);
Configuration::updateValue('PRIVATESALES_PASTSALES', 1);
Configuration::updateValue('PRIVATESALES_FUTURESALES', 1);
Configuration::updateValue('PRIVATESALES_SAME_CATEGORY', 0);
Configuration::updateValue('PRIVATESALES_SAME_CATEGORY_NUMBER', 3);
Configuration::updateValue('PRIVATESALES_SHOWHOME', 0);
Configuration::updateValue('PRIVATESALES_COLUMN', 0);
Configuration::updateValue('PRIVATESALES_TRAILER_COLUMN', 0);
Configuration::updateValue('PRIVATESALES_SEND_ALERT_LIMIT', 1440);
return true;
}
/**
*
* @return boolean
*/
public function uninstall() {
if( !parent::uninstall() ){
return false;
}
$this->deleteTab();
$this->uninstallDb();
Configuration::deleteByName('PRIVATESALES_FUTURELIMIT');
Configuration::deleteByName('PRIVATESALES_PASTLIMIT');
Configuration::deleteByName('PRIVATESALES_ROOT');
Configuration::deleteByName('PRIVATESALES_POPUP_CONNECTION');
Configuration::deleteByName('PRIVATESALES_SEO_FR');
Configuration::deleteByName('PRIVATESALES_SEO_EN');
Configuration::deleteByName('PRIVATESALES_SEOTRAILER_FR');
Configuration::deleteByName('PRIVATESALES_SEOTRAILER_EN');
Configuration::deleteByName('PRIVATESALES_LISTING_PUBLIC');
Configuration::deleteByName('PRIVATESALES_HOTSPOT');
Configuration::deleteByName('PRIVATESALES_FLASH');
Configuration::deleteByName('PRIVATESALES_PASTSALES');
Configuration::deleteByName('PRIVATESALES_FUTURESALES');
Configuration::deleteByName('PRIVATESALES_SAME_CATEGORY');
Configuration::deleteByName('PRIVATESALES_SAME_CATEGORY_NUMBER');
Configuration::deleteByName('PRIVATESALES_SHOWHOME');
Configuration::deleteByName('PRIVATESALES_COLUMN');
Configuration::deleteByName('PRIVATESALES_TRAILER_COLUMN');
Configuration::deleteByName('PRIVATESALES_SEND_ALERT_LIMIT');
return true;
}
/**
*
*/
public function createTab(){
$langs = Language::getLanguages();
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$tabs_i18n = array(
'fr' => array(
'Ventes Privées',
),
'en' => array(
'Private sales',
),
);
$tab0 = new Tab();
$tab0->class_name = "AdminPrivateSales";
$tab0->module = "privatesales";
$tab0->id_parent = 0;
$tab0->position = 5;
foreach($langs as $lang){
if(isset($tabs_i18n[$lang['iso_code']])) {
$tab0->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']][0];
} else {
$tab0->name[$lang['id_lang']] = $tabs_i18n['en'][0];
}
}
$tab0->save();
$blog_tab_id = $tab0->id;
$tabs_i18n = array(
'fr' => array(
'Gestions des ventes',
),
'en' => array(
'Sales management',
),
);
$tab1 = new Tab();
$tab1->class_name = "AdminPrivateSales";
$tab1->module = "privatesales";
$tab1->id_parent = $blog_tab_id;
foreach($langs as $lang){
if(isset($tabs_i18n[$lang['iso_code']])) {
$tab1->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']][0];
} else {
$tab1->name[$lang['id_lang']] = $tabs_i18n['en'][0];
}
}
$tab1->save();
$tabs_i18n = array(
'fr' => array(
'Catégorie Ventes Privées',
),
'en' => array(
'Category Private sales',
),
);
$tab3 = new Tab();
$tab3->class_name = "AdminPrivateSalesCategory";
$tab3->module = "privatesales";
$tab3->id_parent = $blog_tab_id;
foreach($langs as $lang){
if(isset($tabs_i18n[$lang['iso_code']])) {
$tab3->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']][0];
} else {
$tab3->name[$lang['id_lang']] = $tabs_i18n['en'][0];
}
}
$tab3->save();
$tabs_i18n = array(
'fr' => array(
'Préférences Ventes Privées',
),
'en' => array(
'Private sales',
),
);
$tab2 = new Tab();
$tab2->class_name = "AdminPreferencePrivateSales";
$tab2->module = "privatesales";
$tab2->id_parent = $blog_tab_id;
foreach($langs as $lang){
if(isset($tabs_i18n[$lang['iso_code']])) {
$tab2->name[$lang['id_lang']] = $tabs_i18n[$lang['iso_code']][0];
} else {
$tab2->name[$lang['id_lang']] = $tabs_i18n['en'][0];
}
}
$tab2->save();
}
/**
*
*/
public function deleteTab(){
if ($id_tab = Tab::getIdFromClassName('AdminPrivateSales'))
{
$tab = new Tab((int)$id_tab);
$tab->delete();
}
if ($id_tab = Tab::getIdFromClassName('AdminPreferencePrivateSales'))
{
$tab = new Tab((int)$id_tab);
$tab->delete();
}
if ($id_tab = Tab::getIdFromClassName('AdminPrivateSalesCategory'))
{
$tab = new Tab((int)$id_tab);
$tab->delete();
}
if ($id_tab = Tab::getIdFromClassName('AdminPrivateSales'))
{
$tab = new Tab((int)$id_tab);
$tab->delete();
}
}
/**
*
* @return boolean
*/
public function installDb(){
$statements = array();
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales` (
`id_privatesales` int(11) NOT NULL AUTO_INCREMENT,
`id_category` int(11),
`date_start_hotspot` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_end_hotspot` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_start` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_end` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_shipping` date NOT NULL DEFAULT "0000-00-00",
`percent` int(11),
`active` int(11),
`archived` int(11),
`flash` int(11),
`news` int(11),
`alert` int(11),
`position` int(11),
`date_add` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_upd` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
PRIMARY KEY (`id_privatesales`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_lang` (
`id_privatesales` int(11),
`id_lang` int(11),
`title` varchar(255),
`subtitle` varchar(255),
`description` TEXT,
`description_newsletter` TEXT,
PRIMARY KEY (`id_privatesales`,`id_lang`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_group` (
`id_privatesales` int(11),
`id_group` int(11),
PRIMARY KEY (`id_privatesales`,`id_group`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_brand` (
`id_privatesales` int(11),
`id_brand` int(11),
PRIMARY KEY (`id_privatesales`,`id_brand`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_shop` (
`id_privatesales` int(11),
`id_shop` int(11),
PRIMARY KEY (`id_privatesales`,`id_shop`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_alertmail` (
`id_privatesales_alertmail` int(11) NOT NULL AUTO_INCREMENT,
`id_privatesales` int(11),
`id_user` int(11) DEFAULT NULL,
`email` varchar(255),
PRIMARY KEY (`id_privatesales_alertmail`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_alertmail_category` (
`id_privatesales_alertmail_category` int(11) NOT NULL AUTO_INCREMENT,
`id_privatesales_category` int(11),
`id_user` int(11) DEFAULT NULL,
`email` varchar(255),
PRIMARY KEY (`id_privatesales_alertmail_category`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_category` (
`id_privatesales_category` int(11) NOT NULL AUTO_INCREMENT,
`id_parent` int(11),
`active` int(11),
PRIMARY KEY (`id_privatesales_category`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_category_lang` (
`id_privatesales_category` int(11),
`id_lang` int(11),
`title` varchar(255),
`alias` varchar(255),
`description` TEXT,
PRIMARY KEY (`id_privatesales_category`,`id_lang`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_category_sales` (
`id_privatesales_category` int(11),
`id_privatesales` int(11),
PRIMARY KEY (`id_privatesales_category`,`id_privatesales`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
$statements[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesales_historique` (
`id_privatesales_historique` int(11) NOT NULL AUTO_INCREMENT,
`id_privatesales` int(11),
`date_start` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_end` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
`date_add` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
PRIMARY KEY (`id_privatesales_historique`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
return $this->uninstallDb() && $this->updateDb($statements);
}
/**
*
* @return boolean
*/
public function uninstallDb(){
$statements = array();
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_lang` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_group` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_shop` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_alertmail_category` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_alertmail` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_category_lang` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_category_sales` ;';
$statements[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'privatesales_historique` ;';
return $this->updateDb($statements);
}
/**
*
* @param array $statements
* @return boolean
*/
public function updateDb($statements){
foreach($statements as $statement){
if( !Db::getInstance()->execute($statement)){
return false;
}
}
return true;
}
/************************/
/********* HOOK *********/
/************************/
/**
*
* @param type $params
*/
public function hookDisplayHeader($params){
$this->context->controller->addCSS(($this->_path).'css/privatesales.css', 'all');
$this->context->controller->addJS(_PS_THEME_DIR_.'js/owl.js');
$this->context->controller->addCss(_PS_THEME_DIR_.'css/owl.css');
$this->context->controller->addJS(_PS_MODULE_DIR_.'privatesales/js/countdown/jquery.countdown.js');
$this->context->controller->addJS(_PS_MODULE_DIR_.'privatesales/js/countdown/jquery.countdown-'.strtolower(Language::getIsoById($this->context->language->id)).'.js');
if ( Tools::getValue('controller') == 'authentication' && Tools::getValue('ps') == '0' ){
$errors = $this->l('You must be connected for see the privatesales');
}
$this->context->smarty->assign('popup_connection', Configuration::get('PRIVATESALES_POPUP_CONNECTION'));
if ( Tools::getValue('controller') == 'category' || Tools::getValue('controller') == 'product' ){
if(Tools::getValue('controller') == 'category'){
$id_category = (int) Tools::getValue('id_category');
$url_back = $this->context->link->getCategoryLink($id_category);
}else{
$product = new Product((int) Tools::getValue('id_product'));
$id_category = (int)$product->id_category_default;
$url_back = $this->context->link->getProductLink($product);
}
$this->privatesale = SaleCore::loadSaleFromCategoryId($id_category, (int) $this->context->cookie->id_lang);
if ($this->privatesale){
if(!$this->privatesale->isOpen()) {
$categories = Db::getInstance()->ExecuteS('
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category_product` c
WHERE c.`id_product` = '.(int) $product->id.' AND c.`id_category` != '.(int) $product->id_category_default.'
ORDER BY c.`id_category`
');
foreach ($categories as $key => $cat) {
$sale = SaleCore::loadSaleFromCategoryId($cat['id_category'], (int) $this->context->cookie->id_lang);
if ($sale) {
if ($sale->isOpen()) {
$id_category = (int) $cat['id_category'];
$this->privatesale = $sale;
break;
}
}
}
}
}
//OLD : $this->context->link->getModuleLink('privatesales', 'home')
// if($this->privatesale && !$params['cookie']->logged){
// $redirect_string = '&'.Tools::getRedirectString();
// Tools::redirect($this->context->link->getPageLink('authentication',null,$this->context->cookie->id_lang,'ps=0&back='.$url_back.$redirect_string));
// }else
if($this->privatesale /*&& $params['cookie']->logged*/){
if( strtotime($this->privatesale->date_start) > time() || !$this->privatesale->active /*|| count(array_intersect(
Customer::getGroupsStatic((int) $this->context->cookie->id_customer),
$this->privatesale->getGroups()
)) == 0*/){
Tools::redirect($this->context->link->getModuleLink('privatesales', 'trailer' , array('id_sale' => $this->privatesale->id_privatesales )));
}
if(strtotime($this->privatesale->date_end) < time()){
$this->context->smarty->assign(array(
'PS_CATALOG_MODE' => true,
));
}
$this->context->smarty->assign(array(
'privatesale' => $this->privatesale,
'link_img' => __PS_BASE_URI__.'modules/privatesales/img/',
));
}
}
if ( Tools::getValue('controller') == 'category' && Tools::getValue('id_category') == Configuration::get('PRIVATESALES_ROOT')){
$redirect_string = Tools::getRedirectString();
$url = $this->context->link->getModuleLink('privatesales', 'home');
Tools::redirect( $url . (strpos($url, '?') ? '&' : '?' ) . $redirect_string );
}
$cart_rules = $this->context->cart->getCartRules();
$products = $this->context->cart->getProducts();
$deletedprod = 0;
foreach ($products as $product){
foreach ($cart_rules as $cart_rule) {
if ($cart_rule['gift_product'] === $product['id_product']) {
continue(2);
}
}
$id_category = (int)$product['id_category_default'];
$privatesale = SaleCore::loadSaleFromCategoryId($id_category, (int) $this->context->cookie->id_lang);
if ($privatesale) {
if (!$privatesale->isOpen()) {
$categories = Db::getInstance()->ExecuteS('
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category_product` c
WHERE c.`id_product` = '.(int) $product['id_product'].' AND c.`id_category` != '.(int) $product['id_category_default'].'
ORDER BY c.`id_category`
');
foreach ($categories as $key => $cat) {
$sale = SaleCore::loadSaleFromCategoryId($cat['id_category'], (int) $this->context->cookie->id_lang);
if ($sale) {
if ($sale->isOpen()) {
$id_category = (int) $cat['id_category'];
$privatesale = $sale;
break;
}
}
}
}
}
if (!$privatesale)
continue;
if( strtotime($privatesale->date_start) > time() || strtotime($privatesale->date_end) < time() || !$privatesale->active || count(array_intersect(
Customer::getGroupsStatic((int) $this->context->cookie->id_customer),
$privatesale->getGroups()
)) == 0){
$this->context->cart->deleteProduct((int)$product['id_product']);
$deletedprod++;
}
}
if($deletedprod){
$this->context->smarty->assign(array(
'deletedprod' => $deletedprod
));
}
}
/**
*
* @param type $params
*/
public function hookLeftColumn($params){
return $this->hookRightColumn($params);
}
/**
*
* @param type $params
*/
public function hookDisplayTopColumn($params){
return $this->hookRightColumn($params);
}
/**
*
* @param type $params
*/
public function hookRightColumn($params){
if ( Tools::getValue('controller') == 'category'){
if(Tools::getValue('controller') == 'category'){
$id_category = (int) Tools::getValue('id_category');
}else{
$product = new Product((int) Tools::getValue('id_product'));
$id_category = (int)$product->id_category_default;
}
$privatesale = SaleCore::loadSaleFromCategoryId($id_category, (int) $this->context->cookie->id_lang);
if ($privatesale) {
if (!$privatesale->isOpen()) {
$categories = Db::getInstance()->ExecuteS('
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category_product` c
WHERE c.`id_product` = '.(int) $product->id.' AND c.`id_category` != '.(int) $product->id_category_default.'
ORDER BY c.`id_category`
');
foreach ($categories as $key => $cat) {
$sale = SaleCore::loadSaleFromCategoryId($cat['id_category'], (int) $this->context->cookie->id_lang);
if ($sale) {
if ($sale->isOpen()) {
$id_category = (int) $cat['id_category'];
$privatesale = $sale;
break;
}
}
}
}
}
if($privatesale){
$this->context->smarty->assign(array(
'privatesale' => $privatesale,
'link_img' => __PS_BASE_URI__.'modules/privatesales/img/',
));
return $this->display(__FILE__, 'logocat.tpl');
}
}
}
/**
*
* @param type $params
*/
public function hookModuleRoutes($params){
$tab_routes = array();
if(Configuration::get('PRIVATESALES_SEO_'.strtoupper($this->context->language->iso_code))){
$url = Configuration::get('PRIVATESALES_SEO_'.strtoupper($this->context->language->iso_code));
}else{
$url = Configuration::get('PRIVATESALES_SEO_EN');
}
if(Configuration::get('PRIVATESALES_SEOTRAILER_'.strtoupper($this->context->language->iso_code))){
$urltrailer = Configuration::get('PRIVATESALES_SEOTRAILER_'.strtoupper($this->context->language->iso_code));
}else{
$urltrailer = Configuration::get('PRIVATESALES_SEOTRAILER_EN');
}
$tab_routes['module-privatesales-homecat'] = array(
'controller' => 'homecat',
'rule' => $url.'/{:id_sale_category}-{:alias}',
'keywords' => array(
'alias' => array('regexp' => '[a-zA-Z-0-9]*' , 'param' => 'alias'),
'id_sale_category' => array('regexp' => '[0-9]*' , 'param' => 'id_sale_category'),
),
'params' => array(
'fc' => 'module',
'module' => 'privatesales',
)
);
if(Configuration::get('PRIVATESALES_SHOWHOME')){
$url = "";
}
$tab_routes['module-privatesales-home'] = array(
'controller' => 'home',
'rule' => $url,
'keywords' => array(
),
'params' => array(
'fc' => 'module',
'module' => 'privatesales',
)
);
$tab_routes['module-privatesales-trailer'] = array(
'controller' => 'trailer',
'rule' => $urltrailer.'/{:id_sale}',
'keywords' => array(
'id_sale' => array('regexp' => '[a-zA-Z-0-9]*' , 'param' => 'id_sale')
),
'params' => array(
'fc' => 'module',
'module' => 'privatesales',
)
);
return $tab_routes;
}
/**
*
*/
public function hookDisplayHomeTab(){
$this->context->smarty->assign(array(
'link_ps' => $this->context->link->getModuleLink('privatesales', 'home' )
));
return $this->display(__FILE__, 'hometab.tpl');
}
/**
*
*/
public function hookDisplayBackOfficeHeader(){
$this->context->controller->addCss(_PS_MODULE_DIR_.'privatesales/css/admin.css');
}
/**
*
*/
public function hookDisplayCategoryFooter(){
if ( !Configuration::get('PRIVATESALES_SAME_CATEGORY') || !$this->privatesale )
return;
$inSameSaleCategorySales = $this->privatesale->getInSameSaleCategory(Configuration::get('PRIVATESALES_SAME_CATEGORY_NUMBER'));
$this->context->smarty->assign('inSameSaleCategorySales', $inSameSaleCategorySales);
return $this->display(__FILE__, 'inSameSaleCategory.tpl');
}
/**
*
* @param type $params
*/
public function hookDisplayBottomCategory($params){
if ( !$this->privatesale )
return;
// $sales = SaleCore::getInSameSaleCategory($this->privatesale->id);
$sales = SaleCore::getSales('current', 0, true, false, true, 'rand');
if($sales){
$this->context->smarty->assign(array(
'current_sale' => $this->privatesale,
'sales' => $sales,
'link_img' => 'modules/privatesales/img/',
'link_mod_img' => _PS_MODULE_DIR_.'modules/privatesales/img/'
));
return $this->display(__FILE__, 'bottomCategory.tpl');
}
}
public function hookDisplayProductTabContent($params){
global $smarty;
$product = new Product((int) $params['product']->id);
$id_category = (int)$product->id_category_default;
$privatesale = SaleCore::loadSaleFromCategoryId($id_category, (int) $this->context->cookie->id_lang);
if ($privatesale) {
if (!$privatesale->isOpen()) {
$categories = Db::getInstance()->ExecuteS('
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category_product` c
WHERE c.`id_product` = '.(int) $product->id.' AND c.`id_category` != '.(int) $product->id_category_default.'
ORDER BY c.`id_category`
');
foreach ($categories as $key => $cat) {
$sale = SaleCore::loadSaleFromCategoryId($cat['id_category'], (int) $this->context->cookie->id_lang);
if ($sale) {
if ($sale->isOpen()) {
$id_category = (int) $cat['id_category'];
$privatesale = $sale;
break;
}
}
}
}
}
if($privatesale){
$this->context->smarty->assign(array(
'privatesale' => $privatesale,
'product' => $product,
));
return $this->display(__FILE__, 'views/templates/hook/displayProductTabContent.tpl');
}
}
}