/**
  * Function to get quotation for the order
  */
 function _EMCrequestMethods(&$data, &$null, &$rate, &$order, $sending_type, $from, $to)
 {
     if (!$this->init()) {
         return false;
     }
     $app = JFactory::getApplication();
     $total_price = (int) $data[0]['price'];
     unset($data[0]);
     // get selected carriers in config
     $listMethods = array();
     foreach ($rate->shipping_params->methods as $key => $nom) {
         $listMethods[] = $nom;
     }
     $code = $rate->shipping_params->product_category;
     // Informations on sending
     $quotInfo = array('collecte' => date('Y-m-d'), 'delai' => 'aucun', 'code_contenu' => (int) $code, $sending_type . '.valeur' => $total_price);
     $cotCl = new Env_Quotation(array('user' => $rate->shipping_params->emc_login, 'pass' => $rate->shipping_params->emc_password, 'key' => $rate->shipping_params->api_key));
     $config = hikashop_config();
     $cotCl->setPlatformParams('hikashop', $config->get('version'), $config->get('version'));
     // environment 'prod' or 'test'
     $cotCl->setEnv($rate->shipping_params->environment);
     $cotCl->setPerson('expediteur', $from);
     $cotCl->setPerson('destinataire', $to);
     $cotCl->setType($sending_type, $data);
     // Send request to get offers
     $cotCl->getQuotation($quotInfo);
     if ($cotCl->curlError) {
         $app->enqueueMessage(JText::sprintf('Error while sending the request: %s', $cotCl->curlErrorText), 'error');
         return false;
     }
     if (!$cotCl->respError) {
         $cotCl->getOffers(false);
         if (empty($cotCl->offers)) {
             return false;
         }
         //we get all the important informations for each offers returned by envoimoinscher
         foreach ($listMethods as $liste) {
             foreach ($cotCl->offers as $o => $offre) {
                 $code = $offre['operator']['code'];
                 //we take into account only the services selected in the configuration
                 if (strpos($code, $liste) === false) {
                     continue;
                 }
                 $this->result[] = array('Transporteur' => $offre['operator']['label'], 'Service' => $offre['service']['code'], 'Code' => $offre['operator']['code'], 'Prix' => $offre['price']['tax-inclusive'], 'Collecte' => array('Type' => $offre['collection']['type'], 'Label' => $offre['collection']['label']), 'Livraison' => array('Type' => $offre['delivery']['type'], 'Label' => $offre['delivery']['label']), 'Détails' => $offre['characteristics'][1]);
             }
         }
     } else {
         $app->enqueueMessage(JText::_('The request is invalid :'), 'error');
         foreach ($cotCl->respErrorsList as $m => $message) {
             $app->enqueueMessage($message['message'], 'error');
         }
     }
     $order_clone = new stdClass();
     $variables = array('products', 'cart_id', 'coupon', 'shipping_address', 'volume', 'weight', 'volume_unit', 'weight_unit');
     foreach ($variables as $var) {
         if (isset($order->{$var})) {
             $order_clone->{$var} = $order->{$var};
         }
     }
     $temp_rate = array();
     $temp_rate[$rate->shipping_id] = $rate;
     unset($temp_rate[$rate->shipping_id]->shipping_params->methods);
     // we generate a key for the order
     $shipping_key = sha1(serialize($order_clone) . serialize($temp_rate));
     // We need the warehouse id to set it in the results
     $warehouse_id = -1;
     if (isset($order->shipping_warehouse_id)) {
         $warehouse_id = (int) $order->shipping_warehouse_id;
     } else {
         $groups_ids = array_keys($order->shipping_groups);
         $warehouse_id = $groups_ids[0];
     }
     $shipping_id = $rate->shipping_id;
     $result = $app->getUserState(HIKASHOP_COMPONENT . '.shipping.envoimoinscher_result');
     $result[$warehouse_id][$shipping_id] = $this->result;
     $result['shipping_key'] = $shipping_key;
     // Set the results in session
     $app->setUserState(HIKASHOP_COMPONENT . '.shipping.envoimoinscher_result', $result);
 }