name = 'ant_popover'; $this->tab = 'front_office_feature'; $this->version = '1.0.0'; $this->author = 'Antadis'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Ant Popover'); $this->description = $this->l('Ant popover popups'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?'); } /** * * @return boolean */ public function install() { if (!parent::install() || !$this->installDb() || !$this->registerHooks() ){ $this->uninstall(); return false; } return true; } public function registerHooks(){ return ( $this->registerHook('displayFooter') ); } public function installDb(){ return Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_popover_email`( `id_ant_popover` int(11) NOT NULL AUTO_INCREMENT, `email` varchar(255) NOT NULL, `date_add` datetime NOT NULL, PRIMARY KEY (`id_ant_popover`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); } public function getContent(){ $this->html = ''; $this->postProcess(); $this->displaySettingsForm(); return $this->html; } public function postProcess(){ if (Tools::isSubmit('ap_submitConf')){ $this->updateSettings(); } } private function displaySettingsForm(){ $form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Pop-up settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Display new customer popup'), 'name' => 'ANT_POPOVER_CUSTOMER_YIELD', 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'ANT_POPOVER_CUSTOMER_YIELD_on', 'value' => 1 ), array( 'id' => 'ANT_POPOVER_CUSTOMER_YIELD_off', 'value' => 0 ) ), ), array( 'type' => 'switch', 'label' => $this->l('Display cart popup'), 'name' => 'ANT_POPOVER_CART_YIELD', 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'ANT_POPOVER_CART_YIELD_on', 'value' => 1 ), array( 'id' => 'ANT_POPOVER_CART_YIELD_off', 'value' => 0 ) ), ), array( 'type' => 'switch', 'label' => $this->l('Display product popup'), 'name' => 'ANT_POPOVER_PRODUCT_YIELD', 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'ANT_POPOVER_PRODUCT_YIELD_on', 'value' => 1 ), array( 'id' => 'ANT_POPOVER_PRODUCT_YIELD_off', 'value' => 0 ) ), ), array( 'type' => 'switch', 'label' => $this->l('Afficher la pop up jeu concours'), 'name' => 'ANT_POPOVER_CONCOURS_YIELD', 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'ANT_POPOVER_CONCOURS_YIELD_on', 'value' => 1 ), array( 'id' => 'ANT_POPOVER_CONCOURS_YIELD_off', 'value' => 0 ) ), ), array( 'type' => 'switch', 'label' => $this->l('Afficher la pop up d\'entrée de site'), 'name' => 'ANT_POPOVER_PROMO_YIELD', 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'ANT_POPOVER_PROMO_YIELD_on', 'value' => 1 ), array( 'id' => 'ANT_POPOVER_PROMO_YIELD_off', 'value' => 0 ) ), ), ), 'submit' => array( 'title' => $this->l('Save') ) ) ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->module = $this; $helper->submit_action = 'ap_submitConf'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getSettingsVar() ); $this->html .= $helper->generateForm(array($form)); } public function getSettingsVar(){ return array( 'ANT_POPOVER_CUSTOMER_YIELD' => Configuration::get('ANT_POPOVER_CUSTOMER_YIELD'), 'ANT_POPOVER_PROMO_YIELD' => Configuration::get('ANT_POPOVER_PROMO_YIELD'), 'ANT_POPOVER_PROMO_YIELD_LINK' => Configuration::get('ANT_POPOVER_PROMO_YIELD_LINK'), 'ANT_POPOVER_PROMO_YIELD_TEXT' => Configuration::get('ANT_POPOVER_PROMO_YIELD_TEXT'), 'ANT_POPOVER_CART_YIELD' => Configuration::get('ANT_POPOVER_CART_YIELD'), 'ANT_POPOVER_PRODUCT_YIELD' => Configuration::get('ANT_POPOVER_PRODUCT_YIELD'), 'ANT_POPOVER_CONCOURS_YIELD' => Configuration::get('ANT_POPOVER_CONCOURS_YIELD'), ); } public function updateSettings(){ Configuration::updateValue('ANT_POPOVER_CUSTOMER_YIELD', Tools::getValue('ANT_POPOVER_CUSTOMER_YIELD')); Configuration::updateValue('ANT_POPOVER_PROMO_YIELD', Tools::getValue('ANT_POPOVER_PROMO_YIELD')); Configuration::updateValue('ANT_POPOVER_PROMO_YIELD_LINK', Tools::getValue('ANT_POPOVER_PROMO_YIELD_LINK')); Configuration::updateValue('ANT_POPOVER_PROMO_YIELD_TEXT', Tools::getValue('ANT_POPOVER_PROMO_YIELD_TEXT')); Configuration::updateValue('ANT_POPOVER_CART_YIELD', Tools::getValue('ANT_POPOVER_CART_YIELD')); Configuration::updateValue('ANT_POPOVER_PRODUCT_YIELD', Tools::getValue('ANT_POPOVER_PRODUCT_YIELD')); Configuration::updateValue('ANT_POPOVER_CONCOURS_YIELD', Tools::getValue('ANT_POPOVER_CONCOURS_YIELD')); } /** * * @return boolean */ public function uninstall() { if (!parent::uninstall()) return false; return true; } public function getPath($tpl_name){ if (file_exists(_PS_THEME_DIR_.'modules/ant_popover/views/templates/hook/'.$tpl_name.'.tpl')) return _PS_THEME_DIR_.'modules/ant_popover/views/templates/hook/'.$tpl_name.'.tpl'; else return _PS_MODULE_DIR_.'ant_popover/views/templates/hook/'.$tpl_name.'.tpl'; } public function getImgPath(){ if (file_exists(_THEME_DIR_.'modules/ant_popover/img/')) return _THEME_DIR_.'modules/ant_popover/img/'; else return _MODULE_DIR_.'ant_popover/img/'; } public function hookDisplayFooter($params){ $this->context->controller->addJS(_PS_MODULE_DIR_.'ant_popover/js/ant_popover.js'); $page_name = $this->smarty->getTemplateVars('page_name'); $cart = Context::getContext()->cart; $products = $cart->getProducts(); $display_cart_popup = false; $tmp_product = array(); $template_paths = array(); if (Configuration::get('ANT_POPOVER_CART_YIELD') && Validate::isLoadedObject($cart) && $page_name == 'order' && $products && !empty($products) ){ $template_paths[] = $this->getPath('ant_popover_cart_yield'); foreach ($products as $product) if (!isset($tmp_product['price_wt']) || $product['price_wt'] > $tmp_product['price_wt']) $tmp_product = $product; $ap_product_price = Product::getPriceStatic($tmp_product['id_product'], true, $tmp_product['id_product_attribute']); $ap_product_old_price = Product::getPriceStatic($tmp_product['id_product'], true, $tmp_product['id_product_attribute'], 6, null, false, false); $ap_product_reduction = (1 - ($ap_product_price / $ap_product_old_price))*100; $this->smarty->assign(array( 'ap_cart_product' => $tmp_product, 'ap_product_price' => $ap_product_price, 'ap_product_old_price' => $ap_product_old_price, 'ap_product_reduction' => $ap_product_reduction, )); $display_cart_popup = true; } if (Configuration::get('ANT_POPOVER_CUSTOMER_YIELD') && !$this->context->cookie->isLogged() && !$display_cart_popup && $page_name != 'authentication' ) $template_paths[] = $this->getPath('ant_popover_customer_yield'); if (Configuration::get('ANT_POPOVER_PRODUCT_YIELD') && $page_name == 'product') $template_paths[] = $this->getPath('ant_popover_product_yield'); if (Configuration::get('ANT_POPOVER_CONCOURS_YIELD') && ($page_name == 'index' || $page_name == 'module-privatesales-home')) $template_paths[] = $this->getPath('ant_popover_concours_yield'); if (Configuration::get('ANT_POPOVER_PROMO_YIELD') && !$display_cart_popup) { $template_paths[] = $this->getPath('ant_popover_promo_yield'); $this->smarty->assign(array( 'ap_home_link' => Configuration::get('ANT_POPOVER_PROMO_YIELD_LINK'), 'ap_home_text_link'=> Configuration::get('ANT_POPOVER_PROMO_YIELD_TEXT') )); } $this->smarty->assign(array( 'ap_paths' => $template_paths, 'ap_img_dir' => $this->getImgPath(), 'ap_ajax_path' => '/modules/ant_popover/ap_ajax.php' )); return $this->display(__FILE__, 'ap_footer.tpl'); } public function hookDisplayPopupY(){ $this->context->controller->addJS(_PS_MODULE_DIR_.'ant_popover/js/ant_popover.js'); $page_name = $this->smarty->getTemplateVars('page_name'); $cart = Context::getContext()->cart; $products = $cart->getProducts(); $display_cart_popup = false; $tmp_product = array(); $template_paths = array(); if (Configuration::get('ANT_POPOVER_CART_YIELD') && Validate::isLoadedObject($cart) && $page_name == 'order' && $products && !empty($products) ){ $template_paths[] = $this->getPath('ant_popover_cart_yield'); foreach ($products as $product) if (!isset($tmp_product['price_wt']) || $product['price_wt'] > $tmp_product['price_wt']) $tmp_product = $product; $ap_product_price = Product::getPriceStatic($tmp_product['id_product'], true, $tmp_product['id_product_attribute']); $ap_product_old_price = Product::getPriceStatic($tmp_product['id_product'], true, $tmp_product['id_product_attribute'], 6, null, false, false); $ap_product_reduction = (1 - ($ap_product_price / $ap_product_old_price))*100; $this->smarty->assign(array( 'ap_cart_product' => $tmp_product, 'ap_product_price' => $ap_product_price, 'ap_product_old_price' => $ap_product_old_price, 'ap_product_reduction' => $ap_product_reduction, )); $display_cart_popup = true; } if (Configuration::get('ANT_POPOVER_CUSTOMER_YIELD') && !$this->context->cookie->isLogged() && !$display_cart_popup && $page_name != 'authentication' ) $template_paths[] = $this->getPath('ant_popover_customer_yield'); if (Configuration::get('ANT_POPOVER_PRODUCT_YIELD') && $page_name == 'product') $template_paths[] = $this->getPath('ant_popover_product_yield'); if (Configuration::get('ANT_POPOVER_CONCOURS_YIELD') && ($page_name == 'index' || $page_name == 'module-privatesales-home')) $template_paths[] = $this->getPath('ant_popover_concours_yield'); if (Configuration::get('ANT_POPOVER_PROMO_YIELD') && !$display_cart_popup) { $template_paths[] = $this->getPath('ant_popover_promo_yield'); $this->smarty->assign(array( 'ap_home_link' => Configuration::get('ANT_POPOVER_PROMO_YIELD_LINK'), 'ap_home_text_link'=> Configuration::get('ANT_POPOVER_PROMO_YIELD_TEXT') )); } $this->smarty->assign(array( 'ap_paths' => $template_paths, 'ap_img_dir' => $this->getImgPath(), 'ap_ajax_path' => '/modules/ant_popover/ap_ajax.php' )); return $this->display(__FILE__, 'ap_footer.tpl'); } }