* @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 .= '
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->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')) ).' | ||