privilegedemarque/override/controllers/front/CategoryController.php
Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

87 lines
3.0 KiB
PHP
Executable File

<?php
class CategoryController extends CategoryControllerCore
{
public function initContent(){
parent::initContent();
$sale = SaleCore::loadSaleFromCategoryId($this->category->id);
if($sale->news){
$this->addCSS(_THEME_CSS_DIR_.'category_new.css');
}
if(!empty($sale)
&& $this->nbProducts == 1)
{
if (Tools::isSubmit('back')){
$link = Context::getContext()->link->getPageLink('index');
Tools::redirect($link.'#sale_'.$sale->id_privatesales);
}
$product = reset($this->cat_products);
$link = Context::getContext()->link->getProductLink($product);
Tools::redirect($link);
}
}
/**
* Assign list of products template vars
*/
public function assignProductList()
{
$hookExecuted = false;
Hook::exec('actionProductListOverride', array(
'nbProducts' => &$this->nbProducts,
'catProducts' => &$this->cat_products,
'hookExecuted' => &$hookExecuted,
));
// The hook was not executed, standard working
if (!$hookExecuted)
{
$this->context->smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
if ($this->category->id == 550) {
// special vente à tout prix id 550
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, 'DESC');
} else {
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
}
}
// Hook executed, use the override
else
// Pagination must be call after "getProducts"
$this->pagination($this->nbProducts);
Hook::exec('actionProductListModifier', array(
'nb_products' => &$this->nbProducts,
'cat_products' => &$this->cat_products,
));
$sale = SaleCore::loadSaleFromCategoryId($this->category->id);
if ($this->context->customer->isLogged()){
foreach ($this->cat_products as &$product){
if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity']))
$product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];
$res = Db::getInstance()->getValue("
SELECT COUNT(*)
FROM `"._DB_PREFIX_."privatesales_concours` as psc
LEFT JOIN `"._DB_PREFIX_."privatesales` as ps ON (ps.`id_privatesales` = psc.`id_privatesales`)
WHERE psc.`id_product` = ".$product['id_product']."
AND psc.`id_customer` = ".$this->context->customer->id."
AND DATE_ADD(ps.`date_start`, INTERVAL ps.`concours_delay` HOUR) >= NOW()
");
if($res)
$product['register_for_game'] = 1;
else
$product['register_for_game'] = 0;
}
} else {
$product['register_for_game'] = 0;
}
$this->addColorsToProductList($this->cat_products);
$this->context->smarty->assign('nb_products', $this->nbProducts);
$this->context->smarty->assign('sale_concours',(isset($sale->concours)?$sale->concours:false));
}
}