Beispiel #1
0
 public static function GetShippingPrice($zip_from, $zip_to, $weight, $length, $height, $width, $diameter = 0, $onHands = false, $notify = false, $recoverValue = 0)
 {
     $data = array('sCepOrigem' => $zip_from, 'sCepDestino' => $zip_to, 'nVlPeso' => intval($weight), 'nCdFormato' => 1, 'nVlComprimento' => $length, 'nVlAltura' => $height, 'nVlLargura' => $width, 'nVlDiametro' => $diameter, 'sCdMaoPropria' => $onHands ? 's' : 'n', 'nVlValorDeclarado' => intval($recoverValue), 'sCdAvisoRecebimento' => $notify ? 's' : 'n', 'nCdServico' => '40010, 41106', 'StrRetorno' => 'xml');
     #debug(self::CORREIOS_SHIPPING_URL . '?' . http_build_query($data));
     self::$request = new HttpHandler(self::CORREIOS_SHIPPING_URL);
     self::$request->setParams($data);
     self::$request->execute();
     $response = json_decode(json_encode(simplexml_load_string(self::$request->getContent())), true);
     return $response;
 }
 public function shippingPrice()
 {
     if (intval($this->getQueryString('id')) == 0) {
         $this->commitReplace('', '#shippingoptions');
         $this->commitReplace('(escolha um endereço para entrega)', '#totalprice');
         $this->commitReplace('(escolha um endereço para entrega)', '#shippingprice');
         return;
     }
     $orbit = new Orbit();
     $result = $orbit->get('client/address/' . $this->getQueryString('id'));
     $address = $result['address'];
     $zip_to = $address['zip_code'];
     $source = $orbit->get('stations');
     $station = current($source['station']);
     $zip_from = $station['zip_code'];
     #$cartItems = $orbit->get('client/cartitems', 1, 100, array('id' => UID::get('id')));
     $order_id = $this->getQueryString('order_id');
     $cartItems = $this->getCartItems($order_id);
     $cart = $cartItems['cart'];
     $weigth = 0;
     $width = 0;
     $height = 0;
     $diameter = 0;
     $length = 0;
     foreach ($cart as $item) {
         $width += $item['width'];
         $height += $item['height'];
         $diameter += $item['diameter'];
         $length += $item['length'];
         $weigth += $item['weight'];
     }
     $height > 20 || ($height = 20);
     $width > 20 || ($width = 20);
     $length > 20 || ($length = 20);
     $diameter || ($diameter = 0);
     $shipping = Correios::GetShippingPrice($zip_from, $zip_to, 1, $length, $height, $width, $diameter);
     $shipping_options = $shipping['cServico'];
     UID::set('shipping_options', $shipping_options);
     $this->view()->loadTemplate('shippingoptions');
     $this->view()->setVariable('shipping_options', $shipping_options);
     $this->view()->setVariable('order_id', $order_id);
     $this->commitReplace($this->view()->render(), '#shippingoptions');
 }
<!DOCTYPE html>
<html>
<head>
	<title>Correios</title>
</head>
<body>
<?php 
ini_set('display_errors', true);
error_reporting(E_ALL);
$cep = $_GET['cep'];
print_r($cep);
include 'correios.class.php';
if (isset($_GET['cep'])) {
    die(json_encode(Correios::cep($_GET['cep'])));
} elseif (isset($_GET['codigo_rastreio'])) {
    die(json_encode(Correios::rastreio($_GET['codigo_rastreio'])));
} else {
    die('informe parametro GET cep ou codigo_rastreio');
}
?>
</body>
</html>
 /**
  * Cria um objeto de comunicação com os Correios.
  * 
  * @param string $usuario Usuário.
  * @param string $senha Senha.
  * @param string $tipoCalculo Tipo de cálculo.
  */
 public function __construct($usuario = '', $senha = '', $tipoCalculo = Correios::TIPO_CALCULO_PRECO_TODOS)
 {
     parent::__construct($usuario, $senha);
     $this->setTipoCalculo($tipoCalculo);
 }
Beispiel #5
0
 /**
  * @param $id of the type
  * @return object or false
  */
 public static function getByID($id)
 {
     $types = Correios::get_types();
     foreach ($types as $t) {
         if ($t->id == $id) {
             return $t;
         }
     }
     return false;
 }