toutpratique/modules/categorieshome/categorieshome.php

83 lines
2.0 KiB
PHP
Raw Normal View History

2015-08-27 14:48:06 +02:00
<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
class Categorieshome extends Module
{
public function __construct()
{
$this->name = 'categorieshome';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Display category on Home');
$this->description = $this->l('Display category on Home with counter');
$this->secure_key = Tools::encrypt($this->name);
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install()
|| !$this->createTables()
2015-09-23 11:49:18 +02:00
|| !$this->registerHook('displayMenuBoutique')
2015-08-27 14:48:06 +02:00
|| !$this->registerHook('displayHome')
)
return false;
}
public function createTables ()
{
return true;
}
public function hookdisplayHome($params)
{
$id_lang = Context::getContext()->language->id;
$categories = $this->getCategories($id_lang);
array_map(function($category) use ($id_lang){
$category->nbProducts = $category->getProducts($id_lang, 1, 999999, null, null, true);
}, $categories);
$this->smarty->assign(array(
'categories' => $categories,
));
return $this->display(__FILE__, 'category.tpl');
}
2015-09-23 11:49:18 +02:00
public function hookdisplayMenuBoutique($params)
{
$id_lang = Context::getContext()->language->id;
$categories = $this->getCategories($id_lang);
array_map(function($category) use ($id_lang){
$category->nbProducts = $category->getProducts($id_lang, 1, 999999, null, null, true);
}, $categories);
2015-09-23 16:57:43 +02:00
$this->smarty->assign('categories', $categories);
2015-09-23 11:49:18 +02:00
return $this->display(__FILE__, 'category_menu.tpl');
}
2015-08-27 14:48:06 +02:00
private function getCategories($id_lang)
{
$collection = new Collection('Category', $id_lang);
$collection->where('id_parent', '=', '2');
2015-10-14 09:54:29 +02:00
$collection->where('active', '=', '1');
2015-08-27 14:48:06 +02:00
return $collection->getResults();
}
}