✏️ 正在编辑: everpsdomtomsecure.php
路径:
/home/bpioifn/www/pigmentse/modules/everpsdomtomsecure/everpsdomtomsecure.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Project : everpsdomtomsecure * @author Team Ever * @copyright Team Ever * @license Tous droits réservés / Le droit d'auteur s'applique (All rights reserved / French copyright law applies) * @link https://www.team-ever.com */ if (!defined('_PS_VERSION_')) { exit; } class Everpsdomtomsecure extends Module { private $html; private $postErrors = array(); private $postSuccess = array(); public function __construct() { $this->name = 'everpsdomtomsecure'; $this->tab = 'shipping_logistics'; $this->version = '1.0.6'; $this->author = 'Team Ever'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Ever PS DOM-TOM secure'); $this->description = $this->l('check if the address is in the DOM-TOM'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->isSeven = Tools::version_compare(_PS_VERSION_, '1.7', '>=') ? true : false; $this->module_key = '0fc13b1751180f84f31a914180fd9bc3'; } /** * 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'); include(dirname(__FILE__).'/sql/insert.php'); Configuration::updateValue('EVERPSDOMTOMSECURE_FRANCE', false); return parent::install() && $this->installModuleTab( 'AdminEverpsdomtomsecureDomtom', 'AdminParentLocalization', $this->l('Dom Tom') ) && $this->registerHook('actionValidateCustomerAddressForm'); } private function installModuleTab($tabClass, $parent, $tabName) { $tab = new Tab(); $tab->active = 1; $tab->class_name = $tabClass; $tab->id_parent = (int)Tab::getIdFromClassName($parent); $tab->position = Tab::getNewLastPosition($tab->id_parent); $tab->module = $this->name; foreach (Language::getLanguages(false) as $lang) { $tab->name[(int)$lang['id_lang']] = $tabName; } return $tab->add(); } public function uninstall() { include(dirname(__FILE__).'/sql/uninstall.php'); Configuration::deleteByName('EVERPSDOMTOMSECURE_FRANCE'); return parent::uninstall() && $this->uninstallModuleTab('AdminEverpsdomtomsecureDomtom'); } private function uninstallModuleTab($tabClass) { $tab = new Tab((int)Tab::getIdFromClassName($tabClass)); return $tab->delete(); } /** * Load the configuration form */ public function getContent() { /** * If values have been submitted in the form, process. */ if (((bool)Tools::isSubmit('submitEverpsdomtomsecureModule')) == true) { $this->postValidation(); if (!count($this->postErrors)) { $this->postProcess(); } } // Display errors if (count($this->postErrors)) { foreach ($this->postErrors as $error) { $this->html .= $this->displayError($error); } } // Display confirmations if (count($this->postSuccess)) { foreach ($this->postSuccess as $success) { $this->html .= $this->displayConfirmation($success); } } $this->context->smarty->assign('everpsdomtomsecure_dir', $this->_path); $this->html .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/header.tpl'); $this->html .= $this->renderForm(); $this->html .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/footer.tpl'); return $this->html; } protected function renderForm() { $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 = 'submitEverpsdomtomsecureModule'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm(array($this->getConfigForm())); } /** * Create the structure of your form. */ protected function getConfigForm() { $countries = Country::getCountries((int)$this->context->language->id, true); return array( 'form' => array( 'legend' => array( 'title' => $this->l('Settings'), 'icon' => 'icon-cogs', ), 'input' => array( array( 'type' => 'select', 'label' => 'Please confirm France country', 'hint' => 'Will get France ID country', 'desc' => 'For DOM-TOM verification', 'name' => 'EVERPSDOMTOMSECURE_FRANCE', 'identifier' => 'name', 'required' => true, 'options' => array( 'query' => $countries, 'id' => 'id_country', 'name' => 'name', ), ), ), 'submit' => array( 'title' => $this->l('Save'), ), ), ); } /** * Set values for the inputs. */ protected function getConfigFormValues() { return array( 'EVERPSDOMTOMSECURE_FRANCE' => Configuration::get('EVERPSDOMTOMSECURE_FRANCE', true) ); } public function postValidation() { if (Tools::isSubmit('submitEverpsdomtomsecureModule')) { if (!Tools::getIsset('EVERPSDOMTOMSECURE_FRANCE') || !Validate::isUnsignedInt(Tools::getValue('EVERPSDOMTOMSECURE_FRANCE')) ) { $this->postErrors[] = $this->l('Error : The field EVERPSDOMTOMSECURE_FRANCE is not valid'); } } } protected function postProcess() { $form_values = $this->getConfigFormValues(); foreach (array_keys($form_values) as $key) { Configuration::updateValue($key, Tools::getValue($key)); } } public function hookActionValidateCustomerAddressForm($params) { $franceId = (int)Configuration::get('EVERPSDOMTOMSECURE_FRANCE'); $id_country = (int)Tools::getValue('id_country'); $postcode = (int)Tools::getValue('postcode'); if ((int)$id_country == (int)$franceId) { if ($this->isAddressDomTom($postcode)) { $this->context->controller->errors[] = $this->l('Incorrect country'); return 0; } } } private function isAddressDomTom($postcode) { $sql = 'SELECT city_name FROM '._DB_PREFIX_.'everpsdomtomsecure WHERE postcode = '.(int)$postcode; $postcode = Db::getInstance()->getValue($sql); if ($postcode) { return $postcode; } else { return false; } } }
💾 保存文件
← 返回文件管理器