Esempio n. 1
0
//**CALL API
//FROM //IRONOVA ADDRESS
$from = array("pays" => "FR", "code_postal" => "13382", "type" => "particulier", "ville" => "Marseille");
// //TO
$to = array("pays" => $country_to, "code_postal" => $zip_to, "type" => "particulier", "ville" => $city_to);
//TO: DEBUG
// $to = array(
// 	"pays"        => "AU",
// 	"code_postal" => "2000",
// 	"type"        => "particulier",
// 	"ville"       => "Sydney"
// );
//DELIVERY INFORMATION
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => $productCategory, "colis.valeur" => $t_product, "colis.description" => "Bracelets Iro (wearable)");
//INITIALIZE CLASS
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
//INITIALIZE FROM AND TO
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
//INITIALIZE WORKSPACE ENVIRONMENT
$cotCl->setEnv("test");
//INITIALIZE TYPE OF CONTENT
$cotCl->setType("colis", array(1 => array("poids" => $t_weight, "longueur" => $t_depth, "largeur" => $t_width, "hauteur" => $t_height)));
//GET QUOTATION
$orderPassed = $cotCl->getQuotation($quotInfo);
//IF NOT CURL ERROR
if (!$cotCl->curlError) {
    print_r($pointCl->respErrorsList);
    //IF NOT REQUEST ERROR DISPLAY RESULT
    if (!$cotCl->respError) {
        $cotCl->getOffers(true);
Esempio n. 2
0
 *  dont la catégorie de contenu est Journaux). On a besoin d'adresses exactes afin de pouvoir détermines les points relais pour 
 *  le service RelaisColis.
 */
require_once '../utils/header.php';
ob_start();
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once '../utils/autoload.php';
$quotationStyle = 'style="font-weight:bold;"';
// Précision de l'expéditeur et du destinataire
$to = array("pays" => "FR", "code_postal" => "75002", "ville" => "Paris", "type" => "particulier", "adresse" => "41, rue Saint Augustin");
$from = array("pays" => "FR", "code_postal" => "13002", "ville" => "Marseille", "type" => "particulier", "adresse" => "1, rue Chape");
// Informations sur la cotation (date d'enlèvement, le délai, le code de contenu)
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120);
// Initialisation de la classe
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
// Initialisation de l'expéditeur et du destinataire
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
// Précision de l'environnement de travail
$cotCl->setEnv('test');
// Initialisation du type d'envoi
$cotCl->setType("colis", array(1 => array("poids" => 2, "longueur" => 18, "largeur" => 18, "hauteur" => 18)));
$cotCl->getQuotation($quotInfo);
// Si pas d'erreur CURL
if (!$cotCl->curlError) {
    print_r($pointCl->respErrorsList);
    // Si pas d'erreurs de la requête, on affiche le résultat
    if (!$cotCl->respError) {
        $cotCl->getOffers(false);
        ?>
Esempio n. 3
0
// $req->execute(array($productID));
// while($product = $req->fetch()){
// 	$weight = $product['weight'];
// 	$depth = $product['depth'];
// 	$width  = $product['width'];
// 	$height = $product['height'];
// }
//CALL API
//FROM
$from = array("pays" => "FR", "code_postal" => "13382", "type" => "particulier", "ville" => "Marseille");
//TO
$to = array("pays" => "FR", "code_postal" => "75011", "type" => "particulier", "ville" => "Paris");
//INFO
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 80200);
//API INFO
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
//INITIALIZE SHIPPER AND RECIPIENT
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
//WORKSPACE ENVIRONMENT
$cotCl->setEnv('test');
//INITIALIZE TYPE SEND
$cotCl->setType($type_send, array(1 => array("poids" => 0.13, "longueur" => 17.4, "largeur" => 13.4, "hauteur" => 5)));
$cotCl->getQuotation($quotInfo);
if (!$cotCl->respError) {
    $cotCl->getOffers(false);
    echo json_encode($cotCl);
} else {
    echo 'Requete non valide<br>';
    // echo 'Category: '.$category.'<br>';
    // echo 'Zip: '.$cp_to.'<br>';
<?php

/*  Cet exemple vous permet de passer une commande avec l'assurance.
 */
ob_start();
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once '../utils/header.php';
require_once '../utils/autoload.php';
$orderPMAStyle = 'style="font-weight:bold;"';
// Informations sur l'expéditeur et le destinataire
$from = array("pays" => "FR", "code_postal" => "75002", "type" => "particulier", "ville" => "Paris", "adresse" => "41, rue Saint-Augustin | 3e étage", "civilite" => "M", "prenom" => "Développeur", "nom" => "Boxtale", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "Frapper 3 fois");
$to = array("pays" => "FR", "code_postal" => "13005", "type" => "particulier", "ville" => "Marseille", "adresse" => "1, rue Saint-Thome", "civilite" => "Mme", "prenom" => "Autre prénom", "nom" => "Nom du destinataire", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "");
// Informations sur la cotation
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120, "operateur" => "UPSE", "disponibilite.HDE" => "09:00", "disponibilite.HLE" => "19:00", "assurance.selection" => true, "valeur" => 120, "prix_max_ttc" => 40, "description" => "Le Monde, années 1990-1992");
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
$cotCl->setType("colis", array(1 => array("poids" => 2, "longueur" => 30, "largeur" => 44, "hauteur" => 44)));
$orderPassed = $cotCl->makeOrder($quotInfo, true);
if (!$cotCl->curlError && !$cotCl->respError) {
    if ($orderPassed) {
        echo "L'envoi a été correctement réalisé sous référence " . $cotCl->order['ref'];
    } else {
        echo "L'envoi n'a pas été correctement réalisé. Une erreur s'est produite.";
    }
} elseif ($cotCl->respError) {
    echo "La requête n'est pas valide : ";
    foreach ($cotCl->respErrorsList as $m => $message) {
        echo "<br />" . $message['message'];
    }
 /**
  * To make order  when order is updated
  */
 function onAfterOrderUpdate(&$order, &$send_email)
 {
     $order_type = isset($order->order_type) ? $order->order_type : $order->old->order_type;
     if ($order_type != 'sale' || empty($order->order_status)) {
         return;
     }
     // To check the type of the order. if EMC params is empty, no method envoimoinscher has been used
     if (!isset($order->order_shipping_params->EMC_params)) {
         return;
     }
     if (!$this->init()) {
         return false;
     }
     $config = hikashop_config();
     $order_confirmed_status = $config->get('order_confirmed_status', 'confirmed');
     $invoice_order_statuses = explode(',', $config->get('invoice_order_statuses', 'confirmed,shipped'));
     if (empty($invoice_order_statuses)) {
         $invoice_order_statuses = array('confirmed', 'shipped');
     }
     //if order status is "created" we do anything
     if ($order->order_status != $order_confirmed_status && !in_array($order->order_status, $invoice_order_statuses)) {
         return;
     }
     $order_shipping_params = isset($order->order_shipping_params) ? $order->order_shipping_params : $order->old->order_shipping_params;
     if (is_string($order_shipping_params)) {
         $order_shipping_params = unserialize($order_shipping_params);
     }
     /*
      * test if makeOrder has already been done once
      * if there was an error with one, we can't redo
      * we can improve this so we can redo those who had an error with the makeOrder
      */
     $ref_exist = false;
     foreach ($order_shipping_params->EMC_params as $value) {
         if (!empty($value['reference'])) {
             $ref_exist = true;
         }
     }
     if ($ref_exist == true) {
         return;
     }
     $db = JFactory::getDBO();
     $orderClass = hikashop_get('class.order');
     $fullOrder = $orderClass->loadFullOrder($order->order_id, true, false);
     // we group products by warehouse and shipping method
     //
     $tab_products = array();
     foreach ($fullOrder->order_shipping_params->EMC_params as $key => $value) {
         $data = array('products' => array());
         foreach ($fullOrder->products as $k => $product) {
             if ($product->order_product_shipping_method != 'envoimoinscher') {
                 continue;
             }
             if ($key == $product->order_product_shipping_id) {
                 $ids_products = explode('@', $product->order_product_shipping_id);
                 $warehouse_id = $ids_products[1];
                 $data['products'][] = $product;
             }
         }
         if (!empty($data['products'])) {
             $data['warehouse_id'] = $warehouse_id;
             $data['shipping_id'] = $ids_products[0];
             $tab_products[] = $data;
         }
     }
     // Get the destination country
     //
     $czone_code_to = @$fullOrder->shipping_address->address_country;
     $query = 'SELECT zone_id, zone_code_2 FROM ' . hikashop_table('zone') . ' WHERE zone_name_english = ' . $db->Quote($czone_code_to);
     $db->setQuery($query);
     $czone = $db->loadObject();
     $country_to = $czone->zone_code_2;
     if ($country_to == 'FX') {
         $country_to = 'FR';
     }
     $user_address_title = $fullOrder->shipping_address->address_title;
     $key = 'HIKA_TITLE_' . strtoupper($user_address_title);
     if ($key != JText::_($key)) {
         $user_address_title = JText::_($key);
     }
     $email = @$fullOrder->customer->user_email;
     $phone = @$fullOrder->shipping_address->address_telephone;
     // for each group we collect all informations to send the request makeOrder
     //
     foreach ($tab_products as $key => $value) {
         $shipping_ids = explode('-', $value['shipping_id']);
         $this->pluginParams($shipping_ids[0]);
         // check if option make order is disabled
         if ($this->plugin_params->make_order == 0) {
             continue;
         }
         // receiver informations
         if ($this->plugin_params->destination_type == 'res' || $this->plugin_params->destination_type == 'auto' && empty($fullOrder->shipping_address->address_company)) {
             $user_type = 'particulier';
         } else {
             $user_type = 'entreprise';
         }
         if (empty($email) || empty($phone)) {
             return;
         }
         $to = array('pays' => $country_to, 'code_postal' => $fullOrder->shipping_address->address_post_code, 'type' => $user_type, 'ville' => $fullOrder->shipping_address->address_city, 'adresse' => $fullOrder->shipping_address->address_street, 'civilite' => $user_address_title, 'prenom' => $fullOrder->shipping_address->address_firstname, 'nom' => $fullOrder->shipping_address->address_lastname, 'email' => $email, 'tel' => $phone);
         // sender informations
         $admin_address_title = $this->plugin_params->sender_civility;
         $key = 'HIKA_TITLE_' . strtoupper($admin_address_title);
         if ($key != JText::_($key)) {
             $admin_address_title = JText::_($key);
         }
         $czone_code_from = @$this->plugin_params->sender_country;
         $query = 'SELECT zone_id, zone_code_2 FROM ' . hikashop_table('zone') . ' WHERE zone_namekey = ' . $db->Quote($czone_code_from);
         $db->setQuery($query);
         $czone = $db->loadObject();
         $country_from = $czone->zone_code_2;
         if ($country_from == 'FX') {
             $country_from = 'FR';
         }
         $from = array('pays' => $country_from, 'code_postal' => $this->plugin_params->sender_postcode, 'type' => $this->plugin_params->type, 'ville' => $this->plugin_params->sender_city, 'adresse' => $this->plugin_params->sender_address, 'civilite' => $admin_address_title, 'prenom' => $this->plugin_params->sender_firstname, 'nom' => $this->plugin_params->sender_lastname, 'email' => $this->plugin_params->sender_email, 'tel' => $this->plugin_params->sender_phone);
         if ($this->plugin_params->type == 'entreprise') {
             $from['societe'] = $this->plugin_params->sender_company;
         }
         $code = (int) $this->plugin_params->product_category;
         $shipping = explode(' / ', $shipping_ids[1]);
         $service = $shipping[1];
         $shipping = $value['shipping_id'] . '@' . $value['warehouse_id'];
         // We get the drop off point, pick up and code for the shipping method
         foreach ($fullOrder->order_shipping_params->EMC_params as $k => $v) {
             if ($k == $shipping) {
                 $dropoff = explode('<br/>', $v['drop_off']);
                 $pickup = explode('<br/>', $v['pick_up']);
                 $ope = $v['code'];
             }
         }
         $sending_type = strtolower($this->plugin_params->sending_type);
         $collection = $dropoff[0];
         $delivery = $pickup[0];
         // >rray that contains informations about sending
         $quotInfo = array('collecte' => date('Y-m-d'), 'delai' => 'aucun', 'code_contenu' => $code, 'type_emballage.emballage' => 1, 'operateur' => $ope, 'raison' => 'sale', 'service' => $service, 'collection_type' => $collection, 'delivery_type' => $delivery, 'depot.pointrelais' => '', 'retrait.pointrelais' => '', $sending_type . '.description' => '');
         // if there is drop off or pick up point
         if ($collection == 'POST_OFFICE' || $collection == 'DROPOFF_POINT') {
             $quotInfo['depot.pointrelais'] = $dropoff[2];
         }
         if ($delivery == 'PICKUP_POINT') {
             $quotInfo['retrait.pointrelais'] = $pickup[2];
         }
         // the availability for the collection of the package by the carrier, compulsory for some offers
         if (isset($this->plugin_params->start_availability) && !empty($this->plugin_params->start_availability)) {
             $quotInfo['disponibilite.HDE'] = $this->plugin_params->start_availability;
         }
         if (isset($this->plugin_params->end_availability) && !empty($this->plugin_params->end_availability)) {
             $quotInfo['disponibilite.HLE'] = $this->plugin_params->end_availability;
         }
         foreach ($value['products'] as $product) {
             $quotInfo[$sending_type . '.description'] .= '  ' . $product->order_product_name;
         }
         $productClass = hikashop_get('class.product');
         $newOrder = new stdClass();
         // To create a new array order to use the function getData before makeOrder
         // It must be structured in the same way. We set in the array just the necessary data
         //
         foreach ($value['products'] as $p) {
             $product = $productClass->get($p->product_id);
             if ($product->product_parent_id != 0) {
                 // Processing variant product
                 //
                 $parent = $productClass->get($product->product_parent_id);
                 $newProduct = $parent;
                 $newProduct->variants = array(0 => $product);
                 if ($product->product_width == 0 && $product->product_length == 0) {
                     $product->product_width = $parent->product_width;
                     $product->product_length = $parent->product_length;
                     $product->product_height = $parent->product_height;
                 }
                 $product->cart_product_quantity = (int) $p->order_product_quantity;
                 $product->product_weight_orig = $parent->product_weight;
                 $product->product_weight_unit_orig = $parent->product_weight_unit;
                 $product->product_dimension_unit_orig = $parent->product_dimension_unit;
                 //
                 $price = new stdClass();
                 $price->unit_price = new stdClass();
                 $price->unit_price->price_value_with_tax = $p->order_product_price + $p->order_product_tax;
                 //
                 $product->prices = array(0 => $price);
                 //
                 $newOrder->products[] = $newProduct;
             } else {
                 // Processing main product
                 //
                 $product->cart_product_quantity = (int) $p->order_product_quantity;
                 $product->product_weight_orig = $product->product_weight;
                 $product->product_weight_unit_orig = $product->product_weight_unit;
                 $product->product_dimension_unit_orig = $product->product_dimension_unit;
                 //
                 $price = new stdClass();
                 $price->unit_price = new stdClass();
                 $price->unit_price->price_value_with_tax = $p->order_product_price + $p->order_product_tax;
                 //
                 $product->prices = array(0 => $price);
                 //
                 $newOrder->products[] = $product;
             }
         }
         /*
          * makeOrder = true in order not to get receiver and sender infos because we already did it
          * and for the makeOrder we have to give more informations
          */
         $data = $this->getData(null, $this, $newOrder, $sending_type, true);
         $total_price = (int) $data[0]["price"];
         unset($data[0]);
         $quotInfo[$sending_type . '.valeur'] = $total_price;
         $cotCl = new Env_Quotation(array('user' => $this->plugin_params->emc_login, 'pass' => $this->plugin_params->emc_password, 'key' => $this->plugin_params->api_key));
         $cotCl->setEnv($this->plugin_params->environment);
         $config = hikashop_config();
         $contentCl->setPlatformParams('hikashop', $config->get('version'), $config->get('version'));
         $cotCl->setPerson('expediteur', $from);
         $cotCl->setPerson('destinataire', $to);
         $cotCl->setType($sending_type, $data);
         /*
          * for shipments to the international we have to send more informations for each product
          * we call the function setProforma of the library for this
          */
         if ($country_to != $country_from) {
             $infos_products = array();
             $i = 1;
             foreach ($newOrder->products as $product) {
                 if (isset($product->variants)) {
                     $nb = $product->variants[0]->cart_product_quantity;
                     $price = $product->variants[0]->prices[0]->unit_price->price_value_with_tax;
                     $weight = $product->variants[0]->product_weight_orig;
                 } else {
                     $nb = $product->cart_product_quantity;
                     $price = $product->prices[0]->unit_price->price_value_with_tax;
                     $weight = $product->product_weight_orig;
                 }
                 $infos_products[$i++] = array('description_en' => $product->product_name, 'description_fr' => $product->product_name, 'nombr' => $nb, 'valeur' => $price, 'origine' => $country_from, 'poids' => $weight);
             }
             $cotCl->setProforma($infos_products);
         }
         // send request to make order !!
         $orderPassed = $cotCl->makeOrder($quotInfo, true);
         if (!$cotCl->curlError && !$cotCl->respError) {
             if ($orderPassed) {
                 // we add reference to order_shipping_params
                 $fullOrder->order_shipping_params->EMC_params[$shipping]['reference'] = $cotCl->order['ref'];
                 $update_order = new stdClass();
                 $update_order->order_id = $fullOrder->order_id;
                 $update_order->order_shipping_params = $fullOrder->order_shipping_params;
                 $orderClass->save($update_order);
             }
             /*else {
             			echo "The shipment was not properly executed. An error has occurred .";
             		}*/
         } elseif ($cotCl->respError) {
             // The request is invalid, we add message to order history
             $update_history = new stdClass();
             $update_history->history_order_id = $fullOrder->order_id;
             $update_history->history_created = time();
             $update_history->history_notified = 0;
             $update_history->history_ip = hikashop_getIP();
             $update_history->history_reason = 'EnvoiMoinsCher Error';
             $update_history->history_data = '';
             foreach ($cotCl->respErrorsList as $m => $message) {
                 $update_history->history_data .= $message['message'] . '<br/>';
             }
             $historyClass = hikashop_get('class.history');
             $historyClass->save($update_history);
         } else {
             // An error while sending the request, add message to order history
             //
             $update_history = new stdClass();
             $update_history->history_order_id = $fullOrder->order_id;
             $update_history->history_created = time();
             $update_history->history_notified = 0;
             $update_history->history_ip = hikashop_getIP();
             $update_history->history_reason = 'EnvoiMoinsCher Error';
             $update_history->history_data = $cotCl->curlErrorText;
             $historyClass = hikashop_get('class.history');
             $historyClass->save($update_history);
         }
     }
 }
Esempio n. 6
0
function test_Env_Quotation($userData)
{
    $result = default_value();
    $start = microtime_float();
    /* Initialisation */
    $order_env = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
    $order_from = array("pays" => "FR", "code_postal" => "75002", "type" => "particulier", "ville" => "Paris", "adresse" => "41, rue Saint Augustin | floor nr 3", "civilite" => "M", "prenom" => "Test_prenom", "nom" => "Test_nom", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "");
    $order_to = array("pays" => "AU", "code_postal" => "2000", "type" => "particulier", "ville" => "Sydney", "adresse" => "King Street", "civilite" => "M", "prenom" => "Test_prenom_dst", "nom" => "Test_nom_dst", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "Some informations about my shipment");
    // Informations sur l'envoi
    $order_quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120, "operator" => "UPSE", "raison" => "sale", "colis.valeur" => 1200, "colis.description" => "Des journaux", "disponibilite.HDE" => "09:00", "disponibilite.HLE" => "19:00");
    $order_env->setPerson("expediteur", $order_from);
    $order_env->setPerson("destinataire", $order_to);
    $order_env->setType("colis", array(1 => array("poids" => 21, "longueur" => 7, "largeur" => 8, "hauteur" => 11), 2 => array("poids" => 21, "longueur" => 7, "largeur" => 8, "hauteur" => 11)));
    // Pour cet envoi on est obligé de joindre une facture proforma qui résume 2 objets expédiés
    $order_env->setProforma(array(1 => array("description_en" => "L'Equipe newspaper from 1998", "description_fr" => "le journal L'Equipe du 1998", "nombre" => 1, "valeur" => 10, "origine" => "FR", "poids" => 1.2), 2 => array("description_en" => "300 editions of L'Equipe newspaper from 1999", "description_fr" => "300 numéros de L'Equipe du 1999", "nombre" => 300, "valeur" => 8, "origine" => "FR", "poids" => 0.1)));
    $order_env->setEnv('test');
    $orderPassed = $order_env->makeOrder($order_quotInfo, true);
    $offer_env = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
    $offer_env->setEnv('test');
    $offer_to = array("pays" => "FR", "code_postal" => "75002", "ville" => "Paris", "type" => "particulier", "adresse" => "41, rue Saint Augustin");
    $offer_from = array("pays" => "FR", "code_postal" => "13002", "ville" => "Marseille", "type" => "particulier", "adresse" => "1, rue Chape");
    $offer_quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120);
    $offer_env->setPerson("expediteur", $offer_from);
    $offer_env->setPerson("destinataire", $offer_to);
    $offer_env->setType("colis", array(1 => array("poids" => 2, "longueur" => 18, "largeur" => 18, "hauteur" => 18)));
    $offer_env->getQuotation($offer_quotInfo);
    $offer_env->getOffers(false);
    /* Reception test */
    if (!$orderPassed) {
        $result['reception'] = max($result['reception'], ERROR);
        $result['reception_info'][count($result['reception_info'])] = 'Error while making the order (makeOrder returned false)';
    }
    if ($order_env->curlError) {
        $result['reception'] = max($result['reception'], ERROR);
        $result['reception_info'][count($result['reception_info'])] = 'Error while sending the query';
    } else {
        if ($order_env->respError) {
            $result['reception'] = max($result['reception'], ERROR);
            $result['reception_info'][count($result['reception_info'])] = 'Invalid query : ' . $userData["api_key"];
            foreach ($order_env->respErrorsList as $message) {
                $result['reception_info'][count($result['reception_info'])] = $message['message'];
            }
        } else {
            if ($offer_env->curlError) {
                $result['reception'] = max($result['reception'], ERROR);
                $result['reception_info'][count($result['reception_info'])] = 'Error while sending the query';
            } else {
                if ($offer_env->respError) {
                    $result['reception'] = max($result['reception'], ERROR);
                    $result['reception_info'][count($result['reception_info'])] = 'Invalid query : ' . $userData["api_key"];
                    foreach ($offer_env->respErrorsList as $message) {
                        $result['reception_info'][count($result['reception_info'])] = $message['message'];
                    }
                } else {
                    $result['reception'] = max($result['reception'], OK);
                    $result['reception_info'][count($result['reception_info'])] = 'Reception time : ' . (microtime_float() - $start) . 's';
                }
            }
        }
    }
    /* Additionals test */
    /* Test for the result structure */
    $result['additionals'][0]['name'] = 'Structure';
    $result['additionals'][0]['state'] = OK;
    if (count($offer_env->offers) == 0) {
        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$offers array is empty';
    } else {
        foreach ($offer_env->offers as $x => $offer) {
            if (!isset($offer_env->offers[$x]['mode'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"mode" not defined in $offers[' . $x . '] array';
            }
            if (!isset($offer_env->offers[$x]['url'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"url" not defined in $offers[' . $x . '] array';
            }
            if (!isset($offer_env->offers[$x]['characteristics'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"characteristics" not defined in $offers[' . $x . '] array';
            }
            if (!isset($offer_env->offers[$x]['alert'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"alert" not defined in $offers[' . $x . '] array';
            }
            if (!isset($offer_env->offers[$x]['operator'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"operator" not defined in $offers[' . $x . '] array';
            } else {
                if (count($offer_env->offers[$x]['operator']) == 0) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$offers[' . $x . ']["operator"] array is empty';
                } else {
                    if (!isset($offer_env->offers[$x]['operator']['code'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $offers[' . $x . ']["operator"] array';
                    }
                    if (!isset($offer_env->offers[$x]['operator']['label'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $offers[' . $x . ']["operator"] array';
                    }
                    if (!isset($offer_env->offers[$x]['operator']['logo'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"logo" not defined in $offers[' . $x . ']["operator"] array';
                    }
                }
            }
            if (!isset($offer_env->offers[$x]['service'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"operator" not defined in $offers[' . $x . '] array';
            } else {
                if (count($offer_env->offers[$x]['service']) == 0) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$offers[' . $x . ']["service"] array is empty';
                } else {
                    if (!isset($offer_env->offers[$x]['service']['code'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $offers[' . $x . ']["service"] array';
                    }
                    if (!isset($offer_env->offers[$x]['service']['label'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $offers[' . $x . ']["service"] array';
                    }
                }
            }
            if (!isset($offer_env->offers[$x]['price'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"price" not defined in $offers[' . $x . '] array';
            } else {
                if (count($offer_env->offers[$x]['price']) == 0) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$offers[' . $x . ']["price"] array is empty';
                } else {
                    if (!isset($offer_env->offers[$x]['price']['currency'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"currency" not defined in $offers[' . $x . ']["price"] array';
                    }
                    if (!isset($offer_env->offers[$x]['price']['tax-exclusive'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"tax-exclusive" not defined in $offers[' . $x . ']["price"] array';
                    }
                    if (!isset($offer_env->offers[$x]['price']['tax-inclusive'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"tax-inclusive" not defined in $offers[' . $x . ']["price"] array';
                    }
                }
            }
            if (!isset($offer_env->offers[$x]['collection'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"collection" not defined in $offers[' . $x . '] array';
            } else {
                if (count($offer_env->offers[$x]['collection']) == 0) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$offers[' . $x . ']["collection"] array is empty';
                } else {
                    if (!isset($offer_env->offers[$x]['collection']['type'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"type" not defined in $offers[' . $x . ']["collection"] array';
                    }
                    if (!isset($offer_env->offers[$x]['collection']['date'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"date" not defined in $offers[' . $x . ']["collection"] array';
                    }
                    if (!isset($offer_env->offers[$x]['collection']['label'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $offers[' . $x . ']["collection"] array';
                    }
                }
            }
            if (!isset($offer_env->offers[$x]['mandatory'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"mandatory" not defined in $offers[' . $x . '] array';
            } else {
                if (count($offer_env->offers[$x]['mandatory']) == 0) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$offers[' . $x . ']["mandatory"] array is empty';
                }
            }
        }
    }
    if (count($order_env->order) == 0) {
        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order array is empty';
    } else {
        if (!isset($order_env->order['ref'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"ref" not defined in $order array';
        }
        if (!isset($order_env->order['date'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"date" not defined in $order array';
        }
        if (!isset($order_env->order['mode'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"mode" not defined in $order array';
        }
        if (!isset($order_env->order['url'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"url" not defined in $order array';
        }
        if (!isset($order_env->order['proforma'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"proforma" not defined in $order array';
        }
        if (!isset($order_env->order['offer']['operator'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"offer"/"operator" not defined in $order array';
        } else {
            if (count($order_env->order['offer']['operator']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order[' . $x . ']["offer"]["operator"] array is empty';
            } else {
                if (!isset($order_env->order['offer']['operator']['code'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $order["offer"]["operator"] array';
                }
                if (!isset($order_env->order['offer']['operator']['label'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $order["offer"]["operator"] array';
                }
                if (!isset($order_env->order['offer']['operator']['logo'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"logo" not defined in $order["offer"]["operator"] array';
                }
            }
        }
        if (!isset($order_env->order['service'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"operator" not defined in $order array';
        } else {
            if (count($order_env->order['service']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["service"] array is empty';
            } else {
                if (!isset($order_env->order['service']['code'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $order["service"] array';
                }
                if (!isset($order_env->order['service']['label'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $order["service"] array';
                }
            }
        }
        if (!isset($order_env->order['price'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"price" not defined in $order array';
        } else {
            if (count($order_env->order['price']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["price"] array is empty';
            } else {
                if (!isset($order_env->order['price']['currency'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"currency" not defined in $order["price"] array';
                }
                if (!isset($order_env->order['price']['tax-exclusive'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"tax-exclusive" not defined in $order["price"] array';
                }
                if (!isset($order_env->order['price']['tax-inclusive'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"tax-inclusive" not defined in $order["price"] array';
                }
            }
        }
        if (!isset($order_env->order['collection'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"collection" not defined in $order array';
        } else {
            if (count($order_env->order['collection']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["collection"] array is empty';
            } else {
                if (!isset($order_env->order['collection']['code'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $order["collection"] array';
                }
                if (!isset($order_env->order['collection']['type_label'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"type_label" not defined in $order["collection"] array';
                }
                if (!isset($order_env->order['collection']['date'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"date" not defined in $order["collection"] array';
                }
                if (!isset($order_env->order['collection']['time'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"time" not defined in $order["collection"] array';
                }
                if (!isset($order_env->order['collection']['label'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $order["collection"] array';
                }
            }
        }
        if (!isset($order_env->order['delivery'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"delivery" not defined in $order array';
        } else {
            if (count($order_env->order['delivery']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["delivery"] array is empty';
            } else {
                if (!isset($order_env->order['delivery']['code'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $order["delivery"] array';
                }
                if (!isset($order_env->order['delivery']['type_label'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"type_label" not defined in $order["delivery"] array';
                }
                if (!isset($order_env->order['delivery']['date'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"date" not defined in $order["delivery"] array';
                }
                if (!isset($order_env->order['delivery']['time'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"time" not defined in $order["delivery"] array';
                }
                if (!isset($order_env->order['delivery']['label'])) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $order["delivery"] array';
                }
            }
        }
        if (!isset($order_env->order['alerts'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"alerts" not defined in $order array';
        } else {
            if (count($order_env->order['alerts']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["alerts"] array is empty';
            }
        }
        if (!isset($order_env->order['chars'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"chars" not defined in $order array';
        } else {
            if (count($order_env->order['chars']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["chars"] array is empty';
            }
        }
        if (!isset($order_env->order['labels'])) {
            $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
            $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"labels" not defined in $order array';
        } else {
            if (count($order_env->order['labels']) == 0) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$order["labels"] array is empty';
            }
        }
    }
    $result['duration'] = microtime_float() - $start;
    return $result;
}
Esempio n. 7
0
 function onAfterOrderUpdate(&$order, &$send_email)
 {
     $order_type = isset($order->order_type) ? $order->order_type : $order->old->order_type;
     if ($order_type != 'sale' || empty($order->order_status)) {
         return;
     }
     if (!isset($order->order_shipping_params->EMC_params)) {
         return;
     }
     if (!$this->init()) {
         return false;
     }
     $config = hikashop_config();
     $order_confirmed_status = $config->get('order_confirmed_status', 'confirmed');
     $invoice_order_statuses = explode(',', $config->get('invoice_order_statuses', 'confirmed,shipped'));
     if (empty($invoice_order_statuses)) {
         $invoice_order_statuses = array('confirmed', 'shipped');
     }
     if ($order->order_status != $order_confirmed_status && !in_array($order->order_status, $invoice_order_statuses)) {
         return;
     }
     $order_shipping_params = isset($order->order_shipping_params) ? $order->order_shipping_params : $order->old->order_shipping_params;
     if (is_string($order_shipping_params)) {
         $order_shipping_params = unserialize($order_shipping_params);
     }
     $ref_exist = false;
     foreach ($order_shipping_params->EMC_params as $value) {
         if (!empty($value['reference'])) {
             $ref_exist = true;
         }
     }
     if ($ref_exist == true) {
         return;
     }
     $db = JFactory::getDBO();
     $orderClass = hikashop_get('class.order');
     $fullOrder = $orderClass->loadFullOrder($order->order_id, true, false);
     $tab_products = array();
     foreach ($fullOrder->order_shipping_params->EMC_params as $key => $value) {
         $data = array('products' => array());
         foreach ($fullOrder->products as $k => $product) {
             if ($product->order_product_shipping_method != 'envoimoinscher') {
                 continue;
             }
             if ($key == $product->order_product_shipping_id) {
                 $ids_products = explode('@', $product->order_product_shipping_id);
                 $warehouse_id = $ids_products[1];
                 $data['products'][] = $product;
             }
         }
         if (!empty($data['products'])) {
             $data['warehouse_id'] = $warehouse_id;
             $data['shipping_id'] = $ids_products[0];
             $tab_products[] = $data;
         }
     }
     $czone_code_to = @$fullOrder->shipping_address->address_country;
     $query = 'SELECT zone_id, zone_code_2 FROM ' . hikashop_table('zone') . ' WHERE zone_name_english = ' . $db->Quote($czone_code_to);
     $db->setQuery($query);
     $czone = $db->loadObject();
     $country_to = $czone->zone_code_2;
     if ($country_to == 'FX') {
         $country_to = 'FR';
     }
     $user_address_title = $fullOrder->shipping_address->address_title;
     $key = 'HIKA_TITLE_' . strtoupper($user_address_title);
     if ($key != JText::_($key)) {
         $user_address_title = JText::_($key);
     }
     $email = @$fullOrder->customer->user_email;
     $phone = @$fullOrder->shipping_address->address_telephone;
     foreach ($tab_products as $key => $value) {
         $shipping_ids = explode('-', $value['shipping_id']);
         $this->pluginParams($shipping_ids[0]);
         if ($this->plugin_params->make_order == 0) {
             continue;
         }
         if ($this->plugin_params->destination_type == 'res' || $this->plugin_params->destination_type == 'auto' && empty($fullOrder->shipping_address->address_company)) {
             $user_type = 'particulier';
         } else {
             $user_type = 'entreprise';
         }
         if (empty($email) || empty($phone)) {
             return;
         }
         $to = array('pays' => $country_to, 'code_postal' => $fullOrder->shipping_address->address_post_code, 'type' => $user_type, 'ville' => $fullOrder->shipping_address->address_city, 'adresse' => $fullOrder->shipping_address->address_street, 'civilite' => $user_address_title, 'prenom' => $fullOrder->shipping_address->address_firstname, 'nom' => $fullOrder->shipping_address->address_lastname, 'email' => $email, 'tel' => $phone);
         $admin_address_title = $this->plugin_params->sender_civility;
         $key = 'HIKA_TITLE_' . strtoupper($admin_address_title);
         if ($key != JText::_($key)) {
             $admin_address_title = JText::_($key);
         }
         $czone_code_from = @$this->plugin_params->sender_country;
         $query = 'SELECT zone_id, zone_code_2 FROM ' . hikashop_table('zone') . ' WHERE zone_namekey = ' . $db->Quote($czone_code_from);
         $db->setQuery($query);
         $czone = $db->loadObject();
         $country_from = $czone->zone_code_2;
         if ($country_from == 'FX') {
             $country_from = 'FR';
         }
         $from = array('pays' => $country_from, 'code_postal' => $this->plugin_params->sender_postcode, 'type' => $this->plugin_params->type, 'ville' => $this->plugin_params->sender_city, 'adresse' => $this->plugin_params->sender_address, 'civilite' => $admin_address_title, 'prenom' => $this->plugin_params->sender_firstname, 'nom' => $this->plugin_params->sender_lastname, 'email' => $this->plugin_params->sender_email, 'tel' => $this->plugin_params->sender_phone);
         if ($this->plugin_params->type == 'entreprise') {
             $from['societe'] = $this->plugin_params->sender_company;
         }
         $code = (int) $this->plugin_params->product_category;
         $shipping = explode(' / ', $shipping_ids[1]);
         $service = $shipping[1];
         $shipping = $value['shipping_id'] . '@' . $value['warehouse_id'];
         foreach ($fullOrder->order_shipping_params->EMC_params as $k => $v) {
             if ($k == $shipping) {
                 $dropoff = explode('<br/>', $v['drop_off']);
                 $pickup = explode('<br/>', $v['pick_up']);
                 $ope = $v['code'];
             }
         }
         $sending_type = strtolower($this->plugin_params->sending_type);
         $collection = $dropoff[0];
         $delivery = $pickup[0];
         $quotInfo = array('collecte' => date('Y-m-d'), 'delai' => 'aucun', 'code_contenu' => $code, 'type_emballage.emballage' => 1, 'operateur' => $ope, 'raison' => 'sale', 'service' => $service, 'collection_type' => $collection, 'delivery_type' => $delivery, 'depot.pointrelais' => '', 'retrait.pointrelais' => '', $sending_type . '.description' => '');
         if ($collection == 'POST_OFFICE' || $collection == 'DROPOFF_POINT') {
             $quotInfo['depot.pointrelais'] = $dropoff[2];
         }
         if ($delivery == 'PICKUP_POINT') {
             $quotInfo['retrait.pointrelais'] = $pickup[2];
         }
         if (isset($this->plugin_params->start_availability) && !empty($this->plugin_params->start_availability)) {
             $quotInfo['disponibilite.HDE'] = $this->plugin_params->start_availability;
         }
         if (isset($this->plugin_params->end_availability) && !empty($this->plugin_params->end_availability)) {
             $quotInfo['disponibilite.HLE'] = $this->plugin_params->end_availability;
         }
         foreach ($value['products'] as $product) {
             $quotInfo[$sending_type . '.description'] .= '  ' . $product->order_product_name;
         }
         $productClass = hikashop_get('class.product');
         $newOrder = new stdClass();
         $i = 0;
         foreach ($value['products'] as $p) {
             $product = $productClass->get($p->product_id);
             if ($product->product_parent_id != 0) {
                 $parent = $productClass->get($product->product_parent_id);
                 $newOrder->products[$i] = $parent;
                 $newOrder->products[$i]->variants[0] = $product;
                 if ($product->product_width == 0 && $product->product_length == 0) {
                     $product->product_width = $parent->product_width;
                     $product->product_length = $parent->product_length;
                     $product->product_height = $parent->product_height;
                 }
                 $product->cart_product_quantity = $p->order_product_quantity;
                 $product->product_weight_orig = $parent->product_weight;
                 $product->product_weight_unit_orig = $parent->product_weight_unit;
                 $product->product_dimension_unit_orig = $parent->product_dimension_unit;
                 $product->prices[0] = new stdClass();
                 $product->prices[0]->unit_price = new stdClass();
                 $product->prices[0]->unit_price->price_value_with_tax = $p->order_product_price + $p->order_product_tax;
             } else {
                 $newOrder->products[$i] = $product;
                 $newOrder->products[$i]->cart_product_quantity = $p->order_product_quantity;
                 $newOrder->products[$i]->product_weight_orig = $newOrder->products[$i]->product_weight;
                 $newOrder->products[$i]->product_weight_unit_orig = $newOrder->products[$i]->product_weight_unit;
                 $newOrder->products[$i]->product_dimension_unit_orig = $newOrder->products[$i]->product_dimension_unit;
                 $newOrder->products[$i]->prices[0] = new stdClass();
                 $newOrder->products[$i]->prices[0]->unit_price = new stdClass();
                 $newOrder->products[$i]->prices[0]->unit_price->price_value_with_tax = $p->order_product_price + $p->order_product_tax;
             }
             $i++;
         }
         $data = $this->getData(null, $this, $newOrder, $sending_type, true);
         $total_price = (int) $data[0]["price"];
         unset($data[0]);
         $quotInfo[$sending_type . '.valeur'] = $total_price;
         $cotCl = new Env_Quotation(array('user' => $this->plugin_params->emc_login, 'pass' => $this->plugin_params->emc_password, 'key' => $this->plugin_params->api_key));
         $cotCl->setEnv($this->plugin_params->environment);
         $config = hikashop_config();
         $contentCl->setPlatformParams('hikashop', $config->get('version'), $config->get('version'));
         $cotCl->setPerson('expediteur', $from);
         $cotCl->setPerson('destinataire', $to);
         $cotCl->setType($sending_type, $data);
         if ($country_to != $country_from) {
             $infos_products = array();
             $i = 1;
             foreach ($newOrder->products as $product) {
                 $infos_products[$i] = array();
                 if (isset($product->variants)) {
                     $nb = $product->variants[0]->cart_product_quantity;
                     $price = $product->variants[0]->prices[0]->unit_price->price_value_with_tax;
                     $weight = $product->variants[0]->product_weight_orig;
                 } else {
                     $nb = $product->cart_product_quantity;
                     $price = $product->prices[0]->unit_price->price_value_with_tax;
                     $weight = $product->product_weight_orig;
                 }
                 $infos_products[$i]["description_en"] = $product->product_name;
                 $infos_products[$i]["description_fr"] = $product->product_name;
                 $infos_products[$i]["nombre"] = $nb;
                 $infos_products[$i]["valeur"] = $price;
                 $infos_products[$i]["origine"] = $country_from;
                 $infos_products[$i]["poids"] = $weight;
                 $i++;
             }
             $cotCl->setProforma($infos_products);
         }
         $orderPassed = $cotCl->makeOrder($quotInfo, true);
         if (!$cotCl->curlError && !$cotCl->respError) {
             if ($orderPassed) {
                 $fullOrder->order_shipping_params->EMC_params[$shipping]['reference'] = $cotCl->order['ref'];
                 $update_order = new stdClass();
                 $update_order->order_id = $fullOrder->order_id;
                 $update_order->order_shipping_params = $fullOrder->order_shipping_params;
                 $orderClass->save($update_order);
             }
         } elseif ($cotCl->respError) {
             $update_history = new stdClass();
             $update_history->history_order_id = $fullOrder->order_id;
             $update_history->history_created = time();
             $update_history->history_notified = 0;
             $update_history->history_ip = hikashop_getIP();
             $update_history->history_reason = 'EnvoiMoinsCher Error';
             $update_history->history_data = '';
             foreach ($cotCl->respErrorsList as $m => $message) {
                 $update_history->history_data .= $message['message'] . '<br/>';
             }
             $historyClass = hikashop_get('class.history');
             $historyClass->save($update_history);
         } else {
             $update_history = new stdClass();
             $update_history->history_order_id = $fullOrder->order_id;
             $update_history->history_created = time();
             $update_history->history_notified = 0;
             $update_history->history_ip = hikashop_getIP();
             $update_history->history_reason = 'EnvoiMoinsCher Error';
             $update_history->history_data = $cotCl->curlErrorText;
             $historyClass = hikashop_get('class.history');
             $historyClass->save($update_history);
         }
     }
 }
/*  Cet exemple vous permet de passer une commande. L'envoi est composé d'informations basiques (expéditeur, destinataire, type) 
 *  et ne contient pas d'options supplémentaires. Il possède uniquement un filtre selon lequel le montant de la commande ne peut 
 *  pas dépasser 50€ ttc.
 */
ob_start();
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once '../utils/header.php';
require_once '../utils/autoload.php';
$orderDouStyle = 'style="font-weight:bold;"';
// Informations sur l'expéditeur et le destinataire
$from = array("pays" => "FR", "code_postal" => "75002", "type" => "particulier", "ville" => "Paris", "adresse" => "41, rue Saint-Augustin | 3e étage", "civilite" => "M", "prenom" => "Développeur", "nom" => "Boxtale", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "Frapper 3 fois");
$to = array("pays" => "FR", "code_postal" => "13005", "type" => "particulier", "ville" => "Marseille", "adresse" => "1, rue Saint-Thome", "civilite" => "Mme", "prenom" => "Autre prénom", "nom" => "Nom du destinataire", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "");
// Informations sur la cotation
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120, "operateur" => "UPSE", "service" => "Standard", "prix_max_ttc" => 50, "description" => "Le Monde, années 1990-1992", "disponibilite.HDE" => "12:00", "disponibilite.HLE" => "19:00", "assurance.selection" => "off");
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
$cotCl->setType("colis", array(1 => array("poids" => 4, "longueur" => 7, "largeur" => 8, "hauteur" => 11)));
$orderPassed = $cotCl->makeOrder($quotInfo, true);
if (!$cotCl->curlError && !$cotCl->respError) {
    if ($orderPassed) {
        echo "L'envoi a été correctement réalisé sous référence " . $cotCl->order['ref'];
        $cotCl->unsetParams(array("disponibilite.HLE", "disponibilite.HDE", "service", "assurance.selection", "valeur", "prix_max_ttc"));
        $cotCl->makeDoubleOrder(array("operateur" => "CHRP", "depot.pointrelais" => ""));
        if (!$cotCl->curlError && !$cotCl->respError) {
            echo "<br />Le deuxième envoi a été correctement réalisé sous référence " . $cotCl->order['ref'];
        }
    } else {
        echo "<br />Le deuxième envoi n'a pas été correctement réalisé. Une erreur s'est produite.";
    }
<?php

/*  Cet exemple illustre une simple cotation pour une expédition France - Australie
 */
ob_start();
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once '../utils/header.php';
require_once '../utils/autoload.php';
$quotationPSStyle = 'style="font-weight:bold;"';
// Expéditeur et destinataire
$from = array("pays" => "FR", "code_postal" => "75002", "type" => "particulier", "ville" => "Paris");
$to = array("pays" => "AU", "code_postal" => "2000", "type" => "particulier", "ville" => "Sydney");
// Informations sur l'envoi
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120, "colis.valeur" => 1200, "colis.description" => "Des journaux");
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
$cotCl->setType("colis", array(1 => array("poids" => 4, "longueur" => 7, "largeur" => 8, "hauteur" => 11)));
$orderPassed = $cotCl->getQuotation($quotInfo);
// Si pas d'erreur CURL
if (!$cotCl->curlError) {
    print_r($pointCl->respErrorsList);
    // Si pas d'erreurs de la requête, on affiche le tableau
    if (!$cotCl->respError) {
        $cotCl->getOffers(false);
        ?>
<style type="text/css">
table tr td {border:1px solid #000000; padding:5px; }
</style>
<table>
<?php

/*  Cet exemple illustre une simple passation de commande France - Australie
 */
ob_start();
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require_once '../utils/header.php';
require_once '../utils/autoload.php';
$orderPSStyle = 'style="font-weight:bold;"';
// Expéditeur et destinataire
$from = array("pays" => "FR", "code_postal" => "75002", "type" => "particulier", "ville" => "Paris", "adresse" => "41, rue Saint Augustin | floor nr 3", "civilite" => "M", "prenom" => "Test_prenom", "nom" => "Test_nom", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "");
$to = array("pays" => "AU", "code_postal" => "2000", "type" => "particulier", "ville" => "Sydney", "adresse" => "King Street", "civilite" => "M", "prenom" => "Test_prenom_dst", "nom" => "Test_nom_dst", "email" => "*****@*****.**", "tel" => "0601010101", "infos" => "Some informations about my shipment");
// Informations sur l'envoi
$quotInfo = array("collecte" => date("Y-m-d"), "delai" => "aucun", "code_contenu" => 10120, "operator" => "UPSE", "raison" => "sale", "colis.valeur" => 1200, "colis.description" => "Des journaux", "disponibilite.HDE" => "09:00", "disponibilite.HLE" => "19:00");
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
$cotCl->setPerson("expediteur", $from);
$cotCl->setPerson("destinataire", $to);
$cotCl->setType("colis", array(1 => array("poids" => 21, "longueur" => 7, "largeur" => 8, "hauteur" => 11), 2 => array("poids" => 21, "longueur" => 7, "largeur" => 8, "hauteur" => 11)));
// Pour cet envoi on est obligé de joindre une facture proforma qui résume 2 objets expédiés
$cotCl->setProforma(array(1 => array("description_en" => "L'Equipe newspaper from 1998", "description_fr" => "le journal L'Equipe du 1998", "nombre" => 1, "valeur" => 10, "origine" => "FR", "poids" => 1.2), 2 => array("description_en" => "300 editions of L'Equipe newspaper from 1999", "description_fr" => "300 numéros de L'Equipe du 1999", "nombre" => 300, "valeur" => 8, "origine" => "FR", "poids" => 0.1)));
$orderPassed = $cotCl->makeOrder($quotInfo);
if (!$cotCl->curlError && !$cotCl->respError) {
    if ($orderPassed) {
        echo "L'envoi a été correctement réalisé sous référence " . $cotCl->order['ref'];
    } else {
        echo "L'envoi n'a pas été correctement réalisé. Une erreur s'est produite.";
    }
} elseif ($cotCl->respError) {
    echo "La requête n'est pas valide : ";
    foreach ($cotCl->respErrorsList as $m => $message) {
Esempio n. 11
0
$quotationPSStyle = 'style="font-weight:bold;"';
foreach ($_GET as $k => $get) {
    $_GET[$k] = mb_convert_encoding(urldecode($_GET[$k]), "UTF-8");
}
// création du destinataire et de l'expéditeur - classe séparée car dans l'avenir on voudra
// peut-être gérer les carnets d'adresses ou gestion de compte à distance (via une smartphone par exemple)
$to = array("pays" => "FR", "code_postal" => "75002", "ville" => "Paris", "type" => "particulier", "adresse" => "41, rue Saint Augustin");
$from = array("pays" => "FR", "code_postal" => "13002", "ville" => "Marseille", "type" => "particulier", "adresse" => "1, rue Chape");
// On créé la cotation
$date = new DateTime();
$date->add(new DateInterval('P10D'));
$quotInfo = array("collecte" => $date->format('Y-m-d'), "delay" => "aucun", "content_code" => 50113);
if ($_GET["ope"] != "" && $_GET["ope"] != "all") {
    $quotInfo["operator"] = $_GET["ope"];
}
$cotCl = new Env_Quotation(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
// Initialisation de l'expéditeur et du destinataire
$cotCl->setPerson("shipper", $from);
$cotCl->setPerson("recipient", $to);
// Précision de l'environnement de travail
$cotCl->setEnv('test');
// Initialisation du type d'envoi
$cotCl->setType("colis", array(1 => array("poids" => 1, "longueur" => 18, "largeur" => 18, "hauteur" => 18)));
$cotCl->getQuotation($quotInfo);
if ($cotCl->curlError) {
    echo "<b>Une erreur pendant l'envoi de la requête </b> : " . $cotCl->curlErrorText;
    die;
} elseif ($cotCl->respError) {
    echo "La requête n'est pas valide : ";
    foreach ($cotCl->respErrorsList as $m => $message) {
        echo "<br /><b>" . $message['message'] . "</b>";