✏️ 正在编辑: AxeptaXml.php
路径:
/home/bpioifn/www/pigmentse/modules/axepta/classes/AxeptaXml.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * 1961-2020 BNP Paribas * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) that is available * through the world-wide-web at this URL: http://www.opensource.org/licenses/OSL-3.0 * If you are unable to obtain it through the world-wide-web, please send an email * to modules@quadra-informatique.fr so we can send you a copy immediately. * * @author Quadra Informatique <modules@quadra-informatique.fr> * @copyright 1961-2020 BNP Paribas * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ class AxeptaXml { const XML_DICTIONNARY_PATH = _PS_MODULE_DIR_.'axepta/tools/computop_dictionnary.xml'; const XML_METHOD_PATH = _PS_MODULE_DIR_.'axepta/tools/computop_methods.xml'; /** * insert xml data to xml table * @return boolean */ public static function insertXmlToDb() { if (Tools::file_get_contents(self::XML_DICTIONNARY_PATH) && Tools::file_get_contents(self::XML_METHOD_PATH)) { self::resetAxeptaXmlDictionnaryTables(); self::resetAxeptaXmlMethodTables(); $xml_payments = simplexml_load_string(Tools::file_get_contents(self::XML_DICTIONNARY_PATH)); $version = (string) $xml_payments->version; // installing action codes $action_codes = $xml_payments->paygate_action_codes->action_codes; foreach ($action_codes as $actions) { foreach ($actions->children() as $row) { $code = (string)$row->code; $message = (string)$row->message; $description = (string)$row->description; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_paygate_action_code`(`code`,`message`,`description`) VALUES("'.pSQL($code).'","'.pSQL($message).'","'.pSQL($description).'")'; Db::getInstance()->execute($sql); } } // installing categories $categories = $xml_payments->paygate_action_codes->categories; foreach ($categories as $categorie) { foreach ($categorie->children() as $row) { $code = (string)$row->code; $message = (string)$row->message; $description = (string)$row->description; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_paygate_category_code`(`code`,`message`,`description`) VALUES("'.pSQL($code).'","'.pSQL($message).'","'.pSQL($description).'")'; Db::getInstance()->execute($sql); } } // installing details_codes $details_codes = $xml_payments->paygate_action_codes->details_codes; foreach ($details_codes as $detail) { foreach ($detail->children() as $row) { $code = (string)$row->code; $message = (string)$row->message; $description = (string)$row->description; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_paygate_detail_code`(`code`,`message`,`description`) VALUES("'.pSQL($code).'","'.pSQL($message).'","'.pSQL($description).'")'; Db::getInstance()->execute($sql); } } $xml_payments = simplexml_load_string(Tools::file_get_contents(self::XML_METHOD_PATH)); //Configuration::updateGlobalValue('AXEPTA_XML_VERSION', $xml_payments->version); // installing parameter set $parameter_sets = $xml_payments->parameter_sets; foreach ($parameter_sets as $parameter_set) { foreach ($parameter_set->children() as $params) { $attributes = $params->attributes(); $parameters = $params->children()->children(); $id_param = (string)$attributes[0]; foreach ($parameters as $row) { $code = (string)$row->code; $message = (string)$row->message; $description = (string)$row->description; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_parameter`(`name`,`format`,`required`,`parameter_set_id`) VALUES("'.pSQL((string)$row->code).'","'.pSQL((string)$row->format).'","'.pSQL((string)$row->required).'","'.pSQL((int)$id_param).'")'; Db::getInstance()->execute($sql); } } } // Insert method payment $payment_method = $xml_payments->methods->children(); foreach ($payment_method as $method) { $method_name = (string)$method->code; $attribute_method = $method->code->attributes(); $trigramme = (string)$attribute_method['trigram']; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_method`(`trigram`,`code`) VALUES("'.pSQL($trigramme).'","'.pSQL($method_name).'")'; Db::getInstance()->execute($sql); $id_current = Db::getInstance()->Insert_ID(); // Insert method payment lang $labels = $method->labels->children(); foreach ($labels as $label) { $attributes = $label->attributes(); $language = (string)$attributes['language']; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_method_lang`(`method_id`,`iso`,`label`) VALUES("'.(int)$id_current.'","'.pSQL($language).'","'.pSQL((string)$label).'")'; Db::getInstance()->execute($sql); } // Insert method payment parameter set $operations = $method->operations->children(); foreach ($operations as $operation) { $attributes_operation = $operation->attributes(); foreach ($attributes_operation as $attribute_operation) { switch ($attribute_operation->getname()) { case 'parameter_set': $id_parameter_set = (int)$attribute_operation; break; case 'code': $code_operation = (string)$attribute_operation; break; default: break; } } $action_urls = $operation->children(); foreach ($action_urls as $action) { $url = (string)$action->url; $url_test = (string)$action->test_url; } // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_parameter_set`(`operation`,`url`,`url_test`,`method_id`,`parameter_set_id`) VALUES("'.pSQL($code_operation).'","'.pSQL($url).'","'.pSQL($url_test).'", "'.(int)$id_current.'", "'.(int)$id_parameter_set.'")'; Db::getInstance()->execute($sql); } // installing allowed countries $countries = $method->allow_countries->children(); foreach ($countries as $country) { $country_allow = (string)$country; $attribute_country = $country->attributes(); $currency = (string)$attribute_country['currency']; // insert in db $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_allow_countries`(`method_id`,`currency`,`country`) VALUES("'.(int)$id_current.'","'.pSQL($currency).'","'.pSQL($country_allow).'")'; Db::getInstance()->execute($sql); } } // Insert payment position $positions = $xml_payments->positions->simple; $sql = 'INSERT INTO `'._DB_PREFIX_.'axepta_xml_paygate_position`(`position`,`iso`,`trigram`,`is_default`)'; $sqlValues = []; foreach ($positions->countries->children() as $country) { $isoCode2 = (string) $country->attributes()->iso; foreach ($country->paygate as $paygatePosition) { $sqlValues[] = '("' . pSQL((string)$paygatePosition->attributes()->pos) . '","' . pSQL(($isoCode2 == 'default') ? null : (string)$isoCode2) . '","' . pSQL((string)$paygatePosition->attributes()->trigram) . '","' . (($isoCode2 == 'default') ? '1' : '0') . '")'; } } if (empty($sqlValues)) { return false; } $sql .= ' VALUES ' . implode(',', $sqlValues); Db::getInstance()->execute($sql); Configuration::updateGlobalValue('AXEPTA_XML_VERSION', $version); return true; } return false; } /** * check if xml tables need to be upgraded * @return boolean */ public static function paymentsNeedUpgrade() { $xml_payments = simplexml_load_string(Tools::file_get_contents(self::XML_METHOD_PATH)); $version = (string) $xml_payments->version; if (Configuration::getGlobalValue('AXEPTA_XML_VERSION') != $version) { return true; } return false; } /** * Truncate xml tables * @return boolean */ public static function resetAxeptaXmlDictionnaryTables() { $sql = 'TRUNCATE `'._DB_PREFIX_.'axepta_xml_paygate_detail_code`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_paygate_category_code`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_paygate_action_code`;'; return Db::getInstance()->execute($sql); } public static function resetAxeptaXmlMethodTables() { $sql = 'TRUNCATE `'._DB_PREFIX_.'axepta_xml_parameter_set`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_parameter`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_method`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_method_lang`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_allow_countries`; TRUNCATE `'._DB_PREFIX_.'axepta_xml_paygate_position`; '; return Db::getInstance()->execute($sql); } }
💾 保存文件
← 返回文件管理器