Exemplo n.º 1
0
<?php

include dirname(__FILE__) . '/../../../config/config.inc.php';
include dirname(__FILE__) . '/../../../init.php';
include dirname(__FILE__) . '/../mondialrelay.php';
global $cookie;
$cart = new Cart($cookie->id_cart);
$result_MR = Db::getInstance()->ExecuteS("SELECT * FROM " . _DB_PREFIX_ . "mr_method WHERE id_carrier='" . (int) $cart->id_carrier . "' ;");
Db::getInstance()->delete(_DB_PREFIX_ . 'mr_selected', 'id_cart = "' . (int) $cart->id . '"');
$mrselected = new MondialRelayClass();
$mrselected->id_customer = $cart->id_customer;
$mrselected->id_method = $result_MR[0]['id_mr_method'];
$mrselected->id_cart = $cart->id;
$mrselected->MR_Selected_Num = $_POST['Num'];
$mrselected->MR_Selected_LgAdr1 = $_POST['LgAdr1'];
$mrselected->MR_Selected_LgAdr2 = $_POST['LgAdr2'];
$mrselected->MR_Selected_LgAdr3 = $_POST['LgAdr3'];
$mrselected->MR_Selected_LgAdr4 = $_POST['LgAdr4'];
$mrselected->MR_Selected_CP = $_POST['CP'];
$mrselected->MR_Selected_Ville = $_POST['Ville'];
$mrselected->MR_Selected_Pays = $_POST['Pays'];
$mrselected->save();
Exemplo n.º 2
0
 public function hookProcessCarrier($params, $redirect = true)
 {
     $cart = $params['cart'];
     $result_MR = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'mr_method` WHERE `id_carrier` = ' . (int) $cart->id_carrier);
     if (count($result_MR) > 0) {
         $mr_mode_liv = $result_MR[0]['mr_ModeLiv'];
         if ($mr_mode_liv == 'LDS' || $mr_mode_liv == 'LD1') {
             $deliveryAddressLDS = new Address((int) $cart->id_address_delivery);
             if (Validate::isLoadedObject($deliveryAddressLDS) and $deliveryAddressLDS->id_customer == $cart->id_customer) {
                 Db::getInstance()->delete(_DB_PREFIX_ . 'mr_selected', 'id_cart = "' . (int) $cart->id . '"');
                 $mrselected = new MondialRelayClass();
                 $mrselected->id_customer = $cart->id_customer;
                 $mrselected->id_method = $result_MR[0]['id_mr_method'];
                 $mrselected->id_cart = $cart->id;
                 $mrselected->MR_Selected_Num = $mr_mode_liv;
                 $mrselected->save();
             }
         } else {
             if (!Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                 // Redirect is set to false in Presta 1.3 for compatibility
                 // when this method is called under an ajax process
                 if (empty($_POST['MR_Selected_Num_' . $cart->id_carrier]) && $redirect) {
                     // Case error : the customer didn't choose a 'relais' but selected Relais Colis TNT as a carrier
                     Tools::redirect('order.php?step=2&mr_null');
                 } else {
                     Db::getInstance()->delete(_DB_PREFIX_ . 'mr_selected', 'id_cart = "' . (int) $cart->id . '"');
                     $mrselected = new MondialRelayClass();
                     $mrselected->id_customer = $cart->id_customer;
                     $mrselected->id_method = $result_MR[0]['id_mr_method'];
                     $mrselected->id_cart = $cart->id;
                     $mrselected->MR_Selected_Num = $_POST['MR_Selected_Num_' . $cart->id_carrier];
                     $mrselected->MR_Selected_LgAdr1 = $_POST['MR_Selected_LgAdr1_' . $cart->id_carrier];
                     $mrselected->MR_Selected_LgAdr2 = $_POST['MR_Selected_LgAdr2_' . $cart->id_carrier];
                     $mrselected->MR_Selected_LgAdr3 = $_POST['MR_Selected_LgAdr3_' . $cart->id_carrier];
                     $mrselected->MR_Selected_LgAdr4 = $_POST['MR_Selected_LgAdr4_' . $cart->id_carrier];
                     $mrselected->MR_Selected_CP = $_POST['MR_Selected_CP_' . $cart->id_carrier];
                     $mrselected->MR_Selected_Ville = $_POST['MR_Selected_Ville_' . $cart->id_carrier];
                     $mrselected->MR_Selected_Pays = $_POST['MR_Selected_Pays_' . $cart->id_carrier];
                     $mrselected->save();
                 }
             }
         }
     }
 }
    private function _generateetiquettes()
    {
        unset($result);
        $urla4 = '';
        $urla5 = '';
        include_once dirname(__FILE__) . '/mondialrelay.php';
        $mondialrelay = new MondialRelay();
        echo '<p>' . $mondialrelay->getL('List of orders recognized') . '</p>';
        $mr_Enseigne_WebService = Configuration::get('MR_ENSEIGNE_WEBSERVICE');
        $mr_code_marque = Configuration::get('MR_CODE_MARQUE');
        $mr_Key_WebService = Configuration::get('MR_KEY_WEBSERVICE');
        $mr_Langage = Configuration::get('MR_LANGUAGE');
        $mr_Ad1 = Configuration::get('PS_SHOP_NAME');
        $mr_Ad2 = '';
        $mr_Ad3 = Configuration::get('PS_SHOP_ADDR1');
        $mr_Ad4 = Configuration::get('PS_SHOP_ADDR2');
        $mr_Ville = Configuration::get('PS_SHOP_CITY');
        $mr_CP = Configuration::get('PS_SHOP_CODE');
        $mr_Pays = Db::getInstance()->getValue('SELECT c.`iso_code`
												FROM `' . _DB_PREFIX_ . 'country` c
												JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (c.`id_country` = cl.`id_country`)
												WHERE cl.`name` = "' . pSQL(Configuration::get('PS_SHOP_COUNTRY')) . '"
												AND cl.`id_lang` = ' . (int) Configuration::get('PS_LANG_DEFAULT'));
        $mr_Tel1 = Configuration::get('PS_SHOP_PHONE');
        $mr_Tel2 = '';
        $mr_Mail = Configuration::get('PS_SHOP_EMAIL');
        $concatener_id_order = "";
        $concatener_exp_num = "";
        $concatener_error = "";
        if (!empty($mr_Ad1) and !empty($mr_Ad3) and !empty($mr_Ville) and !empty($mr_CP) and !empty($mr_Pays)) {
            foreach ($_POST['order'] as $field) {
                if (is_numeric($field['weight']) and $field['weight'] > 0 and isset($field['selected']) and $field['selected'] == '1') {
                    $customer = new Customer((int) $field['id_customer']);
                    $addressliv = new Address((int) $field['id_address_delivery']);
                    $country = new Country((int) $addressliv->id_country);
                    $params = 'mr_Enseigne_WebService=' . urlencode(free_MR_chaine($mr_Enseigne_WebService));
                    $params .= '&mr_code_marque=' . urlencode(free_MR_chaine($mr_code_marque));
                    $params .= '&mr_Key_WebService=' . urlencode(free_MR_chaine($mr_Key_WebService));
                    $params .= '&ModeCol=' . urlencode(free_MR_chaine($field['mr_ModeCol']));
                    $params .= '&ModeLiv=' . (urlencode(free_MR_chaine($field['mr_ModeLiv'])) == 'LD1' ? 'LDR' : urlencode(free_MR_chaine($field['mr_ModeLiv'])));
                    $params .= '&NDossier=' . urlencode(free_MR_chaine($field['id']));
                    $params .= '&NClient=' . urlencode(free_MR_chaine($field['id_customer']));
                    $params .= '&Expe_Langage=' . urlencode(free_MR_chaine($mr_Langage));
                    $params .= '&Expe_Ad1=' . urlencode(free_MR_chaine($mr_Ad1));
                    $params .= '&Expe_Ad2=' . urlencode(free_MR_chaine($mr_Ad2));
                    $params .= '&Expe_Ad3=' . urlencode(free_MR_chaine($mr_Ad3));
                    $params .= '&Expe_Ad4=' . urlencode(free_MR_chaine($mr_Ad4));
                    $params .= '&Expe_Ville=' . urlencode(free_MR_chaine($mr_Ville));
                    $params .= '&Expe_CP=' . urlencode(free_MR_chaine($mr_CP));
                    $params .= '&Expe_Pays=' . urlencode(free_MR_chaine($mr_Pays));
                    $params .= '&Expe_Tel1=' . urlencode(free_MR_chaine($mr_Tel1));
                    $params .= '&Expe_Tel2=' . urlencode(free_MR_chaine($mr_Tel2));
                    $params .= '&Expe_Mail=' . urlencode(free_MR_chaine($mr_Mail));
                    $params .= '&Dest_Langage=' . urlencode(free_MR_chaine($country->iso_code));
                    $params .= '&Dest_Ad1=' . urlencode(strtoupper(substr(free_MR_chaine($addressliv->lastname) . ' ' . free_MR_chaine($addressliv->firstname), 0, 32)));
                    $params .= '&Dest_Ad2=' . urlencode(strtoupper(substr(free_MR_chaine($addressliv->address2), 0, 32)));
                    $params .= '&Dest_Ad3=' . urlencode(strtoupper(substr(free_MR_chaine($addressliv->address1), 0, 32)));
                    $params .= '&Dest_Ad4=' . urlencode(strtoupper(substr(substr(free_MR_chaine($addressliv->address1), 32), 0, 32)));
                    $params .= '&Dest_Ville=' . urlencode(strtoupper(substr(free_MR_chaine($addressliv->city), 0, 26)));
                    $params .= '&Dest_CP=' . urlencode(strtoupper(substr(free_MR_chaine($addressliv->postcode), 0, 5)));
                    $params .= '&Dest_Pays=' . urlencode($country->iso_code);
                    $params .= '&Dest_Tel1=' . urlencode(free_MR_chaine($addressliv->phone ? $addressliv->phone : ''));
                    $params .= '&Dest_Tel2=' . urlencode(free_MR_chaine($addressliv->phone_mobile ? $addressliv->phone_mobile : ''));
                    $params .= '&Dest_Mail=' . urlencode(free_MR_chaine(strtoupper(substr($customer->email, 0, 70))));
                    while (strlen($field['weight']) < 3) {
                        $field['weight'] = '0' . $field['weight'];
                    }
                    $params .= '&Poids=' . urlencode(free_MR_chaine($field['weight']));
                    $params .= '&Longueur=';
                    $params .= '&Taille=';
                    $params .= '&NbColis=1';
                    $params .= '&CRT_Valeur=0';
                    $params .= '&CRT_Devise=EUR';
                    $params .= '&Exp_Valeur=';
                    $params .= '&Exp_Devise=';
                    if ($field['MR_Selected_Num'] == 'LD1' or $field['MR_Selected_Num'] == 'LDS') {
                        $params .= '&LIV_Rel_Pays=';
                        $params .= '&LIV_Rel=';
                    } else {
                        $params .= '&LIV_Rel_Pays=' . $field['MR_Selected_Pays'];
                        $params .= '&LIV_Rel=' . $field['MR_Selected_Num'];
                    }
                    $params .= '&Assurance=' . urlencode(free_MR_chaine($field['mr_ModeAss']));
                    $params .= '&Instructions=';
                    $params .= '&Texte=';
                    $result = _get('http', htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8'), '80', __PS_BASE_URI__ . 'modules/mondialrelay/kit_mondialrelay/CreationEtiquettePointRelais_ajax.php', $params);
                    $result = explode('|', $result);
                    if ($result[0] == 'a') {
                        $concatener_error .= '<b>Order ID = ' . $field['id'] . '</b><br>' . $result[1] . '<hr>';
                    } elseif ($result[0] != '0') {
                        $concatener_error .= '<b>Order ID = ' . $field['id'] . '</b><br>Error nb ' . $result[0] . '<br>' . $result[1] . '<hr>';
                    } elseif ($result[0] == '0') {
                        $mondialrelayclass = new MondialRelayClass($field['id_mr_selected']);
                        $mondialrelayclass->id_order = $field['id'];
                        $mondialrelayclass->MR_poids = $field['weight'];
                        $mondialrelayclass->exp_number = $result[1];
                        $mondialrelayclass->url_etiquette = $result[2];
                        $mondialrelayclass->url_suivi = $result[3];
                        $mondialrelayclass->save();
                        $concatener_id_order .= $field['id'] . ';';
                        $concatener_exp_num .= $result[1] . ';';
                        $order = new Order((int) $field['id']);
                        $order->shipping_number = $field['id_mr_selected'];
                        $order->update();
                        $templateVars = array('{followup}' => $result[3]);
                        $history = new OrderHistory();
                        $history->id_order = (int) $field['id'];
                        $history->changeIdOrderState(_PS_OS_SHIPPING_, (int) $field['id']);
                        $history->id_employee = (int) $cookie->id_employee;
                        $history->addWithemail(true, $templateVars);
                        echo '<li>' . $mondialrelay->getL('Order number') . ':&nbsp;' . $field['id'];
                        echo ' - ' . $mondialrelay->getL('Email send to') . ':&nbsp;' . $customer->email;
                        echo "</li>\n";
                    }
                    unset($result);
                }
            }
        } else {
            $concatener_error .= $mondialrelay->getL('Empty adress : Are you sure you\'ve set a validate address in the Contact page?');
        }
        $concatener_id_order = substr($concatener_id_order, 0, -1);
        $concatener_exp_num = substr($concatener_exp_num, 0, -1);
        if (trim($concatener_exp_num) > 0) {
            $params = 'mr_Enseigne_WebService=' . urlencode($mr_Enseigne_WebService);
            $params .= '&mr_Key_WebService=' . urlencode($mr_Key_WebService);
            $params .= '&Langue=' . urlencode($mr_Langage);
            $params .= '&Expeditions=' . $concatener_exp_num;
            $result = _get('http', htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8'), '80', __PS_BASE_URI__ . 'modules/mondialrelay/kit_mondialrelay/ImpressionEtiquettePointRelais_ajax.php', $params);
            $result = explode('|', $result);
            if ($result[0] == 'a') {
                $concatener_error .= '<b>Creation url etiquettes</b><br>' . $result[1] . '<hr>';
            } elseif ($result[0] != '0') {
                $concatener_error .= '<b>Creation url etiquettes</b><br>Error nb ' . $result[0] . '<br>' . $result[1] . '<hr>';
            } elseif ($result[0] == '0') {
                $urla4 = $result[1];
                $urla5 = $result[2];
                $query = "INSERT INTO " . _DB_PREFIX_ . "mr_historique (`order` ,`exp` ,`url_a4` ,`url_a5`) \n\t\t\t\t\t\tVALUES ( '" . pSQL($concatener_id_order) . "','" . pSQL($concatener_exp_num) . "', '" . pSQL($result[1]) . "', '" . pSQL($result[2]) . "');";
                $query = Db::getInstance()->Execute($query);
            }
            //curl_close($ch);
        }
        if (trim($concatener_error) != '') {
            echo '<div class="alert">' . $concatener_error . '</div>';
        } else {
            Tools::redirectAdmin('index.php?tab=AdminMondialRelay&updatesuccess&token=' . $this->token);
        }
        return true;
    }