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('displayMenuBoutique') || !$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'); } 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); $this->smarty->assign('categories', $categories); return $this->display(__FILE__, 'category_menu.tpl'); } private function getCategories($id_lang) { $collection = new Collection('Category', $id_lang); $collection->where('id_parent', '=', '2'); $collection->where('active', '=', '1'); $collection->orderBy('position', 'ASC'); return $collection->getResults(); } }