name = 'homeproduct'; $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 product on Home'); $this->description = $this->l('Display product on Home'); $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->registerHook('displayHomeProduct') ) return false; } public function hookdisplayHomeProduct($params) { $products = self::loadProduct(Context::getContext()->language->id, 2); $this->smarty->assign(array( 'products' => $products, )); return $this->display(__FILE__, 'home.tpl'); } public static function loadProduct($id_lang, $limit) { $collection = new Collection('Product', $id_lang); $collection->where('active', '=', 1); $collection->where('online_only', '=', 1); $collection->where('online_only', '=', 1); $collection->setPageSize($limit); $products = $collection->getResults(); $products = array_map(function($elem) { $elem = $elem->loadReductionInfo(); return get_object_vars($elem); }, $products); return $products; } }