133 lines
5.0 KiB
PHP
133 lines
5.0 KiB
PHP
<?php
|
|
/**
|
|
* Description of privatesaleshome
|
|
*
|
|
* @company Antadis
|
|
*/
|
|
|
|
class privatesaleshomecatModuleFrontController extends ModuleFrontController {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function init(){
|
|
|
|
if(Configuration::get('PRIVATESALES_COLUMN') == 0){
|
|
$this->display_column_left = false;
|
|
$this->display_column_right = false;
|
|
}else if(Configuration::get('PRIVATESALES_COLUMN') == 1){
|
|
$this->display_column_left = true;
|
|
$this->display_column_right = false;
|
|
}else if(Configuration::get('PRIVATESALES_COLUMN') == 2){
|
|
$this->display_column_left = false;
|
|
$this->display_column_right = true;
|
|
}else if(Configuration::get('PRIVATESALES_COLUMN') == 3){
|
|
$this->display_column_left = true;
|
|
$this->display_column_right = true;
|
|
}
|
|
|
|
parent::init();
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function initContent(){
|
|
|
|
$ajax = Tools::getValue('ajax');
|
|
if($ajax){
|
|
echo $this->ajaxProcessSubmitAlert();
|
|
}
|
|
|
|
if(!$this->context->cookie->logged && !Configuration::get('PRIVATESALES_LISTING_PUBLIC')){
|
|
Tools::redirect($this->context->link->getPageLink('authentication',null,$this->context->cookie->id_lang,'ps=0&back='.$this->context->link->getModuleLink('privatesales', 'home')));
|
|
}
|
|
|
|
parent::initContent();
|
|
|
|
if(Tools::getValue('id_sale_category')){
|
|
$id_category = Tools::getValue('id_sale_category');
|
|
$alias = Tools::getValue('alias');
|
|
|
|
$category = new SaleCategory($id_category,(int) $this->context->cookie->id_lang);
|
|
if(!$category->id_privatesales_category){
|
|
Tools::redirect($this->context->link->getModuleLink('privatesales', 'home'));
|
|
}
|
|
if($category->alias != $alias){
|
|
Tools::redirect($this->context->link->getModuleLink('privatesales', 'homecat', array( 'id_sale_category' => $id_category, 'alias' => $category->alias)));
|
|
}
|
|
}
|
|
|
|
|
|
if(Configuration::get('PRIVATESALES_FLASH'))
|
|
$flashsales = SaleCore::getSales("current",0,TRUE,FALSE,TRUE,'position','ASC',$id_category,TRUE);
|
|
else
|
|
$flashsales = array();
|
|
|
|
if(Configuration::get('PRIVATESALES_HOTSPOT'))
|
|
$hotspotsales = SaleCore::getSales("hotspot",0,TRUE,FALSE,TRUE,'position','ASC',$id_category);
|
|
else
|
|
$hotspotsales = array();
|
|
|
|
if(Configuration::get('PRIVATESALES_PASTSALES'))
|
|
$pastsales = SaleCore::getSales("past",Configuration::get('PRIVATESALES_PASTLIMIT'),TRUE,FALSE,TRUE,'position','ASC',$id_category);
|
|
else
|
|
$pastsales = array();
|
|
|
|
if(Configuration::get('PRIVATESALES_FUTURESALES'))
|
|
$futuresales = SaleCore::getSales("future",Configuration::get('PRIVATESALES_FUTURELIMIT'),TRUE,FALSE,TRUE,'position','ASC',$id_category);
|
|
else
|
|
$futuresales = array();
|
|
|
|
$currentsales = SaleCore::getSales("current",0,TRUE,FALSE,TRUE,'position','ASC',$id_category);
|
|
|
|
$categories = SaleCategory::getCategory();
|
|
|
|
$this->addCSS(array(
|
|
_THEME_CSS_DIR_.'scenes.css' => 'all',
|
|
_THEME_CSS_DIR_.'category.css' => 'all',
|
|
_THEME_CSS_DIR_.'product_list.css' => 'all',
|
|
));
|
|
|
|
$customer = Context::getContext()->customer;
|
|
$alertedcat = SaleAlertMailCat::isAlertedCategory($customer->id,$id_category);
|
|
|
|
$this->context->smarty->assign(array(
|
|
'flashsales' => $flashsales,
|
|
'currentsales' => $currentsales,
|
|
'hotspotsales' => $hotspotsales,
|
|
'futuresales' => $futuresales,
|
|
'pastsales' => $pastsales,
|
|
'categories' => $categories,
|
|
'alertedcat' => $alertedcat,
|
|
'id_category' => $id_category,
|
|
'alias' => $alias,
|
|
'link_allsale' => $this->context->link->getModuleLink('privatesales', 'home'),
|
|
'popup_connection' => Configuration::get('PRIVATESALES_POPUP_CONNECTION'),
|
|
'link_img' => __PS_BASE_URI__.'modules/privatesales/img/',
|
|
'link_mod_img' => _PS_MODULE_DIR_.'modules/privatesales/img/'
|
|
));
|
|
$this->setTemplate('privatesales-home.tpl');
|
|
}
|
|
|
|
public function ajaxProcessSubmitAlert(){
|
|
$id_category = Tools::getValue('id_category');
|
|
if(!$id_category)
|
|
return Tools::jsonEncode(array('hasError' => true));
|
|
|
|
$customer = Context::getContext()->customer;
|
|
if(!$customer)
|
|
return Tools::jsonEncode(array('hasError' => true));
|
|
|
|
$alert = new SaleAlertMailCat();
|
|
$alert->id_privatesales_category = $id_category;
|
|
$alert->id_user = $customer->id;
|
|
$alert->email = $customer->email;
|
|
if($alert->add()){
|
|
return Tools::jsonEncode(array('hasError' => false));
|
|
}else{
|
|
return Tools::jsonEncode(array('hasError' => true));
|
|
}
|
|
}
|
|
} |