示例#1
0
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 *  @author PrestaShop SA <*****@*****.**>
 *  @copyright  2007-2014 PrestaShop SA
 *  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 *  International Registered Trademark & Property of PrestaShop SA
 */
include_once 'lib/includes/includes.inc.php';
require_once dirname(__FILE__) . '/../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../init.php';
include_once 'fianetsceau.php';
if (_PS_VERSION_ < '1.5') {
    $sceau = new Sceau();
} else {
    $sceau = new Sceau(Tools::getValue('id_shop'));
}
if (Tools::getValue('token') == Tools::getAdminToken($sceau->getSiteid() . $sceau->getAuthkey() . $sceau->getLogin())) {
    $category_id = Tools::getValue('category_id');
    $elem_id = Tools::getValue('elem_id');
    $module = new FianetSceau();
    $subcategory = $module->loadFianetSubCategories($category_id);
    if ($category_id == '0') {
        $select = "";
    } else {
        $select = "<select id='fianetsceau_" . $elem_id . "_subcategory' name='fianetsceau_" . $elem_id . "_subcategory'>";
        foreach ($subcategory as $value) {
            $select .= "<option value=" . $value['subcategory_id'] . ">" . $value['label'] . "</option>";
        }
        $select .= "</select>";
    }
 /**
  * build xml with customer's and order's data et send it to FIA-NET
  * 
  * @param int $id_order
  * @return boolean 
  */
 public function sendXML($id_order)
 {
     $order = new Order($id_order);
     $montant = $order->total_paid;
     $date = $order->date_add;
     $customer = new Customer($order->id_customer);
     $lastname = $customer->lastname;
     $firstname = $customer->firstname;
     $id_currency = $order->id_currency;
     $currency = new Currency($id_currency);
     if (_PS_VERSION_ < '1.5') {
         $civility = $customer->id_gender;
         $accepted_civility = array("1", "2", "3");
         if (!in_array($civility, $accepted_civility)) {
             $civility = '1';
         }
     } else {
         $gender = new Gender($customer->id_gender);
         $id_lang = Language::getIdByIso($this->context->language->iso_code);
         $civility = $gender->name[$id_lang] == 'Mr.' ? 1 : 2;
     }
     //xml construction
     if (_PS_VERSION_ < '1.5') {
         $fianetsceau = new Sceau();
     } else {
         $fianetsceau = new Sceau((int) $order->id_shop);
     }
     $utilisateur = new SceauXMLElement('<utilisateur></utilisateur>');
     $nom = $utilisateur->childNom($customer->lastname);
     $nom->addAttribute('titre', $civility);
     $utilisateur->childPrenom($customer->firstname);
     $utilisateur->childEmail(strtolower($customer->email));
     $infocommande = new SceauXMLElement('<infocommande></infocommande>');
     $infocommande->childSiteid($fianetsceau->getSiteid());
     $infocommande->childRefid($id_order);
     $montant = $infocommande->childMontant($order->total_paid);
     $montant->addAttribute('devise', $currency->iso_code);
     $ip = new SceauXMLElement('<ip>' . $this->getCustomerIP($id_order) . '</ip>');
     $ip->addAttribute('timestamp', $order->date_add);
     $infocommande->childIp($ip);
     $paiement = new SceauXMLElement('<paiement></paiement>');
     $paiement->childType($this->getPaymentFianetType($id_order));
     $lang = Language::getIsoById($order->id_lang);
     $langue = $infocommande->childLangue($lang);
     $xml_order = new SceauControl();
     $xml_order->childUtilisateur($utilisateur);
     $xml_order->childInfocommande($infocommande);
     $xml_order->childPaiement($paiement);
     $fianetsceau->addCrypt($xml_order);
     $result = $fianetsceau->sendSendrating($xml_order);
     if (!($result === false)) {
         $resxml = new SceauXMLElement($result);
         if ($resxml->getAttribute('type') != "OK") {
             //update fianetsceau_state 3:error
             $this->updateOrder($id_order, array('id_fianetsceau_state' => '3'));
             SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' XML Send error : ' . $resxml->getChildByName('detail')->getValue());
             return false;
         } else {
             //update fianetsceau_state 2:sent
             $this->updateOrder($id_order, array('id_fianetsceau_state' => '2'));
         }
         return true;
     } else {
         //update fianetsceau_state 3:error
         $this->updateOrder($id_order, array('id_fianetsceau_state' => '3'));
         SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' XML Send error : ' . $resxml->getChildByName('detail')->getValue());
         return false;
     }
 }
