name = 'cms_pack'; $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('Product pack for CMS ANTADIS'); $this->description = $this->l('Manage your product pack in CMS Antadis'); $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('footer') || !$this->registerHook('displayBottomProductCms') || !$this->registerHook('displayleftPostCms') ) return false; } public function createTables (){ return true; } public function hookdisplayFooter() { $this->context->controller->addJS(($this->_path).'pack.js', 'all'); return $this->display(__FILE__, 'lightbox_footer.tpl'); } public function hookdisplayleftPostCms($params) { $pack = $this->loadPackForCMS($params['id_cmspost']); if($pack) { $this->smarty->assign(array( 'pack' => $pack, )); return $this->display(__FILE__, 'pack_left.tpl'); } } public function hookdisplayBottomProductCms($params) { $pack = $this->loadPackForCMS($params['id_cmspost']); if ($pack) { $this->smarty->assign(array( 'pack' => $pack, )); return $this->display(__FILE__, 'pack_bottom.tpl'); } } public function loadPackForCMS($id_cmspost) { $id_pack = Db::getInstance()->getValue(' SELECT `id_pack` FROM `'._DB_PREFIX_.'cmsps_posts_relation_pack` WHERE `id_post` = '.(int)$id_cmspost ); $result = array(); $id_lang = Context::getContext()->language->id; if ($id_pack) { $pack = new CmsPack($id_pack); $pack->loadProducts(); $collection_product = new Collection('Product', $id_lang); $collection_product->where('id_product', 'IN', $pack->products); $collection_product->where('active', '=', 1); $products = $collection_product->getResults(); $products = array_map(function($product) { return $product->loadReductionInfo(); }, $products); $result['products'] = $products; $price = array_map(function($product) { return floatval($product->price); }, $result['products']); $result['price_total'] = array_sum($price); $result['pack'] = $pack->title; if ($pack->id_cart_rule) { $result['remise'] = true; $result['remise_percent'] = $pack->getPercentageReduction(); } else { $result['remise']= false; } } return $result; } }