* @copyright 2007-2015 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) { exit; } if (!class_exists('WsCoupons')) { include_once(dirname(__FILE__).'/classes/WsCoupons.php'); } class Advansedcoupons extends Module { protected $config_form = false; public function __construct() { $this->name = 'advansedcoupons'; $this->tab = 'pricing_promotion'; $this->version = '2.7.1'; $this->author = 'Snegurka'; $this->need_instance = 0; $this->module_key = 'c61fd3d17a6dcbde55168a1ecfba4827'; /** * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Advanced Coupons'); $this->description = $this->l('display coupons in left column'); if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $this->base_dir_ssl = _PS_BASE_URL_SSL_.__PS_BASE_URI__; } else { $this->base_dir_ssl = _PS_BASE_URL_.__PS_BASE_URI__; } ## prestashop 1.7 ## if (version_compare(_PS_VERSION_, '1.7', '>')) { $smarty = Context::getContext()->smarty; $smarty->assign( array( $this->name.'is17' => 1, 'base_dir' => $this->base_dir_ssl, ) ); } else { $smarty = $this->context->smarty; $smarty->assign( array( $this->name.'is17' => 0, 'base_dir' => $this->base_dir_ssl, ) ); } ## prestashop 1.7 ## $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); $this->dir_mails = _PS_MODULE_DIR_.'advansedcoupons/mails/'; $this->log_directory = dirname(__FILE__).'/logs/'; if (!Module::isInstalled('advancedloyalty')) { $this->dir_loyalty_state = _PS_MODULE_DIR_.'/advansedcoupons/classes/WsAdvLoyaltyStateModule.php'; $this->dir_loyalty = _PS_MODULE_DIR_.'/advansedcoupons/classes/WsAdvLoyaltyModule.php'; } else { $this->dir_loyalty_state = _PS_MODULE_DIR_.'/advancedloyalty/classes/WsAdvLoyaltyStateModule.php'; $this->dir_loyalty = _PS_MODULE_DIR_.'/advancedloyalty/classes/WsAdvLoyaltyModule.php'; } } private function instanceDefaultStates() { include_once($this->dir_loyalty_state); /* Recover default loyalty status save at module installation */ $this->loyaltyStateDefault = new WsAdvLoyaltyStateModule(WsAdvLoyaltyStateModule::getDefaultId()); $this->loyaltyStateValidation = new WsAdvLoyaltyStateModule(WsAdvLoyaltyStateModule::getValidationId()); $this->loyaltyStateCancel = new WsAdvLoyaltyStateModule(WsAdvLoyaltyStateModule::getCancelId()); $this->loyaltyStateConvert = new WsAdvLoyaltyStateModule(WsAdvLoyaltyStateModule::getConvertId()); $this->loyaltyStateNoneAward = new WsAdvLoyaltyStateModule(WsAdvLoyaltyStateModule::getNoneAwardId()); } /** * Don't forget to create update methods if needed: * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update */ public function install() { include(dirname(__FILE__).'/sql/install.php'); $defaultTranslations = array('en' => 'Reward', 'fr' => 'Récompense'); $desc_acc = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Reward')); $desc_bthd = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Reward bthd')); $desc_f_ord = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Reward 2')); $desc_ord = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Reward 3')); foreach (Language::getLanguages() as $language) { if (isset($defaultTranslations[$language['iso_code']])) { $desc_acc[(int)$language['id_lang']] = $defaultTranslations[$language['iso_code']]; $desc_bthd[(int)$language['id_lang']] = $defaultTranslations[$language['iso_code']]; $desc_ord[(int)$language['id_lang']] = $defaultTranslations[$language['iso_code']]; $desc_f_ord[(int)$language['id_lang']] = $defaultTranslations[$language['iso_code']]; } } /* Define a default value for fixed amount vouchers, for each currency */ foreach (Currency::getCurrencies() as $currency) { Configuration::updateValue('COUPON_DISCOUNT_VALUE_ACC_'.(int)($currency['id_currency']), 5); Configuration::updateValue('COUPON_DISCOUNT_VALUE_BTHD_'.(int)($currency['id_currency']), 5); Configuration::updateValue('COUPON_DISCOUNT_VALUE_ORD_'.(int)($currency['id_currency']), 5); Configuration::updateValue('COUPON_DISCOUNT_VALUE_F_ORD_'.(int)($currency['id_currency']), 5); } /* Define a default value for the percentage vouchers */ Configuration::updateValue('COUPON_MIN_ORDER', 0); Configuration::updateValue('COUPON_MIN_F_ORDER', 0); Configuration::updateValue('COUPON_ACC_VOUCHER', true); Configuration::updateValue('COUPON_DISCOUNT_TYPE_ACC', 1); Configuration::updateValue('COUPON_PERCENTAGE_ACC', 5); Configuration::updateValue('COUPON_BTHD_VOUCHER', true); Configuration::updateValue('COUPON_DISCOUNT_TYPE_BTHD', 1); Configuration::updateValue('COUPON_PERCENTAGE_BTHD', 5); Configuration::updateValue('COUPON_ORDER_VOUCHER', true); Configuration::updateValue('COUPON_DISCOUNT_TYPE_ORD', 1); Configuration::updateValue('COUPON_PERCENTAGE_ORD', 5); Configuration::updateValue('COUPON_F_ORDER_VOUCHER', true); Configuration::updateValue('COUPON_GUEST_VOUCHER', true); Configuration::updateValue('COUPON_DISCOUNT_TYPE_F_ORD', 1); Configuration::updateValue('COUPON_PERCENTAGE_F_ORD', 5); Configuration::updateValue('COUPON_VOUCHER_DESCR_ACC', $desc_acc); Configuration::updateValue('COUPON_VOUCHER_DESCR_BTHD', $desc_bthd); Configuration::updateValue('COUPON_VOUCHER_DESCR_ORD', $desc_ord); Configuration::updateValue('COUPON_VOUCHER_DESCR_F_ORD', $desc_f_ord); Configuration::updateValue('COUPON_ORD_STATE_GENERATION', serialize(array(2))); Configuration::updateValue('COUPON_F_ORD_STATE_GENERATION', serialize(array(2))); Configuration::updateValue('COUPON_VOUCHER_DURATION_ACC', 365); Configuration::updateValue('COUPON_VOUCHER_DURATION_BTHD', 365); Configuration::updateValue('COUPON_VOUCHER_DURATION_ORD', 365); Configuration::updateValue('COUPON_VOUCHER_DURATION_F_ORD', 365); Configuration::updateValue('COUPON_HIGHLIGHT_ACC', true); Configuration::updateValue('COUPON_HIGHLIGHT_BTHD', true); Configuration::updateValue('COUPON_HIGHLIGHT_ORD', true); Configuration::updateValue('COUPON_HIGHLIGHT_F_ORD', true); Configuration::updateValue('COUPON_CUMULAT_ACC', true); Configuration::updateValue('COUPON_CUMULAT_BTHD', true); Configuration::updateValue('COUPON_CUMULAT_ORD', true); Configuration::updateValue('COUPON_CUMULAT_F_ORD', true); Configuration::updateValue('COUPON_TAX_ACC', 1); Configuration::updateValue('COUPON_TAX_BTHD', 1); Configuration::updateValue('COUPON_TAX_ORD', 1); Configuration::updateValue('COUPON_TAX_F_ORD', 1); Configuration::updateValue('COUPON_WSPECIAL_ACC', true); Configuration::updateValue('COUPON_WSPECIAL_BTHD', true); Configuration::updateValue('COUPON_WSPECIAL_ORD', true); Configuration::updateValue('COUPON_WSPECIAL_F_ORD', true); Configuration::updateValue('COUPON_VOUCHER_MIN_ACC', 0); Configuration::updateValue('COUPON_VOUCHER_MIN_BTHD', 0); Configuration::updateValue('COUPON_VOUCHER_MIN_F_ORD', 0); Configuration::updateValue('COUPON_VOUCHER_MIN_ORD', 0); Configuration::updateValue('COUPON_CRON_TYPE', 1); Configuration::updateValue('COUPON_BTHD_BATCHLASTDATE', 0); if (!Module::isInstalled('advancedloyalty') and !Module::isInstalled('referralbyphone')) { include(dirname(__FILE__).'/sql/install_loyalty.php'); include_once($this->dir_loyalty_state); WsAdvLoyaltyStateModule::insertDefaultData(); Configuration::updateValue('ADVANCEDLOYALTY_POINT_VALUE', '0.20'); Configuration::updateValue('ADVANCEDLOYALTY_MINIMAL', 0); Configuration::updateValue('ADVANCEDLOYALTY_POINT_RATE', '10'); Configuration::updateValue('ADVANCEDLOYALTY_NONE_AWARD', '1'); Configuration::updateValue('ADVANCEDLOYALTY_TAX', '0'); $defaultLoyaltyTranslations = array('en' => 'Loyalty reward', 'fr' => 'Récompense fidélité'); $conf = array((int)Configuration::get('PS_LANG_DEFAULT') => $this->l('Loyalty reward')); foreach (Language::getLanguages() as $language) { if (isset($defaultLoyaltyTranslations[$language['iso_code']])) { $conf[(int)$language['id_lang']] = $defaultLoyaltyTranslations[$language['iso_code']]; } } Configuration::updateValue('ADVANCEDLOYALTY_VOUCHER_DETAILS', $conf); $category_config = ''; $categories = Category::getSimpleCategories((int)Configuration::get('PS_LANG_DEFAULT')); foreach ($categories as $category) { $category_config .= (int)$category['id_category'].','; } $category_config = rtrim($category_config, ','); Configuration::updateValue('ADVANCEDLOYALTY_VOUCHER_CATEGORY', $category_config); } $this->installModuleTab(); return parent::install() && $this->registerHook('orderConfirmation') && $this->registerHook('updateOrderStatus') && $this->registerHook('shoppingCart') && $this->registerHook('newOrder') && $this->registerHook('createAccount') && $this->registerHook('customerAccount') && $this->registerHook('adminCustomers') && $this->registerHook('backOfficeHeader') && $this->registerHook('extraRight') && $this->registerHook('header') && $this->registerHook('top') && $this->registerHook('displayLeftColumn'); } private function installModuleTab() { if (version_compare(_PS_VERSION_, '1.7', '<')) { $myTab = array( 'tabClassName' => 'AdminAdvansedCouponsRules', 'tabParentName' => 'AdminPriceRule', 'tabName' => $this->l('Advanced Coupons'), ); } else { $myTab = array( 'tabClassName' => 'AdminAdvansedCouponsRules', 'tabParentName' => 'AdminCatalog', 'tabName' => $this->l('Advanced Coupons'), ); } $id_tab = Tab::getIdFromClassName($myTab['tabClassName']); if (!$id_tab) { $tab = new Tab(); $tab->class_name = $myTab['tabClassName']; if ($myTab['tabParentName']) { $tab->id_parent = Tab::getIdFromClassName($myTab['tabParentName']); } else { $tab->id_parent = -1; } $tab->module = $this->name; //Initialize multilang configuration values $translations = array(); $translations['AdminAdvansedCouponsRules']['en'] = 'Advanced Coupons'; $translations['AdminAdvansedCouponsRules']['fr'] = 'Coupons avancés'; $translations['AdminAdvansedCouponsRules']['es'] = 'Cupones Avanzados'; $languages = Language::getLanguages(false); foreach ($languages as $lang) { $tab->name[$lang['id_lang']] = isset($translations[$myTab['tabClassName']][$lang['iso_code']]) ? $translations[$myTab['tabClassName']][$lang['iso_code']] : $translations[$myTab['tabClassName']]['en']; } $tab->add(); } return true; } public function uninstall() { include(dirname(__FILE__).'/sql/uninstall.php'); $tab_id = Tab::getIdFromClassName("AdminAdvansedCouponsRules"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } return parent::uninstall(); } /** * Load the configuration form */ public function getContent() { $this->_html = ''; $this->instanceDefaultStates(); $this->_postValidation(); if (!sizeof($this->_errors)) { $this->_html .= $this->postProcess(); } else { foreach ($this->_errors as $err) { $this->_html .= $err; } } $this->context->controller->addJS(array ( _MODULE_DIR_.'advansedcoupons/views/js/back.js', _PS_JS_DIR_.'admin-categories-tree.js', )); $this->_html .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl'); $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= ''; $this->_html .= '
'; $this->_html .= '
'.$this->renderWelCouponsForm().'
'; $this->_html .= '
'.$this->renderBthdCouponsForm().'
'; $this->_html .= '
'.$this->renderFOCouponsForm().'
'; $this->_html .= '
'.$this->renderOrdCouponsForm().'
'; $this->_html .= '
'; $this->context->smarty->assign( array( 'coupoon_log' => $this->getLogsFile(), 'module_name' => $this->name, ) ); $this->_html .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/log.tpl'); $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= $this->renderLoyalForm(); $this->_html .= '
'; $this->_html .= '
'; $this->context->smarty->assign( array( 'module_name' => $this->name, ) ); $this->_html .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/help.tpl'); $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
'; return $this->_html; } /** * Create the form that will be displayed in the configuration of your module. */ protected function renderWelCouponsForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitCouponsAcc'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $countries = self::getCountriesRestriction('acc'); $helper->tpl_vars = array( 'currencies' => Currency::getCurrencies(), 'category_tree_html' => self::getCategoryRestriction('acc'), 'cr_countries_unselected' => $countries['unselected'], 'cr_countries_selected' => $countries['selected'], 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm($this->getConfigWelForm()); } protected function renderBthdCouponsForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitCouponsBthd'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $countries = self::getCountriesRestriction('bthd'); $helper->tpl_vars = array( 'currencies' => Currency::getCurrencies(), 'category_tree_html' => self::getCategoryRestriction('bthd'), 'cr_countries_unselected' => $countries['unselected'], 'cr_countries_selected' => $countries['selected'], 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm($this->getConfigBthdForm()); } protected function renderFOCouponsForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitCouponsFO'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $countries = self::getCountriesRestriction('f_ord'); $helper->tpl_vars = array( 'currencies' => Currency::getCurrencies(), 'category_tree_html' => self::getCategoryRestriction('f_ord'), 'cr_countries_unselected' => $countries['unselected'], 'cr_countries_selected' => $countries['selected'], 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm($this->getConfigFOForm()); } protected function renderOrdCouponsForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitCouponsOrd'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $countries = self::getCountriesRestriction('ord'); $helper->tpl_vars = array( 'currencies' => Currency::getCurrencies(), 'category_tree_html' => self::getCategoryRestriction('ord'), 'cr_countries_unselected' => $countries['unselected'], 'cr_countries_selected' => $countries['selected'], 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm($this->getConfigOrdForm()); } protected function getCategoryRestriction($type) { $categoriesbdd = array (); $b_type = Tools::strtoupper($type); if (trim(Configuration::get('COUPON_CR_CATEGORIES_'.$b_type)) != '') { $categoriesbdd = explode(',', Configuration::get('COUPON_CR_CATEGORIES_'.$b_type)); } $tree = new HelperTreeCategories('categories-tree'.$type, $this->l('Filter by category')); $tree->setRootCategory((Shop::getContext() == Shop::CONTEXT_SHOP ? Category::getRootCategory()->id_category : 0))->setUseCheckBox(true); $tree->setAttribute('is_category_filter', true); $tree->setInputName('categoryBox_'.$type); if (Tools::getValue('categoryBox_'.$type) && (int)Tools::getValue('cr_iscategory_'.$type) == 1) { $tree->setSelectedCategories(Tools::getValue('categoryBox_'.$type)); } else { $tree->setSelectedCategories($categoriesbdd); } return $tree->render(); } protected function getCountriesRestriction($type) { $b_type = Tools::strtoupper($type); $countries = Configuration::get('COUPON_COUNTRIES_'.$b_type); $tt_countries = array(); $tt_countries['unselected'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_country,cl.name FROM '._DB_PREFIX_.'country c LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (c.id_country = cl.id_country AND cl.id_lang = '.(int)$this->context->cookie->id_lang.') '.(trim($countries) != '' ? ' WHERE c.active = 1 AND c.id_country not in ('.$countries.')' : '')); $tt_countries['selected'] = array (); if (trim($countries) != '') { $tt_countries['selected'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_country,cl.name FROM '._DB_PREFIX_.'country c LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (c.id_country = cl.id_country AND cl.id_lang = '.(int)$this->context->cookie->id_lang.') WHERE c.id_country in ('.$countries.')'); } return $tt_countries; } protected function renderLoyalForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitCouponLoyalty'; $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( 'currencies' => Currency::getCurrencies(), 'fields_value' => $this->getLoyaltyFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm($this->getLoyaltyForm()); } /** * Create the structure of your form. */ protected function getConfigWelForm() { $fields_form = array(); $fields_form[0] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Welcome coupon'), 'icon' => 'icon-money', ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Generate a voucher when the customer creates an account'), 'name' => 'account_voucher', 'is_bool' => true, 'required' => true, 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Voucher description'), 'name' => 'voucher_descr_acc', 'required' => true, 'lang' => true, ), array( 'type' => 'radio', 'label' => $this->l('Voucher type :'), 'name' => 'discount_type_acc', 'required' => true, 'class' => 't', 'values' => array( array( 'id' => 'discount_type1', 'value' => 1, 'label' => $this->l('Voucher offering a percentage')), array( 'id' => 'discount_type2', 'value' => 2, 'label' => $this->l('Voucher offering a fixed amount (by currency)')), ), ), array( 'type' => 'text', 'label' => $this->l('Percentage'), 'name' => 'discount_value_percentage_acc', 'class' => 'fixed-width-xs', 'required' => true, 'suffix' => '%' ), array( 'type' => 'discount_value', 'label' => $this->l('Voucher amount'), 'name' => 'discount_value_acc', 'class' => 'discount_value_acc', 'required' => true, 'id' => 'discount_value_acc', ), array( 'type' => 'select', 'label' => $this->l('Voucher tax'), 'name' => 'discount_tax_acc', 'options' => array( 'query' => array( array('id' => 0, 'name' => $this->l('Tax excluded')), array('id' => 1, 'name' => $this->l('Tax included')) ), 'id' => 'id', 'name' => 'name', ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsAcc', ), ), ); $fields_form[1] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Extra options'), 'icon' => 'icon-wrench', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Validity of the voucher (in days)'), 'name' => 'voucher_duration_acc', 'class' => 'fixed-width-xs', 'suffix' => 'days', 'desc' => 'The number of validity days of the voucher.', ), array( 'type' => 'text', 'label' => $this->l('Voucher Prefix'), 'name' => 'prefix_acc', 'class' => 'fixed-width-xs', ), array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be used'), 'name' => 'voucher_min_acc', 'class' => 'fixed-width-xs', 'desc' => 'You can choose a minimum amount for the cart either with or without the taxes.', ), array( 'type' => 'category_restriction', 'label' => $this->l('Restrictions'), 'name' => 'cr_iscategory_acc', 'class' => 'category_restriction_acc', 'id' => 'category_restriction_acc', 'value' => Tools::getValue('cr_iscategory_acc', Configuration::get('COUPON_CR_ISCATEGORY_ACC')), ), array( 'type' => 'country_restriction', 'label' => $this->l(' '), 'name' => 'cr_iscountry_acc', 'class' => 'country_select_acc', 'id' => 'country_restriction_acc', 'value' => Tools::getValue('cr_iscountry_acc', Configuration::get('COUPON_CR_ISCOUNTRY_ACC')), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Exclude discounted products'), 'desc' => 'If enabled, the voucher will not apply to products already on sale (only for PrestaShop 1.7).', 'name' => 'with_special_acc', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'with_special_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'with_special_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Show the welcome voucher in the shopping cart'), 'name' => 'highlight_acc', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'highlight_acc_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'highlight_acc_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Cumulative with other vouchers'), 'name' => 'cumulat_acc', 'desc' => 'If enabled, a customer can use several vouchers for a same order.', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'cumulat_acc_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'cumulat_acc_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsAcc', ), ), ); if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) { $fields_form[2]= array( 'form' => array( 'legend' => array( 'title' => $this->l('Multishop options'), 'icon' => 'icon-random', ), 'input' => array( array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Active in all stores'), 'name' => 'multishop_acc', 'desc' => 'A coupon created in one store will be available in all group stores.', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'multishop_acc_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'multishop_acc_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), ), ); } return $fields_form; } protected function getConfigBthdForm() { $fields_form = array(); $fields_form[0] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Birthday coupon'), 'icon' => 'icon-birthday-cake', ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Create a voucher in the customer\'s birthday'), 'name' => 'bthd_voucher', 'is_bool' => true, 'values' => array( array( 'id' => 'active_bthd_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_bthd_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'radio', 'label' => $this->l('Automatic options :'), 'name' => 'cron_type', 'desc' => '

Your CRON URL to call: '.$this->base_dir_ssl.'modules/'.$this->name.'/cron.php?token='.Tools::substr(Tools::encrypt('advansedcoupons'), 0, 10).'

', 'class' => 't', 'values' => array( array( 'id' => 'cron_type1', 'value' => 1, 'label' => $this->l('Cron')), array( 'id' => 'cron_type2', 'value' => 2, 'label' => $this->l('First visitor')), ), ), array( 'type' => 'text', 'label' => $this->l('Voucher description'), 'name' => 'voucher_descr_bthd', 'lang' => true, ), array( 'type' => 'radio', 'label' => $this->l('Voucher type :'), 'name' => 'discount_type_bthd', 'class' => 't', 'values' => array( array( 'id' => 'discount_type1', 'value' => 1, 'label' => $this->l('Voucher offering a percentage')), array( 'id' => 'discount_type2', 'value' => 2, 'label' => $this->l('Voucher offering a fixed amount (by currency)')), ), ), array( 'type' => 'text', 'label' => $this->l('Percentage'), 'name' => 'discount_value_percentage_bthd', 'class' => 'fixed-width-xs', 'suffix' => '%' ), array( 'type' => 'discount_value', 'label' => $this->l('Voucher amount'), 'name' => 'discount_value_bthd', 'class' => 'discount_value_bthd', 'id' => 'discount_value_bthd', ), array( 'type' => 'select', 'label' => $this->l('Voucher tax'), 'name' => 'discount_tax_bthd', 'options' => array( 'query' => array( array('id' => 0, 'name' => $this->l('Tax excluded')), array('id' => 1, 'name' => $this->l('Tax included')) ), 'id' => 'id', 'name' => 'name', ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsBthd', ), ), ); $fields_form[1] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Extra options'), 'icon' => 'icon-wrench', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Validity of the voucher (in days)'), 'name' => 'voucher_duration_bthd', 'class' => 'fixed-width-xs', 'suffix' => 'days' ), array( 'type' => 'text', 'label' => $this->l('Voucher Prefix'), 'name' => 'prefix_bthd', 'class' => 'fixed-width-xs', ), array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be used'), 'name' => 'voucher_min_bthd', 'class' => 'fixed-width-xs', 'desc' => 'You can choose a minimum amount for the cart either with or without the taxes.', ), array( 'type' => 'text', 'label' => $this->l('Number of days before birthday'), 'name' => 'nb_day_before', 'class' => 'fixed-width-xs', 'suffix' => 'days' ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('The customer must have an order'), //'desc' => 'If enabled, the voucher will not apply to products already on sale (only for PrestaShop 1.7).', 'name' => 'bthd_have_order', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'bthd_have_order_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'bthd_have_order_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'category_restriction', 'label' => $this->l('Restrictions'), 'name' => 'cr_iscategory_bthd', 'class' => 'category_restriction_bthd', 'id' => 'category_restriction_bthd', 'value' => Tools::getValue('cr_iscategory_bthd', Configuration::get('COUPON_CR_ISCATEGORY_BTHD')), ), array( 'type' => 'country_restriction', 'label' => $this->l(' '), 'name' => 'cr_iscountry_bthd', 'class' => 'country_select_bthd', 'id' => 'country_restriction_bthd', 'value' => Tools::getValue('cr_iscountry_bthd', Configuration::get('COUPON_CR_ISCOUNTRY_BTHD')), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Exclude discounted products'), 'desc' => 'If enabled, the voucher will not apply to products already on sale (only for PrestaShop 1.7).', 'name' => 'with_special_bthd', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'with_special_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'with_special_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Show the birthday voucher in the shopping cart'), 'name' => 'highlight_bthd', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'highlight_bthd_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'highlight_bthd_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Cumulative with other vouchers'), 'name' => 'cumulat_bthd', 'desc' => 'If enabled, a customer can use several vouchers for a same order.', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'cumulat_bthd_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'cumulat_bthd_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsBthd', ), ), ); if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) { $fields_form[2]= array( 'form' => array( 'legend' => array( 'title' => $this->l('Multishop options'), 'icon' => 'icon-random', ), 'input' => array( array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Active in all stores'), 'name' => 'multishop_bthd', 'desc' => 'A coupon created in one store will be available in all group stores.', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'multishop_acc_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'multishop_acc_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), ), ); } return $fields_form; } protected function getConfigFOForm() { $order_states = OrderState::getOrderStates((int)$this->context->language->id); $baseCurrencyObj = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $groups = Group::getGroups($this->context->language->id); $fields_form = array(); $fields_form[0] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Voucher after first customer order '), 'icon' => 'icon-money', ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Generate voucher after first order'), 'name' => 'f_order_voucher', 'is_bool' => true, 'values' => array( array( 'id' => 'active_f_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_f_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Voucher description'), 'name' => 'voucher_descr_f_ord', 'lang' => true, ), array( 'type' => 'radio', 'label' => $this->l('Voucher type :'), 'name' => 'discount_type_f_ord', 'class' => 't', 'values' => array( array( 'id' => 'discount_type1', 'value' => 1, 'label' => $this->l('Voucher offering a percentage')), array( 'id' => 'discount_type2', 'value' => 2, 'label' => $this->l('Voucher offering a fixed amount (by currency)')), array( 'id' => 'discount_type3', 'value' => 3, 'label' => $this->l('% from the current order')), ), ), array( 'type' => 'text', 'label' => $this->l('Percentage'), 'name' => 'discount_value_percentage_f_ord', 'class' => 'fixed-width-xs', 'suffix' => '%' ), array( 'type' => 'discount_value', 'label' => $this->l('Voucher amount'), 'name' => 'discount_value_f_ord', 'class' => 'discount_value_f_ord', 'id' => 'discount_value_ord', ), array( 'type' => 'select', 'label' => $this->l('Voucher is awarded when the order is'), 'name' => 'id_f_order_state_generation[]', 'multiple' => true, 'options' => array( 'query' => $order_states, 'id' => 'id_order_state', 'name' => 'name' )), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsFO', ), ), ); $fields_form[1] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Extra options'), 'icon' => 'icon-wrench', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be created'), 'name' => 'min_f_order', 'suffix' => $baseCurrencyObj->getSign(), 'class' => 'fixed-width-xs', ), array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be used'), 'name' => 'voucher_min_f_ord', 'class' => 'fixed-width-xs', 'suffix' => $baseCurrencyObj->getSign(), 'desc' => 'You can choose a minimum amount for the cart either with or without the taxes.', ), array( 'type' => 'switch', 'label' => $this->l('Generate voucher after guest order'), 'name' => 'guest_voucher', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'select', 'label' => $this->l("Groups of customers who receive a coupon:"), 'name' => 'f_order_group[]', 'multiple' => true, 'required' => true, 'options' => array( 'query' => $groups, 'id' => 'id_group', 'name' => 'name' ) ), array( 'type' => 'text', 'label' => $this->l('Validity of the voucher (in days)'), 'name' => 'voucher_duration_f_ord', 'class' => 'fixed-width-xs', 'suffix' => 'day' ), array( 'type' => 'text', 'label' => $this->l('Voucher Prefix'), 'name' => 'prefix_f_ord', 'class' => 'fixed-width-xs', ), array( 'type' => 'select', 'label' => $this->l('Voucher tax'), 'name' => 'discount_tax_f_ord', 'options' => array( 'query' => array( array('id' => 0, 'name' => $this->l('Tax excluded')), array('id' => 1, 'name' => $this->l('Tax included')) ), 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'category_restriction', 'label' => $this->l('Restrictions'), 'name' => 'cr_iscategory_f_ord', 'class' => 'category_restriction_f_ord', 'id' => 'category_restriction_f_ord', 'value' => Tools::getValue('cr_iscategory_f_ord', Configuration::get('COUPON_CR_ISCATEGORY_F_ORD')), ), array( 'type' => 'country_restriction', 'label' => $this->l(' '), 'name' => 'cr_iscountry_f_ord', 'class' => 'country_select_f_ord', 'id' => 'country_restriction_f_ord', 'value' => Tools::getValue('cr_iscountry_f_ord', Configuration::get('COUPON_CR_ISCOUNTRY_F_ORD')), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Exclude discounted products'), 'desc' => 'If enabled, the voucher will not apply to products already on sale (only for PrestaShop 1.7).', 'name' => 'with_special_f_ord', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'with_special_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'with_special_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Show the voucher in the shopping cart'), 'name' => 'highlight_f_ord', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'highlight_ord_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'highlight_ord_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Cumulative with other vouchers'), 'hint' => $this->l('A customer can have several active vouchers. Do you allow these vouchers to be combined on a single purchase?'), 'name' => 'cumulat_f_ord', 'class' => 'presta_compab', 'desc' => 'If enabled, a customer can use several vouchers for a same order.', 'is_bool' => true, 'values' => array( array( 'id' => 'cumulat_ord_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'cumulat_ord_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsFO', ), ), ); if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) { $fields_form[2]= array( 'form' => array( 'legend' => array( 'title' => $this->l('Multishop options'), 'icon' => 'icon-random', ), 'input' => array( array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Active in all stores'), 'name' => 'multishop_f_ord', 'desc' => 'A coupon created in one store will be available in all group stores.', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'multishop_acc_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'multishop_acc_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), ), ); } return $fields_form; } protected function getConfigOrdForm() { $order_states = OrderState::getOrderStates((int)$this->context->language->id); $groups = Group::getGroups($this->context->language->id); $fields_form = array(); $fields_form[0] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Vouchers after customer orders '), 'icon' => 'icon-money', ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Generate voucher with each new order'), 'name' => 'order_voucher', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Voucher description'), 'name' => 'voucher_descr_ord', 'lang' => true, ), array( 'type' => 'radio', 'label' => $this->l('Voucher type :'), 'name' => 'discount_type_ord', 'class' => 't', 'values' => array( array( 'id' => 'discount_type1', 'value' => 1, 'label' => $this->l('Voucher offering a percentage')), array( 'id' => 'discount_type2', 'value' => 2, 'label' => $this->l('Voucher offering a fixed amount (by currency)')), array( 'id' => 'discount_type3', 'value' => 3, 'label' => $this->l('% from the current order')), ), ), array( 'type' => 'text', 'label' => $this->l('Percentage'), 'name' => 'discount_value_percentage_ord', 'class' => 'fixed-width-xs', 'suffix' => '%' ), array( 'type' => 'discount_value', 'label' => $this->l('Voucher amount'), 'name' => 'discount_value_ord', 'class' => 'discount_value_ord', 'id' => 'discount_value_ord', ), array( 'type' => 'select', 'label' => $this->l('Voucher is awarded when the order is'), 'name' => 'id_order_state_generation[]', 'multiple' => true, 'options' => array( 'query' => $order_states, 'id' => 'id_order_state', 'name' => 'name' )), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsOrd', ), ), ); $fields_form[1] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Extra options'), 'icon' => 'icon-wrench', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be created'), 'name' => 'min_order', 'class' => 'fixed-width-xs', ), array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be used'), 'name' => 'voucher_min_ord', 'class' => 'fixed-width-xs', 'desc' => 'You can choose a minimum amount for the cart either with or without the taxes.', ), array( 'type' => 'switch', 'label' => $this->l('Generate voucher after guest order'), 'name' => 'guest_voucher', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Validity of the voucher (in days)'), 'name' => 'voucher_duration_ord', 'class' => 'fixed-width-xs', 'suffix' => 'day' ), array( 'type' => 'text', 'label' => $this->l('Voucher Prefix'), 'name' => 'prefix_ord', 'class' => 'fixed-width-xs', ), array( 'type' => 'select', 'label' => $this->l('Voucher tax'), 'name' => 'discount_tax_ord', 'options' => array( 'query' => array( array('id' => 0, 'name' => $this->l('Tax excluded')), array('id' => 1, 'name' => $this->l('Tax included')) ), 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'select', 'label' => $this->l("Groups of customers who receive a coupon:"), 'name' => 'order_group[]', 'multiple' => true, 'required' => true, 'options' => array( 'query' => $groups, 'id' => 'id_group', 'name' => 'name' ) ), array( 'type' => 'category_restriction', 'label' => $this->l('Restrictions'), 'name' => 'cr_iscategory_ord', 'class' => 'category_restriction_ord', 'id' => 'category_restriction_ord', 'value' => Tools::getValue('cr_iscategory_ord', Configuration::get('COUPON_CR_ISCATEGORY_ORD')), ), array( 'type' => 'country_restriction', 'label' => $this->l(' '), 'name' => 'cr_iscountry_ord', 'class' => 'country_select_ord', 'id' => 'country_restriction_ord', 'value' => Tools::getValue('cr_iscountry_ord', Configuration::get('COUPON_CR_ISCOUNTRY_ORD')), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Show the voucher in the shopping cart'), 'name' => 'highlight_ord', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'highlight_ord_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'highlight_ord_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Exclude discounted products'), 'desc' => 'If enabled, the voucher will not apply to products already on sale (only for PrestaShop 1.7).', 'name' => 'with_special_ord', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'with_special_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'with_special_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Cumulative with other vouchers'), 'hint' => $this->l('A customer can have several active vouchers. Do you allow these vouchers to be combined on a single purchase?'), 'name' => 'cumulat_ord', 'class' => 'presta_compab', 'desc' => 'If enabled, a customer can use several vouchers for a same order.', 'is_bool' => true, 'values' => array( array( 'id' => 'cumulat_ord_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'cumulat_ord_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitCouponsOrd', ), ), ); if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) { $fields_form[2]= array( 'form' => array( 'legend' => array( 'title' => $this->l('Multishop options'), 'icon' => 'icon-random', ), 'input' => array( array( 'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch', 'label' => $this->l('Active in all stores'), 'name' => 'multishop_ord', 'desc' => 'A coupon created in one store will be available in all group stores.', 'class' => 'presta_compab', 'is_bool' => true, 'values' => array( array( 'id' => 'multishop_acc_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'multishop_acc_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), ), ), ); } return $fields_form; } protected function getLoyaltyForm() { $order_states = OrderState::getOrderStates($this->context->language->id); $currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); $root_category = Category::getRootCategory(); $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name); if (Tools::getValue('categoryBox')) { $selected_categories = Tools::getValue('categoryBox'); } else { $selected_categories = explode(',', Configuration::get('ADVANCEDLOYALTY_VOUCHER_CATEGORY')); } $fields_form_1 = array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'switch', 'is_bool' => true, //retro-compat 'label' => $this->l('Enable loyalty programm'), 'name' => 'COUPON_LOYALTY', 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ) ), array( 'type' => 'text', 'label' => $this->l('Ratio'), 'name' => 'point_rate', 'prefix' => $currency->sign, 'class' => 'fixed-width-xs', 'suffix' => $this->l('= 1 reward point.'), ), array( 'type' => 'text', 'label' => $this->l('1 point ='), 'name' => 'point_value', 'class' => 'fixed-width-xs', 'prefix' => $currency->sign, 'suffix' => $this->l('for the discount.'), ), array( 'type' => 'text', 'label' => $this->l('Validity period of a point'), 'name' => 'validity_period', 'class' => 'fixed-width-xs', 'suffix' => $this->l('days'), ), array( 'type' => 'text', 'label' => $this->l('Voucher details'), 'name' => 'voucher_details', 'lang' => true, ), array( 'type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be used'), 'name' => 'minimal', 'class' => 'fixed-width-xs', 'prefix' => $currency->sign, ), array( 'type' => 'switch', 'is_bool' => true, //retro-compat 'label' => $this->l('Apply taxes on the voucher'), 'name' => 'ADVANCEDLOYALTY_TAX', 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ) ), array( 'type' => 'categories', 'label' => $this->l('Vouchers created by the loyalty system can be used in the following categories:'), 'name' => 'categoryBox', 'desc' => $this->l('Mark the boxes of categories in which loyalty vouchers can be used.'), 'tree' => array( 'use_search' => false, 'id' => 'categoryBox', 'use_checkbox' => true, 'selected_categories' => $selected_categories, ), //retro compat 1.5 for category tree 'values' => array( 'trads' => array( 'Root' => $root_category, 'selected' => $this->l('Selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All') ), 'selected_cat' => $selected_categories, 'input_name' => 'categoryBox[]', 'use_radio' => false, 'use_search' => false, 'disabled_categories' => array(), 'top_category' => Category::getTopCategory(), 'use_context' => true, ) ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); $fields_form_2 = array( 'form' => array( 'legend' => array( 'title' => $this->l('Welcome Loyalty rewards'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'switch', 'is_bool' => true, //retro-compat 'label' => $this->l('Give points for registration'), 'name' => 'ADVANCEDLOYALTY_WELCOME', 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ) ), array( 'type' => 'text', 'label' => $this->l('Welcome points'), 'name' => 'WS_WELCOME_POINTS', 'class' => 'fixed-width-xs', 'suffix' => $this->l('reward points'), ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); $fields_form_3 = array( 'form' => array( 'legend' => array( 'title' => $this->l('Loyalty rewards by orders'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'select', 'label' => $this->l('Points are awarded when the order is'), 'name' => 'id_order_state_validation', 'options' => array( 'query' => $order_states, 'id' => 'id_order_state', 'name' => 'name', ) ), array( 'type' => 'select', 'label' => $this->l('Points are cancelled when the order is'), 'name' => 'id_order_state_cancel', 'options' => array( 'query' => $order_states, 'id' => 'id_order_state', 'name' => 'name', ) ), array( 'type' => 'switch', 'is_bool' => true, //retro-compat 'label' => $this->l('Give points on discounted products'), 'name' => 'ADVANCEDLOYALTY_NONE_AWARD', 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ) ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); $fields_form_4 = array( 'form' => array( 'legend' => array( 'title' => $this->l('Loyalty points progression'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Initial'), 'name' => 'default_loyalty_state', 'lang' => true, ), array( 'type' => 'text', 'label' => $this->l('Unavailable'), 'name' => 'none_award_loyalty_state', 'lang' => true, ), array( 'type' => 'text', 'label' => $this->l('Converted'), 'name' => 'convert_loyalty_state', 'lang' => true, ), array( 'type' => 'text', 'label' => $this->l('Validation'), 'name' => 'validation_loyalty_state', 'lang' => true, ), array( 'type' => 'text', 'label' => $this->l('Cancelled'), 'name' => 'cancel_loyalty_state', 'lang' => true, ), ), 'submit' => array( 'title' => $this->l('Save'), ) ), ); return array($fields_form_1, $fields_form_2, $fields_form_3, $fields_form_4); } /** * Set values for the inputs. */ protected function getConfigFormValues() { $fields_values = array( 'min_order' => Configuration::get('COUPON_MIN_ORDER'), 'min_f_order' => Configuration::get('COUPON_MIN_F_ORDER'), 'order_group[]' => Tools::getValue('order_group[]', explode(',', Configuration::get('COUPON_ORD_GROUP'))), 'f_order_group[]' => Tools::getValue('f_order_group[]', explode(',', Configuration::get('COUPON_F_ORD_GROUP'))), 'account_voucher' => Configuration::get('COUPON_ACC_VOUCHER'), 'bthd_voucher' => Configuration::get('COUPON_BTHD_VOUCHER'), 'order_voucher' => Configuration::get('COUPON_ORDER_VOUCHER'), 'f_order_voucher' => Configuration::get('COUPON_F_ORDER_VOUCHER'), 'guest_voucher' => Configuration::get('COUPON_GUEST_VOUCHER'), 'discount_type_acc' => Configuration::get('COUPON_DISCOUNT_TYPE_ACC'), 'discount_value_percentage_acc' => Configuration::get('COUPON_PERCENTAGE_ACC'), 'voucher_duration_acc' => Configuration::get('COUPON_VOUCHER_DURATION_ACC'), 'discount_type_bthd' => Configuration::get('COUPON_DISCOUNT_TYPE_BTHD'), 'discount_value_percentage_bthd' => Configuration::get('COUPON_PERCENTAGE_BTHD'), 'voucher_duration_bthd' => Configuration::get('COUPON_VOUCHER_DURATION_BTHD'), 'discount_type_ord' => Configuration::get('COUPON_DISCOUNT_TYPE_ORD'), 'discount_value_percentage_ord' => Configuration::get('COUPON_PERCENTAGE_ORD'), 'voucher_duration_ord' => Configuration::get('COUPON_VOUCHER_DURATION_ORD'), 'discount_type_f_ord' => Configuration::get('COUPON_DISCOUNT_TYPE_F_ORD'), 'discount_value_percentage_f_ord' => Configuration::get('COUPON_PERCENTAGE_F_ORD'), 'voucher_duration_f_ord' => Configuration::get('COUPON_VOUCHER_DURATION_F_ORD'), 'id_order_state_generation[]' => unserialize(Configuration::get('COUPON_ORD_STATE_GENERATION')), 'id_f_order_state_generation[]' => unserialize(Configuration::get('COUPON_F_ORD_STATE_GENERATION')), 'highlight_acc' => Configuration::get('COUPON_HIGHLIGHT_ACC'), 'highlight_bthd' => Configuration::get('COUPON_HIGHLIGHT_BTHD'), 'highlight_ord' => Configuration::get('COUPON_HIGHLIGHT_ORD'), 'highlight_f_ord' => Configuration::get('COUPON_HIGHLIGHT_F_ORD'), 'cumulat_acc' => Configuration::get('COUPON_CUMULAT_ACC'), 'cumulat_bthd' => Configuration::get('COUPON_CUMULAT_BTHD'), 'cumulat_ord' => Configuration::get('COUPON_CUMULAT_ORD'), 'cumulat_f_ord' => Configuration::get('COUPON_CUMULAT_F_ORD'), 'discount_tax_acc' => Configuration::get('COUPON_TAX_ACC'), 'discount_tax_bthd' => Configuration::get('COUPON_TAX_BTHD'), 'discount_tax_ord' => Configuration::get('COUPON_TAX_ORD'), 'discount_tax_f_ord' => Configuration::get('COUPON_TAX_F_ORD'), 'with_special_acc' => Configuration::get('COUPON_WSPECIAL_ACC'), 'with_special_bthd' => Configuration::get('COUPON_WSPECIAL_BTHD'), 'with_special_ord' => Configuration::get('COUPON_WSPECIAL_ORD'), 'with_special_f_ord' => Configuration::get('COUPON_WSPECIAL_F_ORD'), 'voucher_min_acc' => Configuration::get('COUPON_VOUCHER_MIN_ACC'), 'voucher_min_bthd' => Configuration::get('COUPON_VOUCHER_MIN_BTHD'), 'voucher_min_ord' => Configuration::get('COUPON_VOUCHER_MIN_ORD'), 'voucher_min_f_ord' => Configuration::get('COUPON_VOUCHER_MIN_F_ORD'), 'prefix_acc' => Configuration::get('COUPON_PREF_ACC'), 'prefix_bthd' => Configuration::get('COUPON_PREF_BTHD'), 'prefix_ord' => Configuration::get('COUPON_PREF_ORD'), 'prefix_f_ord' => Configuration::get('COUPON_PREF_F_ORD'), 'multishop_acc' => Configuration::get('COUPON_MULTYSHOP_ACC'), 'multishop_bthd' => Configuration::get('COUPON_MULTYSHOP_BTHD'), 'multishop_ord' => Configuration::get('COUPON_MULTYSHOP_ORD'), 'multishop_f_ord' => Configuration::get('COUPON_MULTYSHOP_F_ORD'), 'bthd_have_order' => Configuration::get('COUPON_CR_HAVEORDER'), 'nb_day_before' => Configuration::get('COUPON_NB_DAY_BEFORE'), 'cron_type' => Configuration::get('COUPON_CRON_TYPE'), ); $languages = Language::getLanguages(false); foreach ($languages as $lang) { $fields_values['voucher_descr_acc'][$lang['id_lang']] = Tools::getValue('voucher_descr_acc_'.(int)$lang['id_lang'], Configuration::get('COUPON_VOUCHER_DESCR_ACC', (int)$lang['id_lang'])); $fields_values['voucher_descr_bthd'][$lang['id_lang']] = Tools::getValue('voucher_descr_bthd_'.(int)$lang['id_lang'], Configuration::get('COUPON_VOUCHER_DESCR_BTHD', (int)$lang['id_lang'])); $fields_values['voucher_descr_ord'][$lang['id_lang']] = Tools::getValue('voucher_descr_ord_'.(int)$lang['id_lang'], Configuration::get('COUPON_VOUCHER_DESCR_ORD', (int)$lang['id_lang'])); $fields_values['voucher_descr_f_ord'][$lang['id_lang']] = Tools::getValue('voucher_descr_f_ord_'.(int)$lang['id_lang'], Configuration::get('COUPON_VOUCHER_DESCR_F_ORD', (int)$lang['id_lang'])); } $currencies = Currency::getCurrencies(); foreach ($currencies as $currency) { $fields_values['discount_value_acc'][$currency['id_currency']] = Tools::getValue('discount_value_acc['.(int)$currency['id_currency'].']', Configuration::get('COUPON_DISCOUNT_VALUE_ACC'.(int)$currency['id_currency'])); $fields_values['discount_value_bthd'][$currency['id_currency']] = Tools::getValue('discount_value_bthd['.(int)$currency['id_currency'].']', Configuration::get('COUPON_DISCOUNT_VALUE_BTHD'.(int)$currency['id_currency'])); $fields_values['discount_value_ord'][$currency['id_currency']] = Tools::getValue('discount_value_ord['.(int)$currency['id_currency'].']', Configuration::get('COUPON_DISCOUNT_VALUE_ORD'.(int)$currency['id_currency'])); $fields_values['discount_value_f_ord'][$currency['id_currency']] = Tools::getValue('discount_value_f_ord['.(int)$currency['id_currency'].']', Configuration::get('COUPON_DISCOUNT_VALUE_F_ORD'.(int)$currency['id_currency'])); } return $fields_values; } protected function getLoyaltyFormValues() { $fields_values = array( 'COUPON_LOYALTY' => Tools::getValue('COUPON_LOYALTY', Configuration::get('COUPON_LOYALTY')), 'point_rate' => Tools::getValue('ADVANCEDLOYALTY_POINT_RATE', Configuration::get('ADVANCEDLOYALTY_POINT_RATE')), 'point_value' => Tools::getValue('ADVANCEDLOYALTY_POINT_VALUE', Configuration::get('ADVANCEDLOYALTY_POINT_VALUE')), 'ADVANCEDLOYALTY_NONE_AWARD' => Tools::getValue('ADVANCEDLOYALTY_NONE_AWARD', Configuration::get('ADVANCEDLOYALTY_NONE_AWARD')), 'minimal' => Tools::getValue('ADVANCEDLOYALTY_MINIMAL', Configuration::get('ADVANCEDLOYALTY_MINIMAL')), 'validity_period' => Tools::getValue('ADVANCEDLOYALTY_VALIDITY_PERIOD', Configuration::get('ADVANCEDLOYALTY_VALIDITY_PERIOD')), 'id_order_state_validation' => Tools::getValue('id_order_state_validation', $this->loyaltyStateValidation->id_order_state), 'id_order_state_cancel' => Tools::getValue('id_order_state_cancel', $this->loyaltyStateCancel->id_order_state), 'ADVANCEDLOYALTY_TAX' => Tools::getValue('ADVANCEDLOYALTY_TAX', Configuration::get('ADVANCEDLOYALTY_TAX')), 'ADVANCEDLOYALTY_WELCOME' => Tools::getValue('ADVANCEDLOYALTY_WELCOME', Configuration::get('ADVANCEDLOYALTY_WELCOME')), 'WS_WELCOME_POINTS' => Tools::getValue('WS_WELCOME_POINTS', Configuration::get('WS_WELCOME_POINTS')), ); $languages = Language::getLanguages(false); foreach ($languages as $lang) { $fields_values['voucher_details'][$lang['id_lang']] = Tools::getValue('voucher_details_'.(int)$lang['id_lang'], Configuration::get('ADVANCEDLOYALTY_VOUCHER_DETAILS', (int)$lang['id_lang'])); $fields_values['default_loyalty_state'][$lang['id_lang']] = Tools::getValue('default_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateDefault->name[(int)($lang['id_lang'])]); $fields_values['validation_loyalty_state'][$lang['id_lang']] = Tools::getValue('validation_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateValidation->name[(int)($lang['id_lang'])]); $fields_values['cancel_loyalty_state'][$lang['id_lang']] = Tools::getValue('cancel_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateCancel->name[(int)($lang['id_lang'])]); $fields_values['convert_loyalty_state'][$lang['id_lang']] = Tools::getValue('convert_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateConvert->name[(int)($lang['id_lang'])]); $fields_values['none_award_loyalty_state'][$lang['id_lang']] = Tools::getValue('none_award_loyalty_state_'.(int)$lang['id_lang'], $this->loyaltyStateNoneAward->name[(int)($lang['id_lang'])]); } return $fields_values; } public function getL($key) { $translations = array( 'Awaiting validation' => $this->l('Awaiting validation'), 'Available' => $this->l('Available'), 'Cancelled' => $this->l('Cancelled'), 'Already converted' => $this->l('Already converted'), 'Unavailable on discounts' => $this->l('Unavailable on discounts'), 'Not available on discounts.' => $this->l('Not available on discounts.')); return (array_key_exists($key, $translations)) ? $translations[$key] : $key; } /** * Save form data. */ protected function postProcess() { $this->_errors = array(); if (Tools::isSubmit('submitCouponLoyalty')) { $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(); if (!is_array(Tools::getValue('categoryBox')) || !count(Tools::getValue('categoryBox'))) { $this->_errors[] = $this->l('You must choose at least one category for voucher\'s action'); } if (!count($this->_errors)) { Configuration::updateValue('COUPON_LOYALTY', Tools::getValue('COUPON_LOYALTY')); Configuration::updateValue('ADVANCEDLOYALTY_VOUCHER_CATEGORY', $this->voucherCategories(Tools::getValue('categoryBox'))); Configuration::updateValue('ADVANCEDLOYALTY_POINT_VALUE', (float)(Tools::getValue('point_value'))); Configuration::updateValue('ADVANCEDLOYALTY_POINT_RATE', (float)(Tools::getValue('point_rate'))); Configuration::updateValue('ADVANCEDLOYALTY_NONE_AWARD', (int)(Tools::getValue('ADVANCEDLOYALTY_NONE_AWARD'))); Configuration::updateValue('ADVANCEDLOYALTY_MINIMAL', (float)(Tools::getValue('minimal'))); Configuration::updateValue('ADVANCEDLOYALTY_TAX', (int)(Tools::getValue('ADVANCEDLOYALTY_TAX'))); Configuration::updateValue('ADVANCEDLOYALTY_VALIDITY_PERIOD', (int)(Tools::getValue('validity_period'))); Configuration::updateValue('ADVANCEDLOYALTY_WELCOME', Tools::getValue('ADVANCEDLOYALTY_WELCOME')); Configuration::updateValue('WS_WELCOME_POINTS', (int)(Tools::getValue('WS_WELCOME_POINTS'))); $this->loyaltyStateValidation->id_order_state = (int)(Tools::getValue('id_order_state_validation')); $this->loyaltyStateCancel->id_order_state = (int)(Tools::getValue('id_order_state_cancel')); $arrayVoucherDetails = array(); foreach ($languages as $language) { $arrayVoucherDetails[(int)($language['id_lang'])] = Tools::getValue('voucher_details_'.(int)($language['id_lang'])); $this->loyaltyStateDefault->name[(int)($language['id_lang'])] = Tools::getValue('default_loyalty_state_'.(int)($language['id_lang'])); $this->loyaltyStateValidation->name[(int)($language['id_lang'])] = Tools::getValue('validation_loyalty_state_'.(int)($language['id_lang'])); $this->loyaltyStateCancel->name[(int)($language['id_lang'])] = Tools::getValue('cancel_loyalty_state_'.(int)($language['id_lang'])); $this->loyaltyStateConvert->name[(int)($language['id_lang'])] = Tools::getValue('convert_loyalty_state_'.(int)($language['id_lang'])); $this->loyaltyStateNoneAward->name[(int)($language['id_lang'])] = Tools::getValue('none_award_loyalty_state_'.(int)($language['id_lang'])); } if (empty($arrayVoucherDetails[$id_lang_default])) { $arrayVoucherDetails[$id_lang_default] = ' '; } Configuration::updateValue('ADVANCEDLOYALTY_VOUCHER_DETAILS', $arrayVoucherDetails); if (empty($this->loyaltyStateDefault->name[$id_lang_default])) { $this->loyaltyStateDefault->name[$id_lang_default] = ' '; } $this->loyaltyStateDefault->save(); if (empty($this->loyaltyStateValidation->name[$id_lang_default])) { $this->loyaltyStateValidation->name[$id_lang_default] = ' '; } $this->loyaltyStateValidation->save(); if (empty($this->loyaltyStateCancel->name[$id_lang_default])) { $this->loyaltyStateCancel->name[$id_lang_default] = ' '; } $this->loyaltyStateCancel->save(); if (empty($this->loyaltyStateConvert->name[$id_lang_default])) { $this->loyaltyStateConvert->name[$id_lang_default] = ' '; } $this->loyaltyStateConvert->save(); if (empty($this->loyaltyStateNoneAward->name[$id_lang_default])) { $this->loyaltyStateNoneAward->name[$id_lang_default] = ' '; } $this->loyaltyStateNoneAward->save(); $this->_html .= $this->displayConfirmation($this->l('Loyalty configuration updated.')); } else { $errors = ''; foreach ($this->_errors as $error) { $errors .= $error.'
'; } $this->html .= $this->displayError($errors); } } if (Tools::isSubmit('submitCouponsAcc')) { Configuration::updateValue('COUPON_ACC_VOUCHER', Tools::getValue('account_voucher')); if (Tools::getValue('account_voucher')) { Configuration::updateValue('COUPON_DISCOUNT_TYPE_ACC', (int)(Tools::getValue('discount_type_acc'))); if ((int)(Tools::getValue('discount_type_acc')) === 1) { Configuration::updateValue('COUPON_PERCENTAGE_ACC', (int)(Tools::getValue('discount_value_percentage_acc'))); } if ((int)(Tools::getValue('discount_type_acc')) === 2) { foreach (Tools::getValue('discount_value_acc') as $id_currency => $discount_value) { Configuration::updateValue('COUPON_DISCOUNT_VALUE_ACC'.(int)($id_currency), (float)($discount_value)); } } self::_updateCommonValue('acc'); } } if (Tools::isSubmit('submitCouponsBthd')) { Configuration::updateValue('COUPON_BTHD_VOUCHER', Tools::getValue('bthd_voucher')); if (Tools::getValue('bthd_voucher')) { Configuration::updateValue('COUPON_DISCOUNT_TYPE_BTHD', (int)(Tools::getValue('discount_type_bthd'))); if ((int)(Tools::getValue('discount_type_bthd')) === 1) { Configuration::updateValue('COUPON_PERCENTAGE_BTHD', (int)(Tools::getValue('discount_value_percentage_bthd'))); } if ((int)(Tools::getValue('discount_type_bthd')) === 2) { foreach (Tools::getValue('discount_value_bthd') as $id_currency => $discount_value) { Configuration::updateValue('COUPON_DISCOUNT_VALUE_BTHD'.(int)($id_currency), (float)($discount_value)); } } Configuration::updateValue('COUPON_CR_HAVEORDER', Tools::getValue('bthd_have_order')); Configuration::updateValue('COUPON_NB_DAY_BEFORE', Tools::getValue('nb_day_before')); Configuration::updateValue('COUPON_CRON_TYPE', Tools::getValue('cron_type')); self::_updateCommonValue('bthd'); } } if (Tools::isSubmit('submitCouponsFO')) { Configuration::updateValue('COUPON_F_ORDER_VOUCHER', Tools::getValue('f_order_voucher')); if (Tools::getValue('f_order_voucher')) { Configuration::updateValue('COUPON_MIN_F_ORDER', (int)(Tools::getValue('min_f_order'))); Configuration::updateValue('COUPON_GUEST_VOUCHER', Tools::getValue('guest_voucher')); Configuration::updateValue('COUPON_DISCOUNT_TYPE_F_ORD', (int)(Tools::getValue('discount_type_f_ord'))); if ((int)(Tools::getValue('discount_type_f_ord')) === 1 || (int)(Tools::getValue('discount_type_f_ord')) === 3) { Configuration::updateValue('COUPON_PERCENTAGE_F_ORD', (int)(Tools::getValue('discount_value_percentage_f_ord'))); } if ((int)(Tools::getValue('discount_type_f_ord')) === 2) { foreach (Tools::getValue('discount_value_f_ord') as $id_currency => $discount_value) { Configuration::updateValue('COUPON_DISCOUNT_VALUE_F_ORD'.(int)($id_currency), (float)($discount_value)); } } Configuration::updateValue('COUPON_F_ORD_STATE_GENERATION', serialize(Tools::getValue('id_f_order_state_generation'))); Configuration::updateValue('COUPON_F_ORD_GROUP', implode(",", Tools::getValue('f_order_group'))); self::_updateCommonValue('f_ord'); } } if (Tools::isSubmit('submitCouponsOrd')) { Configuration::updateValue('COUPON_ORDER_VOUCHER', Tools::getValue('order_voucher')); if (Tools::getValue('order_voucher')) { Configuration::updateValue('COUPON_MIN_ORDER', (int)(Tools::getValue('min_order'))); Configuration::updateValue('COUPON_GUEST_VOUCHER', Tools::getValue('guest_voucher')); Configuration::updateValue('COUPON_DISCOUNT_TYPE_ORD', (int)(Tools::getValue('discount_type_ord'))); if ((int)(Tools::getValue('discount_type_ord')) === 1 || (int)(Tools::getValue('discount_type_ord')) === 3) { Configuration::updateValue('COUPON_PERCENTAGE_ORD', (int)(Tools::getValue('discount_value_percentage_ord'))); } if ((int)(Tools::getValue('discount_type_ord')) === 2) { foreach (Tools::getValue('discount_value_ord') as $id_currency => $discount_value) { Configuration::updateValue('COUPON_DISCOUNT_VALUE_ORD'.(int)($id_currency), (float)($discount_value)); } } Configuration::updateValue('COUPON_ORD_STATE_GENERATION', serialize(Tools::getValue('id_order_state_generation'))); Configuration::updateValue('COUPON_ORD_GROUP', implode(",", Tools::getValue('order_group'))); self::_updateCommonValue('ord'); } $this->_html .= $this->displayConfirmation($this->l('Vouchers configuration updated.')); } } private function _updateCommonValue($type) { $b_type = Tools::strtoupper($type); Configuration::updateValue('COUPON_VOUCHER_DURATION_'.$b_type, (int)(Tools::getValue('voucher_duration_'.$type))); Configuration::updateValue('COUPON_VOUCHER_MIN_'.$b_type, (int)(Tools::getValue('voucher_min_'.$type))); Configuration::updateValue('COUPON_HIGHLIGHT_'.$b_type, Tools::getValue('highlight_'.$type)); Configuration::updateValue('COUPON_CUMULAT_'.$b_type, Tools::getValue('cumulat_'.$type)); Configuration::updateValue('COUPON_TAX_'.$b_type, Tools::getValue('discount_tax_'.$type)); Configuration::updateValue('COUPON_WSPECIAL_'.$b_type, Tools::getValue('with_special_'.$type)); Configuration::updateValue('COUPON_MULTYSHOP_'.$b_type, Tools::getValue('multishop_'.$type)); Configuration::updateValue('COUPON_PREF_'.$b_type, Tools::getValue('prefix_'.$type)); foreach (Language::getLanguages(false) as $lang) { Configuration::updateValue('COUPON_VOUCHER_DESCR_'.$b_type, array($lang['id_lang'] => Tools::getValue('voucher_descr_'.$type.'_'.(int)$lang['id_lang']))); } // Category restriction Configuration::updateValue('COUPON_CR_ISCATEGORY_'.$b_type, (int)Tools::getValue('cr_iscategory_'.$type)); $categories = ''; if ((int)Tools::getValue('cr_iscategory_'.$type) == 1) { $categories = implode(',', Tools::getValue('categoryBox_'.$type)); } Configuration::updateValue('COUPON_CR_CATEGORIES_'.$b_type, $categories); // Countries restriction Configuration::updateValue('COUPON_CR_ISCOUNTRY_'.$b_type, (int)Tools::getValue('cr_iscountry_'.$type)); $countries = ''; if ((int)Tools::getValue('cr_iscountry_'.$type) == 1) { //$countries = implode ( ',', Tools::getValue ( 'country_select' ) ); //die($countries); $countries = implode(',', Tools::getValue('country_select_'.$type)); } Configuration::updateValue('COUPON_COUNTRIES_'.$b_type, $countries); } private function _postValidation() { $this->_errors = array(); if (Tools::isSubmit('submitCouponsAcc')) { if (((int)Tools::getValue('cr_iscategory_acc') == 1) && (!Tools::getValue('categoryBox_acc') || !is_array(Tools::getValue('categoryBox_acc')) || !count(Tools::getValue('categoryBox_acc')) > 0)) { $this->_errors[] = $this->displayError($this->l('Restriction categories is checked, but not category is selected')); } if ((int)(Tools::getValue('discount_type_acc')) === 1) { if (!(int)(Tools::getValue('discount_value_percentage_acc')) or (int)(Tools::getValue('discount_value_percentage_acc')) < 0 or (int)(Tools::getValue('discount_value_percentage_acc')) > 100) { $this->_errors[] = $this->displayError($this->l('Discount percentage is required/invalid.')); } } if ((int)(Tools::getValue('discount_type_acc')) === 2) { if (!is_array(Tools::getValue('discount_value_acc'))) { $this->_errors[] = $this->displayError($this->l('Discount value is invalid.')); } foreach (Tools::getValue('discount_value_acc') as $id_currency => $discount_value_acc) { if ($discount_value_acc == '') { $this->_errors[] = $this->displayError(sprintf($this->l('Discount value for the currency #%d is empty.'), $id_currency)); } elseif (!Validate::isUnsignedFloat($discount_value_acc)) { $this->_errors[] = $this->displayError(sprintf($this->l('Discount value for the currency #%d is invalid.'), $id_currency)); } } } } if (Tools::isSubmit('submitCouponsOrd')) { if (Tools::getValue('min_order') < 0 || !Validate::isUnsignedFloat(Tools::getValue('min_order'))) { $this->_errors[] = $this->displayError($this->l('Minimum amount for order is invalid.')); } if ((int)(Tools::getValue('discount_type_ord')) === 1) { if (!(int)(Tools::getValue('discount_value_percentage_ord')) or (int)(Tools::getValue('discount_value_percentage_ord')) < 0 or (int)(Tools::getValue('discount_value_percentage_ord')) > 100) { $this->_errors[] = $this->displayError($this->l('Discount percentage is required/invalid.')); } } if ((int)(Tools::getValue('discount_type_ord')) === 2) { if (!is_array(Tools::getValue('discount_value_ord'))) { $this->_errors[] = $this->displayError($this->l('Discount value is invalid.')); } foreach (Tools::getValue('discount_value_ord') as $id_currency => $discount_value_ord) { if ($discount_value_ord == '') { $this->_errors[] = $this->displayError(sprintf($this->l('Discount value for the currency #%d is empty.'), $id_currency)); } elseif (!Validate::isUnsignedFloat($discount_value_ord)) { $this->_errors[] = $this->displayError(sprintf($this->l('Discount value for the currency #%d is invalid.'), $id_currency)); } } } if ((int)(Tools::getValue('discount_type_ord')) === 3) { if (!(int)(Tools::getValue('discount_value_percentage_ord')) or (int)(Tools::getValue('discount_value_percentage_ord')) < 0 or (int)(Tools::getValue('discount_value_percentage_ord')) > 100) { $this->_errors[] = $this->displayError($this->l('Discount percentage is required/invalid.')); } } if (((int)Tools::getValue('cr_iscategory_ord') == 1) && (!Tools::getValue('categoryBox_ord') || !is_array(Tools::getValue('categoryBox_ord')) || !count(Tools::getValue('categoryBox_ord')) > 0)) { $this->_errors[] = $this->displayError($this->l('Restriction categories is checked, but not category is selected')); } } } private function voucherCategories($categories) { $cat = ''; if ($categories && is_array($categories)) { foreach ($categories as $category) { $cat .= $category.','; } } return rtrim($cat, ','); } /** * Add the CSS & JavaScript files you want to be loaded in the BO. */ public function hookBackOfficeHeader() { if (Tools::getValue('module_name') == $this->name) { //$this->context->controller->addJS($this->_path.'views/js/back.js'); $this->context->controller->addCSS($this->_path.'views/css/back.css'); } } public static function displayDiscount($discountValue, $discountType, $currency = false) { if ((float)$discountValue and (int)$discountType) { if ($discountType == 1) { return $discountValue.chr(37); // asCII #37 --> % (percent) } elseif ($discountType == 2) { return Tools::displayPrice($discountValue, $currency); } } return ''; // return a string because it's a display method } /** * Hook called on creation customer account * Create a discount for the customer if sponsorised */ public function hookCreateAccount($params) { $newCustomer = $params['newCustomer']; if (!Validate::isLoadedObject($newCustomer)) { return false; } /* $iCustomerId = Customer::customerExists($newCustomer->email, true); // if customer exists if ($iCustomerId) { return false; } */ if (Configuration::get('COUPON_ACC_VOUCHER')) { $cartRule_code = WsCoupons::registerDiscount((int)$newCustomer->id, (int)$params['cookie']->id_currency, 'acc'); $min_amount = false; if (Configuration::get('COUPON_VOUCHER_MIN_ACC')) { $min_amount = $this->l('*When you spend ').Tools::displayPrice(Configuration::get('COUPON_VOUCHER_MIN_ACC'), (int)$this->context->currency->id).$this->l(' or more'); } $data = array( '{firstname}' => $newCustomer->firstname, '{lastname}' => $newCustomer->lastname, '{voucher_num}' => $cartRule_code, '{min_amount}' => $min_amount, '{voucher_duration}' => $this->l('*The number of validity days of the voucher: ').date($this->context->language->date_format_lite, time() + (int)Configuration::get('COUPON_VOUCHER_DURATION_ACC')*24*60*60), '{voucher_amount}' => (Configuration::get('COUPON_DISCOUNT_TYPE_ACC') == 2 ? Tools::displayPrice((float)Configuration::get('COUPON_DISCOUNT_VALUE_ACC'.(int)$this->context->currency->id), (int)$this->context->currency->id) : (float)Configuration::get('COUPON_PERCENTAGE_ACC').'%')); $cookie = $this->context->cookie; $iso_lng = Language::getIsoById((int)($this->context->language->id)); if (is_dir($this->dir_mails . $iso_lng . '/')) { $id_lang_current = $this->context->language->id; } else { $id_lang_current = Language::getIdByIso('en'); } Mail::Send( $id_lang_current, 'welcome_coupon', $this->l('Congratulations! Welcome Coupon inside!'), //Mail::l('Congratulations! Welcome Coupon inside!', (int)$cookie->id_lang), $data, $newCustomer->email, $newCustomer->firstname.' '.$newCustomer->lastname, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), null, null, $this->dir_mails ); Tools::redirect('index.php?controller=discount'); } if (Configuration::get('ADVANCEDLOYALTY_WELCOME')) { include_once($this->dir_loyalty); include_once($this->dir_loyalty_state); $loyalty = new WsAdvLoyaltyModule(); $loyalty->id_customer = (int)$newCustomer->id; $loyalty->id_order = 0; $loyalty->points = Configuration::get('WS_WELCOME_POINTS'); $loyalty->id_loyalty_state = WsAdvLoyaltyStateModule::getValidationId(); $loyalty->save(); } } public function hookOrderConfirmation($params) { /* if (Configuration::get('COUPON_ORDER_VOUCHER')) { $total_paid = $params["objOrder"]->total_paid_tax_excl; if (Configuration::get('COUPON_MIN_ORDER')) { if ($total_paid < Configuration::get('COUPON_MIN_ORDER')) { return ; } } $cartRule_code = $this->registerDiscount($params['objOrder']->id_customer, (int)$params['cookie']->id_currency, 'ord', $params["objOrder"]->total_paid_tax_excl); } */ } /* Hook called when a new order is created */ public function hookNewOrder($params) { if (Configuration::get('COUPON_LOYALTY')) { include_once($this->dir_loyalty); include_once($this->dir_loyalty_state); if (!Validate::isLoadedObject($params['customer']) || !Validate::isLoadedObject($params['order'])) { die($this->l('Missing parameters')); } $loyalty = new WsAdvLoyaltyModule(); $loyalty->id_customer = (int)$params['customer']->id; // TODO $params_obj_order = $params['objOrder']; in 17 $loyalty->id_order = (int)$params['order']->id; $loyalty->points = WsAdvLoyaltyModule::getOrderNbPoints($params['order']); if (!Configuration::get('ADVANCEDLOYALTY_NONE_AWARD') && (int)$loyalty->points == 0) { $loyalty->id_loyalty_state = WsAdvLoyaltyStateModule::getNoneAwardId(); } else { $loyalty->id_loyalty_state = WsAdvLoyaltyStateModule::getDefaultId(); } return $loyalty->save(); } } /** * Hook called when order status changed * register a discount for sponsor and send him an e-mail */ public function hookUpdateOrderStatus($params) { if (!Validate::isLoadedObject($params['newOrderStatus'])) { die($this->l('Missing parameters')); } $orderState = $params['newOrderStatus']; $order = new Order((int)($params['id_order'])); if ($order and !Validate::isLoadedObject($order)) { die($this->l('Incorrect Order object.')); } if (Configuration::get('COUPON_ORDER_VOUCHER') || Configuration::get('COUPON_F_ORDER_VOUCHER')) { $order_status_fo = unserialize(Configuration::get('COUPON_F_ORD_STATE_GENERATION')); $order_status = unserialize(Configuration::get('COUPON_ORD_STATE_GENERATION')); $customer = new Customer((int)$order->id_customer); $stats = $customer->getStats(); $generate_coupon = false; //It is considered that 0 for any status except "delivered", then it is considered - 1 $nb_orders = $stats['nb_orders']; if ($orderState->id != 5) { $nb_orders++; } if (Configuration::get('COUPON_F_ORDER_VOUCHER') and $nb_orders == 1 and in_array((int)$orderState->id, $order_status_fo)) { $key_v = 'f_ord'; $generate_coupon = true; if (Configuration::get('COUPON_F_ORD_GROUP')) { $allowed_groups = explode(',', Configuration::get('COUPON_F_ORD_GROUP')); if (!in_array($customer->id_default_group, $allowed_groups)) { $generate_coupon = false; } } $v_guest_order = Configuration::get('COUPON_GUEST_ORDER'); $v_tax_ord = Configuration::get('COUPON_TAX_F_ORD'); $v_min_ord = Configuration::get('COUPON_MIN_F_ORDER'); $voucher_amount = (int)Configuration::get('COUPON_PERCENTAGE_F_ORD').'%'; $type_discount = Configuration::get('COUPON_DISCOUNT_TYPE_F_ORD'); $voucher_duration = date('Y-m-d', time() + (int)Configuration::get('COUPON_VOUCHER_DURATION_F_ORD')*24*60*60); $voucher_amount_val = (float)Configuration::get('COUPON_DISCOUNT_VALUE_F_ORD'.(int)$this->context->currency->id); } elseif (Configuration::get('COUPON_ORDER_VOUCHER') and in_array((int)$orderState->id, $order_status)) { $key_v = 'ord'; $generate_coupon = true; if (Configuration::get('COUPON_ORD_GROUP')) { $allowed_groups = explode(',', Configuration::get('COUPON_ORD_GROUP')); if (!in_array($customer->id_default_group, $allowed_groups)) { $generate_coupon = false; } } $v_guest_order = Configuration::get('COUPON_GUEST_ORDER'); $v_tax_ord = Configuration::get('COUPON_TAX_ORD'); $v_min_ord = Configuration::get('COUPON_MIN_ORDER'); $voucher_amount = (int)Configuration::get('COUPON_PERCENTAGE_ORD').'%'; $type_discount = Configuration::get('COUPON_DISCOUNT_TYPE_ORD'); $voucher_duration = date('Y-m-d', time() + (int)Configuration::get('COUPON_VOUCHER_DURATION_ORD')*24*60*60); $voucher_amount_val = (float)Configuration::get('COUPON_DISCOUNT_VALUE_ORD'.(int)$this->context->currency->id); } if ($generate_coupon) { $id_customer = 0; $b_type_voucher = Tools::strtoupper($key_v); if (!$customer->is_guest) { $id_customer = $order->id_customer; } elseif (!$v_guest_order) { return false; } if ($v_tax_ord) { $total_paid = $order->total_products_wt; } else { $total_paid = $order->total_products; } if ($v_min_ord) { if ($total_paid < $v_min_ord) { $generate_coupon = false; } } } if ($generate_coupon) { if ($type_discount == 2) { $voucher_amount = Tools::displayPrice((float)$voucher_amount_val, (int)Configuration::get('PS_CURRENCY_DEFAULT')); } elseif ($type_discount == 3) { $gdOrder = $total_paid*$voucher_amount/100; $voucher_amount = Tools::displayPrice((float)$gdOrder, (int)Configuration::get('PS_CURRENCY_DEFAULT')); } $cartRule_code = WsCoupons::registerDiscount((int)$id_customer, (int)$order->id_currency, $key_v, $total_paid); $min_amount = false; if (Configuration::get('COUPON_VOUCHER_MIN_'.$b_type_voucher)) { $min_amount = $this->l('*When you spend ').Tools::displayPrice(Configuration::get('COUPON_VOUCHER_MIN_'.$b_type_voucher), (int)$order->id_currency).$this->l(' or more'); } if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $base_dir_ssl = _PS_BASE_URL_SSL_.__PS_BASE_URI__; } else { $base_dir_ssl = _PS_BASE_URL_.__PS_BASE_URI__; } $data = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{voucher_num}' => $cartRule_code, '{min_amount}' => $min_amount, '{voucher_duration}' => $this->l('*The number of validity days of the voucher: ').date($this->context->language->date_format_lite, time() + (int)Configuration::get('COUPON_VOUCHER_DURATION_'.$b_type_voucher)*24*60*60), '{voucher_amount}' => $voucher_amount ); $cookie = $this->context->cookie; $iso_lng = Language::getIsoById((int)($this->context->language->id)); if (is_dir($this->dir_mails . $iso_lng . '/')) { $id_lang_current = $this->context->language->id; } else { $id_lang_current = Language::getIdByIso('en'); } Mail::Send( $id_lang_current, 'coupon_congratulations', $this->l('New Discount for you!'), $data, $customer->email, $customer->firstname.' '.$customer->lastname, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), null, null, $this->dir_mails ); } } if (Configuration::get('COUPON_LOYALTY')) { include_once($this->dir_loyalty); include_once($this->dir_loyalty_state); $this->instanceDefaultStates(); if ($orderState->id == $this->loyaltyStateValidation->id_order_state || $orderState->id == $this->loyaltyStateCancel->id_order_state) { if (!Validate::isLoadedObject($loyalty = new WsAdvLoyaltyModule(WsAdvLoyaltyModule::getByOrderId($order->id)))) { return false; } if ((int)Configuration::get('ADVANCEDLOYALTY_NONE_AWARD') && $loyalty->id_loyalty_state == WsAdvLoyaltyStateModule::getNoneAwardId()) { return true; } if ($orderState->id == $this->loyaltyStateValidation->id_order_state) { $loyalty->id_loyalty_state = WsAdvLoyaltyStateModule::getValidationId(); if ((int)$loyalty->points < 0) { $loyalty->points = abs((int)$loyalty->points); } } elseif ($orderState->id == $this->loyaltyStateCancel->id_order_state) { $loyalty->id_loyalty_state = WsAdvLoyaltyStateModule::getCancelId(); $loyalty->points = 0; } return $loyalty->save(); } } return false; } public function hookAdminCustomers($params) { include_once($this->dir_loyalty); include_once($this->dir_loyalty_state); $customer = new Customer((int)$params['id_customer']); if ($customer && !Validate::isLoadedObject($customer)) { die($this->l('Incorrect Customer object.')); } $details = WsAdvLoyaltyModule::getAllByIdCustomer((int)$params['id_customer'], (int)$params['cookie']->id_lang); $points = (int)WsAdvLoyaltyModule::getPointsByCustomer((int)$params['id_customer']); $html = '
'.sprintf($this->l('Loyalty points (%d points)'), $points).'
'; if (!isset($points) || count($details) == 0) { return $html.' '.$this->l('This customer has no points').'
'; } $html .= '
'; foreach ($details as $key => $loyalty) { $url = 'index.php?tab=AdminOrders&id_order='.$loyalty['id'].'&vieworder&token='.Tools::getAdminToken('AdminOrders'.(int)Tab::getIdFromClassName('AdminOrders').(int)$params['cookie']->id_employee); $html .= ' '; } $html .= '
'.$this->l('Order').' '.$this->l('Date').' '.$this->l('Total (without shipping)').' '.$this->l('Points').' '.$this->l('Points Status').'
'.((int)$loyalty['id'] > 0 ? ''.sprintf($this->l('#%d'), $loyalty['id']).'' : '--').' '.Tools::displayDate($loyalty['date']).' '.((int)$loyalty['id'] > 0 ? $loyalty['total_without_shipping'] : '--').' '.(int)$loyalty['points'].' '.$loyalty['state'].'
  '.$this->l('Total points available:').' '.$points.' '.$this->l('Voucher value:').' '.Tools::displayPrice( WsAdvLoyaltyModule::getVoucherValue((int)$points, (int)Configuration::get('PS_CURRENCY_DEFAULT')), new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT')) ).'
'; return $html; } /** * Add the CSS & JavaScript files you want to be added on the FO. */ public function hookHeader() { $this->context->controller->addCSS($this->_path.'/views/css/front.css'); } public function hookTop($params) { if ((int)Configuration::get('COUPON_CRON_TYPE') == 2 && (int)Configuration::get('COUPON_BTHD_VOUCHER') && (int)date('Ymd') > (int)Configuration::get('COUPON_BTHD_BATCHLASTDATE')) { WsCoupons::registreBthDiscount(); Configuration::updateValue('COUPON_BTHD_BATCHLASTDATE', date('Ymd')); } //return true; } public function hookShoppingCart($params) { $this->smarty->assign(array( 'points' => 0, 'loyalty_on' => false, 'discount_val' => false, )); if ($this->context->customer->isLogged()) { if (!isset($params['cart']->id_customer)) { return false; } $discount_val = false; $loyalty_on = false; $code = false; //PS16 $customer_discount = Discount::getCustomerDiscounts((int)$this->context->language->id, (int)$params['cart']->id_customer, true); $customer_discount = CartRule::getCustomerCartRules( $this->context->language->id, $this->context->customer->id, $active = true, $includeGeneric = false, $inStock = true ); if (!empty($customer_discount)) { $total = count($customer_discount)-1; if ((float)$customer_discount[$total]["reduction_amount"] > 0) { $discount_val = Tools::displayPrice($customer_discount[$total]["reduction_amount"], $this->context->currency); } else { $discount_val = $customer_discount[$total]["reduction_percent"].chr(37); } $code = $customer_discount[$total]["code"]; } $this->smarty->assign(array( 'discount_val' => $discount_val, 'discount_code' => $code, )); } if (Configuration::get('COUPON_LOYALTY')) { include_once($this->dir_loyalty); if (Validate::isLoadedObject($params['cart'])) { $points = WsAdvLoyaltyModule::getCartNbPoints($params['cart']); if ($this->context->currency) { $currency = (int)$this->context->currency->id; } else { $currency = (int)Configuration::get('PS_CURRENCY_DEFAULT'); } $t_voucher = WsAdvLoyaltyModule::getVoucherValue((int)$points); $this->smarty->assign(array( 'points' => (int)$points, 'voucher' => Product::convertPriceWithCurrency(array('price' => $t_voucher, 'currency' => $currency), $this->smarty), 'guest_checkout' => (int)Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'loyalty_on' => true )); } } return $this->display(__FILE__, 'shopping-cart.tpl'); } public function hookDisplayLeftColumn() { if ($this->context->customer->isLogged()) { //PS16 $customer_discount = Discount::getCustomerDiscounts((int)$this->context->language->id, (int)$this->context->customer->id, true); $customer_discount = CartRule::getCustomerCartRules( $this->context->language->id, $this->context->customer->id, $active = true, $includeGeneric = false, $inStock = true ); if (!empty($customer_discount)) { $total = count($customer_discount)-1; if ((float)$customer_discount[$total]["reduction_amount"] > 0) { $discount_val = Tools::displayPrice($customer_discount[$total]["reduction_amount"], $this->context->currency); } else { $discount_val = $customer_discount[$total]["reduction_percent"].chr(37); } $this->smarty->assign(array('discount_val' => $discount_val)); return $this->display(__FILE__, 'left.tpl'); } } } /* Hook display on customer account page */ public function hookCustomerAccount($params) { if (Configuration::get('COUPON_LOYALTY')) { return $this->display(__FILE__, 'my-account.tpl'); } } /* Hook display on product detail */ public function hookExtraRight($params) { if (Configuration::get('COUPON_LOYALTY')) { include_once($this->dir_loyalty); $product = new Product((int)Tools::getValue('id_product')); if (Validate::isLoadedObject($product)) { if (Validate::isLoadedObject($params['cart'])) { $pointsBefore = (int)WsAdvLoyaltyModule::getCartNbPoints($params['cart']); $pointsAfter = (int)WsAdvLoyaltyModule::getCartNbPoints($params['cart'], $product); $points = (int)($pointsAfter - $pointsBefore); } else { if (!(int)Configuration::get('ADVANCEDLOYALTY_NONE_AWARD') && Product::isDiscounted((int)$product->id)) { $points = 0; $this->smarty->assign('no_pts_discounted', 1); } else { $points = (int)WsAdvLoyaltyModule::getNbPointsByPrice( $product->getPrice( Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, (int)$product->getIdProductAttributeMostExpensive() ) ); } $pointsAfter = $points; $pointsBefore = 0; } $t_voucher = WsAdvLoyaltyModule::getVoucherValue((int)$pointsAfter); if ($this->context->currency) { $currency = (int)$this->context->currency->id; } else { $currency = (int)Configuration::get('PS_CURRENCY_DEFAULT'); } $this->smarty->assign(array( 'points' => (int)$points, 'total_points' => (int)$pointsAfter, 'point_rate' => Configuration::get('ADVANCEDLOYALTY_POINT_RATE'), 'point_value' => Configuration::get('ADVANCEDLOYALTY_POINT_VALUE'), 'points_in_cart' => (int)$pointsBefore, 'voucher' => Product::convertPriceWithCurrency(array('price' => $t_voucher, 'currency' => $currency), $this->smarty), 'none_award' => Configuration::get('ADVANCEDLOYALTY_NONE_AWARD') )); $this->context->controller->addJS(($this->_path).'js/loyalty.js'); return $this->display(__FILE__, 'ws_loyalty_product.tpl'); } } return false; } public function hookProductActions($params) { return $this->hookExtraRight($params); } public function hookDisplayMyAccountBlock($params) { return $this->hookCustomerAccount($params); } public function translateCustom() { return array( 'voucher_duration'=> $this->l('*The number of validity days of the voucher: '), 'bthd_coupon' => $this->l('Congratulations! Happy Birthday!'), ); } public function log($log_message, $file = 'bthd') { $fp = @fopen(_PS_MODULE_DIR_.'advansedcoupons/logs/coupons_'.$file.'_log-'.date('Ymd').'.log', 'a'); @fwrite($fp, date('H\Hi').' '.$log_message.chr(13).chr(10)); @fclose($fp); } public function getLogsFile() { $files = array(); $folder = new DirectoryIterator(_PS_MODULE_DIR_.'advansedcoupons/logs'); foreach ($folder as $file) { if ($file->isFile() && !$file->isDot() && strstr($file->getFilename(), '.log')) { $files[] = $file->getFilename(); } natsort($files); } return ($files); } }