示例#3
0
 public function getContent()
 {
     $head_msg = '';
     //if some POST datas are found
     //Get log file
     $log_content = htmlentities(SceauLogger::getLogContent());
     if (_PS_VERSION_ < '1.5') {
         $id_shop = 1;
         $fianetsceau = new Sceau();
     } else {
         $id_shop = Context::getContext()->shop->id;
         $fianetsceau = new Sceau($id_shop);
     }
     //include FIA-NET categories array
     include _PS_MODULE_DIR_ . 'fianetsceau/lib/includes/fianetcategories.inc.php';
     if (Tools::isSubmit('submitSettings')) {
         //if the form is correctly saved
         if ($this->processForm()) {
             //adds a confirmation message
             $head_msg = $this->displayConfirmation($this->l('Configuration updated.'));
         } else {
             //if errors have been encountered while validating the form
             //add an error message informing about errors that have been encountered
             $error_msg = $this->l('Some errors have been encoutered while updating configuration.');
             $error_msg .= '<ul>';
             foreach ($this->_errors as $error_label) {
                 $error_msg .= '<li>' . $error_label . '</li>';
             }
             $error_msg .= '</ul>';
             $head_msg = $this->displayError($error_msg);
         }
         //if submit form, we save data form
         $login = Tools::isSubmit('fianetsceau_login') ? Tools::getValue('fianetsceau_login') : $fianetsceau->getLogin();
         $password = Tools::isSubmit('fianetsceau_password') ? Tools::getValue('fianetsceau_password') : $fianetsceau->getPassword();
         $siteid = Tools::isSubmit('fianetsceau_siteid') ? Tools::getValue('fianetsceau_siteid') : $fianetsceau->getSiteid();
         $authkey = Tools::isSubmit('fianetsceau_authkey') ? Tools::getValue('fianetsceau_authkey') : $fianetsceau->getAuthkey();
         $status = Tools::isSubmit('fianetsceau_status') ? Tools::getValue('fianetsceau_status') : $fianetsceau->getStatus();
         $fianetsceau_logo_position = Tools::getValue('fianetsceau_logo_position');
         $fianetsceau_widget_position = Tools::getValue('fianetsceau_widget_position');
         $fianetsceau_logo = Tools::getValue('fianetsceau_logo_sizes');
         $widget_number = Tools::getValue('fianetsceau_widget_number');
         $show_status = Tools::getValue('fianetsceau_showstatus');
         $fianetsceau_default_category = Tools::getValue('fianetsceau_0_category');
         $fianetsceau_default_subcategory = Tools::getValue('fianetsceau_0_subcategory');
     } else {
         //if no submit form and 0 value in database, we put a defaut value
         $login = Configuration::get('FIANETSCEAU_LOGIN') === false ? '' : Configuration::get('FIANETSCEAU_LOGIN');
         $password = Configuration::get('FIANETSCEAU_PASSWORD') === false ? '' : Configuration::get('FIANETSCEAU_PASSWORD');
         $siteid = Configuration::get('FIANETSCEAU_SITEID') === false ? '' : Configuration::get('FIANETSCEAU_SITEID');
         $authkey = Configuration::get('FIANETSCEAU_AUTHKEY') === false ? '' : Configuration::get('FIANETSCEAU_AUTHKEY');
         $status = Configuration::get('FIANETSCEAU_STATUS') === false ? 'test' : Configuration::get('FIANETSCEAU_STATUS');
         $fianetsceau_logo_position = Configuration::get('FIANETSCEAU_LOGO_POSITION') === false ? 'left' : Configuration::get('FIANETSCEAU_LOGO_POSITION');
         $fianetsceau_widget_position = Configuration::get('FIANETSCEAU_WIDGET_POSITION') === false ? 'left' : Configuration::get('FIANETSCEAU_WIDGET_POSITION');
         $fianetsceau_logo = Configuration::get('FIANETSCEAU_LOGO_SIZE') === false ? '120' : Configuration::get('FIANETSCEAU_LOGO_SIZE');
         $widget_number = Configuration::get('FIANETSCEAU_WIDGET_NUMBER') === false ? '1' : Configuration::get('FIANETSCEAU_WIDGET_NUMBER');
         $show_status = Configuration::get('FIANETSCEAU_SHOW_STATUS_ORDER') === false ? '0' : Configuration::get('FIANETSCEAU_SHOW_STATUS_ORDER');
         $fianetsceau_default_subcategory = $this->getFianetSubCategoryId(0, $id_shop);
         $fianetsceau_default_category = $this->getFianetCategoryId($fianetsceau_default_subcategory);
     }
     //token
     $token = Tools::getAdminToken($fianetsceau->getSiteid() . $fianetsceau->getAuthkey() . $fianetsceau->getLogin());
     //listing payment type of the shop
     $payment_modules = $this->loadPaymentMethods();
     //lists all categories
     $shop_categories = $this->loadProductCategories();
     $base_url = __PS_BASE_URI__;
     $logo_sizes = array();
     foreach ($this->_fianetsceau_logo_sizes as $size => $img_name) {
         $logo_sizes[$size] = $base_url . 'modules/' . $this->name . '/img/' . $img_name;
     }
     $iso_lang_current = $this->context->language->iso_code;
     //give smarty data to the view
     $this->smarty->assign(array('head_message' => $head_msg, 'image_path' => $base_url . 'modules/' . $this->name . '/img/sceaudeconfiance.png', 'fianetsceau_login' => Tools::safeOutput($login), 'fianetsceau_password' => Tools::safeOutput($password), 'fianetsceau_siteid' => Tools::safeOutput($siteid), 'fianetsceau_authkey' => Tools::safeOutput($authkey), 'fianetsceau_status' => Tools::safeOutput($status), 'fianetsceau_statuses' => $this->_fianetsceau_statuses, 'payment_modules' => $payment_modules, 'fianetsceau_payment_types' => $this->_payment_types, 'logo_account_path' => $base_url . 'modules/' . $this->name . '/img/account.gif', 'logo_payments_path' => $base_url . 'modules/' . $this->name . '/img/payments.gif', 'fianetsceau_logo_positions' => $this->_fianetsceau_positions[$iso_lang_current], 'fianetsceau_logo_position' => Tools::safeOutput($fianetsceau_logo_position), 'fianetsceau_logo_sizes' => $logo_sizes, 'fianetsceau_logo' => (int) $fianetsceau_logo, 'fianetsceau_widget_positions' => $this->_fianetsceau_positions[$iso_lang_current], 'fianetsceau_widget_position' => Tools::safeOutput($fianetsceau_widget_position), 'fianetsceau_widget_numbers' => array_keys($this->_fianetsceau_widgets), 'widget_number' => (int) $widget_number, 'path_prefix' => $base_url . 'modules/' . $this->name . '/img', 'fianetsceaushow_status' => (int) $show_status, 'log_content' => $log_content, 'shop_categories' => $shop_categories, 'fianetsceau_default_category' => Tools::safeOutput($fianetsceau_default_category), 'fianetsceau_default_subcategory' => Tools::safeOutput($fianetsceau_default_subcategory), 'logo_categories_path' => $base_url . 'modules/' . $this->name . '/img/categories.gif', 'fianetsceau_categories' => $_fianetsceau_categories, 'fianetsceau_subcategories' => $_fianetsceau_subcategories, 'token' => $token, 'id_shop' => $id_shop));
     //view selection by prestashop 1.4 or 1.5
     return $this->display(__FILE__, '/views/templates/admin/admin.tpl');
 }