147 lines
5.7 KiB
PHP
Executable File
147 lines
5.7 KiB
PHP
Executable File
<?php
|
|
class CategoryController extends CategoryControllerCore {
|
|
public function preProcess() {
|
|
global $site_version_front; $cookie;
|
|
|
|
parent::preProcess();
|
|
|
|
if(Module::isInstalled('privatesales')) {
|
|
include_once dirname(__FILE__).'/../../modules/privatesales/Sale.php';
|
|
$id_category = Tools::getValue('id_category');
|
|
$sale = Sale::getSaleFromCategory($id_category);
|
|
|
|
$other_sales = array();
|
|
if(!empty($sale)){
|
|
$other_sales = $sale->getOthersSales(true, null, null, 'current', false, Configuration::get('PRIVATES_SHOW_PUBLIC'), '`date_start` desc', $site_version_front);
|
|
foreach ($other_sales as $key => &$s) {
|
|
if(file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$s['id_category'].'_thumb_vp_'.$cookie->id_lang.'.jpg')) {
|
|
$s['is_thumb_img_lang'] = true;
|
|
} elseif (file_exists(_PS_ROOT_DIR_.'/img/c/'.(int)$s['id_category'].'_thumb_vp.jpg')) {
|
|
$s['is_thumb_img'] = true;
|
|
} else {
|
|
$s['is_thumb_img'] = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!in_array($site_version_front, $sale->versions)) {
|
|
Tools::redirect('/');
|
|
}
|
|
|
|
self::$smarty->assign(array(
|
|
'sale' => $sale,
|
|
'category' => $this->category,
|
|
'HOOK_PRIVATESALES_CATEGORY' => Module::hookExec('privatesales_category', array('sale' => $sale)),
|
|
'HOOK_LEFT_COLUMN_VP' => Module::hookExec('displayleftVP', array('id_category' => $id_category)),
|
|
'is_sale_home' => ($sale? $sale->id_category == $id_category: FALSE),
|
|
'other_sales' => $other_sales,
|
|
'last_qties' => (int)Configuration::get('PS_LAST_QTIES'),
|
|
'HOOK_PRIVATESALES_LISTING' => Module::hookExec('privatesales_listing', array('other_sales_category' => $other_sales, 'futuresales' => array())),
|
|
));
|
|
}
|
|
}
|
|
|
|
public function setMedia() {
|
|
parent::setMedia();
|
|
|
|
global $css_files;
|
|
$css_files = array_slice($css_files, 0, 1);
|
|
global $js_files;
|
|
$js_files = array_slice($js_files, 0, 1);
|
|
$js_files[] = _PS_JS_DIR_.'jquery/jquery.scrollTo-1.4.2-min.js';
|
|
$js_files[] = _PS_JS_DIR_.'jquery/jquery.serialScroll-1.2.2-min.js';
|
|
$js_files[] = _PS_JS_DIR_.'/jquery.flexslider-min.js';
|
|
}
|
|
|
|
public function productListAssign() {
|
|
global $cookie;
|
|
|
|
$hookExecuted = false;
|
|
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
|
|
if(!$hookExecuted) { // The hook was not executed, standard working
|
|
self::$smarty->assign('categoryNameComplement', '');
|
|
$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, TRUE, TRUE, FALSE, 1, TRUE/*, ((($sale = self::$smarty->getTemplateVars('sale')) !== NULL) && (int) $sale->id > 0 && $sale->avail_only == TRUE? TRUE: FALSE)*/);
|
|
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
|
|
$this->cat_products = $this->category->getProducts(
|
|
(int)(self::$cookie->id_lang),
|
|
(int)($this->p),
|
|
(int)($this->n),
|
|
$this->orderBy,
|
|
$this->orderWay,
|
|
FALSE,
|
|
TRUE,
|
|
FALSE,
|
|
1,
|
|
TRUE/*,
|
|
(
|
|
(
|
|
(
|
|
$sale = self::$smarty->getTemplateVars('sale')
|
|
) !== NULL
|
|
)
|
|
&& (int) $sale->id > 0 && $sale->avail_only == TRUE? TRUE: FALSE
|
|
)*/
|
|
);
|
|
|
|
$id_products = array();
|
|
foreach($this->cat_products as $key => $p) {
|
|
$id_products[] = $p['id_product'];
|
|
}
|
|
$attributes = array();
|
|
$id_attributes = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT pa.`id_product`, pa.`quantity`, ag.`public_name` as `group`, al.`name`, al.`id_attribute`
|
|
FROM `'._DB_PREFIX_.'product_attribute` pa, `'._DB_PREFIX_.'product_attribute_combination` ac, `'._DB_PREFIX_.'attribute` a, `'._DB_PREFIX_.'attribute_lang` al, `'._DB_PREFIX_.'attribute_group_lang` ag
|
|
WHERE pa.`id_product` IN ('.implode(', ', $id_products).')
|
|
AND ac.`id_product_attribute` = pa.`id_product_attribute`
|
|
AND al.`id_attribute` = ac.`id_attribute`
|
|
AND al.`id_lang` = '.(int) $cookie->id_lang.'
|
|
AND a.`id_attribute` = al.`id_attribute`
|
|
AND ag.`id_attribute_group` = a.`id_attribute_group`
|
|
AND ag.`id_lang` = '.(int) $cookie->id_lang.'
|
|
AND pa.`quantity` > 0
|
|
AND ag.`id_attribute_group` IN(75, 9, 272, 172)
|
|
ORDER BY pa.`id_product` ASC, ag.`public_name` ASC, al.`name` ASC
|
|
') as $attr) {
|
|
if(!isset($attributes[$attr['id_product']])) {
|
|
$attributes[$attr['id_product']] = array();
|
|
}
|
|
if(!isset($attributes[$attr['id_product']][$attr['group']])) {
|
|
$attributes[$attr['id_product']][$attr['group']] = array();
|
|
}
|
|
if(!isset($id_attributes[$attr['id_product']])) {
|
|
$id_attributes[$attr['id_product']] = array();
|
|
}
|
|
|
|
if(!in_array($attr['id_attribute'], $id_attributes[$attr['id_product']])) {
|
|
$attributes[$attr['id_product']][$attr['group']][] = array(
|
|
'name' => $attr['name'],
|
|
'quantity' => $attr['quantity'],
|
|
);
|
|
$id_attributes[$attr['id_product']][] = $attr['id_attribute'];
|
|
}
|
|
}
|
|
|
|
$images = array();
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT i.`id_product`, i.`cover`, i.`id_image`, il.`legend`, i.`position`
|
|
FROM `'._DB_PREFIX_.'image` i
|
|
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($cookie->id_lang).')
|
|
WHERE i.`id_product` IN ('.implode(', ', $id_products).')
|
|
ORDER BY `position`
|
|
') as $img) {
|
|
if(!isset($images[$img['id_product']])) {
|
|
$images[$img['id_product']] = array();
|
|
}
|
|
$images[$img['id_product']][] = $img;
|
|
}
|
|
|
|
self::$smarty->assign('images', $images);
|
|
self::$smarty->assign('categoryProductAttributes', $attributes);
|
|
} else { // Hook executed, use the override
|
|
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
|
|
}
|
|
self::$smarty->assign('nb_products', (int)$this->nbProducts);
|
|
}
|
|
}
|