Example #1
0
include_once dirname(__FILE__) . '/errorCode.php';
try {
    if (!Tools::getValue('token')) {
        die('{"error":"Security error"}');
    }
    if (sha1('mr' . _COOKIE_KEY_ . 'Back') != Tools::getValue('token')) {
        die('{"error":"Security error"}');
    }
    $webservice = MondialRelay::MR_URL . 'webservice/Web_Services.asmx?WSDL';
    $client = new SoapClient($webservice);
    $params = array();
    $params['Enseigne'] = Tools::getValue('enseigne');
    $params['Poids'] = '';
    $params['Taille'] = '';
    $params['CP'] = Configuration::get('PS_SHOP_CODE') ? Configuration::get('PS_SHOP_CODE') : '75000';
    $params['Ville'] = '';
    $id_country = Configuration::get('PS_SHOP_COUNTRY_ID') ? Configuration::get('PS_SHOP_COUNTRY_ID') : Configuration::get('PS_COUNTRY_DEFAULT');
    $params['Pays'] = Country::getIsoById($id_country);
    $params['Action'] = '';
    $concat = $params['Enseigne'] . $params['Pays'] . $params['Ville'] . $params['CP'] . $params['Poids'] . Tools::getValue('key');
    $params['Security'] = Tools::strtoupper(md5($concat));
    $result_mr = $client->WSI2_RecherchePointRelais($params);
    if (($errorNumber = $result_mr->WSI2_RecherchePointRelaisResult->STAT) != 0) {
        echo '{"error":"' . str_replace('"', '', $statCode[$errorNumber]) . '"}';
        die;
    }
    echo '{"success":1}';
} catch (Exception $e) {
    echo '{"error":"' . str_replace('"', '', $statCode[99]) . '"}';
    die;
}
 public function send()
 {
     if ($client = new SoapClient($this->_webserviceURL)) {
         $client->soap_defencoding = 'UTF-8';
         $client->decode_utf8 = false;
         $params = $this->_getSimpleParamArray($this->_fields['list']);
         $result = $client->WSI2_RecherchePointRelais($params);
         $this->_parseResult($client, $result, $params);
         unset($client);
     } else {
         throw new Exception($this->_mondialRelay->l('The Mondial Relay webservice isn\'t currently reliable'));
     }
 }
 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 {
     try {
         $result = Mage::getModel('shipping/rate_result');
         if (!$this->getConfigData('active')) {
             return $result;
         }
         $shipping_free_cart_price = null;
         if ($this->getConfigData('free_active')) {
             $shipping_free_cart_price = $this->getConfigData('free_price');
         }
         $request->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name);
         if ($this->getConfigData('package_weight')) {
             $request->_data['package_weight'] = $request->_data['package_weight'] + $this->getConfigData('package_weight') / 1000;
         }
         $quote = Mage::getModel('sales/quote');
         if (isset($data['cart'])) {
             foreach ($data['cart'] as $id => $itemqty) {
                 $item = Mage::getModel('sales/quote_item')->load($id);
                 if (!$quote->getId()) {
                     $quote->load($item->getQuoteId());
                 }
                 $item->setQuote($quote);
                 $product = $item->getProduct();
                 if ($product->getTypeId() != 'configurable') {
                     $process['products'][] = array("product" => $product, "qtycart" => $itemqty);
                 }
             }
         } else {
             $cart = Mage::getModel('checkout/cart')->getQuote();
             foreach ($cart->getAllItems() as $item) {
                 $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
                 if ($product->getTypeId() != 'configurable') {
                     $process['products'][] = array("product" => $product, "qtycart" => $item->getQty());
                 }
             }
         }
         if (isset($process['products'])) {
             foreach ($process['products'] as $product) {
                 $rates = $this->getRate($request, $product['product'], $product['qtycart']);
                 //$productShippingPrice = $rate['price'];
                 //$productn = $product['product'];
                 /*if ($productShippingPrice > $maxProductShippingPrice) {
                 			$maxProductShippingPrice = $productShippingPrice;
                 			if ($product['qty']>1){
                 				$maxProductShippingPrice *= $coeff;
                 			}
                 		}*/
             }
         }
         $cartTmp = $request->_data['package_value_with_discount'];
         $weghtTmp = $request->_data['package_weight'];
         foreach ($rates as $rate) {
             if (!empty($rate) && $rate['price'] >= 0) {
                 /*---------------------------------------- Liste des points relais -----------------------------------------*/
                 // On met en place les paramètres de la requète
                 $params = array('Enseigne' => $this->getConfigData('enseigne'), 'Pays' => $request->_data['dest_country_id'], 'CP' => $request->_data['dest_postcode']);
                 //On crée le code de sécurité
                 $code = implode("", $params);
                 $code .= $this->getConfigData('cle');
                 //On le rajoute aux paramètres
                 $params["Security"] = strtoupper(md5($code));
                 // On se connecte
                 $client = new SoapClient("http://www.mondialrelay.fr/WebService/Web_Services.asmx?WSDL");
                 // Et on effectue la requète
                 $points_relais = $client->WSI2_RecherchePointRelais($params)->WSI2_RecherchePointRelaisResult;
                 $i = 0;
                 // On cr�e une m�thode de livraison par point relais
                 foreach ($points_relais as $point_relais) {
                     if (is_object($point_relais) && trim($point_relais->Num) != '') {
                         $i++;
                         $method = Mage::getModel('shipping/rate_result_method');
                         $method->setCarrier('pointsrelais');
                         $method->setCarrierTitle($this->getConfigData('title'));
                         $methodTitle = $point_relais->LgAdr1 . ' - ' . $point_relais->Ville . ' <a href="#" onclick="PointsRelais.showInfo(\'' . $point_relais->Num . '\'); return false;">Détails</a> - <span style="display:none;" id="pays">' . $request->_data['dest_country_id'] . '</span>';
                         $method->setMethod($point_relais->Num);
                         $method->setMethodTitle($methodTitle);
                         if ($shipping_free_cart_price != null && ($cartTmp > $shipping_free_cart_price && $weghtTmp > 0.101)) {
                             $price = $rate['price'] = 0;
                             $rate['cost'] = 0;
                             $method->setPrice($price);
                             $method->setCost($rate['cost']);
                         } else {
                             $price = $rate['price'];
                             $method->setPrice($this->getFinalPriceWithHandlingFee($price));
                             $method->setCost($rate['cost']);
                         }
                         $result->append($method);
                     }
                 }
                 if (!$i) {
                     $method = Mage::getModel('shipping/rate_result_method');
                     $method->setCarrier('pointsrelais');
                     $method->setCarrierTitle('');
                     $method->setMethod('000');
                     $method->setMethodTitle("Livraison");
                     $method->setPrice(0);
                     $method->setCost(0);
                     $result->append($method);
                 }
             }
         }
         //echo "<pre>" .  var_dump($result) .'</pre>';
         return $result;
     } catch (exception $e) {
         return 0;
     }
 }