65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?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()
|
|
|| !$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');
|
|
}
|
|
|
|
private function getCategories($id_lang)
|
|
{
|
|
$collection = new Collection('Category', $id_lang);
|
|
$collection->where('id_parent', '=', '2');
|
|
return $collection->getResults();
|
|
}
|
|
|
|
}
|