Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('includes/application_top.php');
- error_reporting(0);
- function calcula_frete_correios($cep_origem, $cep_destino, $peso, $valordeclarado, $servico, $trys) {
- $chances = 1;
- $conexao = fsockopen("www.correios.com.br", 80, $errno, $errstr, 2);
- if (!$conexao) {
- if ($trys < $chances) {
- calcula_frete_correios($ceporigem, $cepdestino, $peso, $valordeclarado, $servico, ++$trys);
- } else
- return 0;
- } else {
- $saida = "GET /encomendas/precos/calculo.cfm?servico=$servico&CepOrigem=$cep_origem&CepDestino=$
- cep_destino&Peso=$peso&ValorDeclarado=$valordeclarado HTTP/1.1\r\n";
- $saida .= "Host: www.correios.com.br\r\n";
- $saida .= "Connection: Close\r\n\r\n";
- fwrite($conexao, $saida);
- stream_set_timeout($conexao, 10000);
- $resposta = "";
- while (!feof($conexao))
- $resposta .= fgets($conexao, 128);
- fclose($conexao);
- ereg ("&Tarifa=([0-9]+\.[0-9]+)", $resposta, $reg);
- if (!$reg[1])
- ereg ("&Tarifa=([0-9]+)", $resposta, $reg);
- $resultado = $reg[1];
- if ($resultado == 0 && $trys < $chances) {
- calcula_frete_correios($ceporigem, $cepdestino, $peso, $valordeclarado, $servico, ++$trys);
- } else
- return $resultado;
- }
- // } catch(Exception $e) { // PHP5
- // return 0;
- // }
- }
- // $idml = $_GET["idml"];
- // $idproduto = mysql_query("select * from products where products_ml = '".$idml."'");
- // $idx = mysql_fetch_array($idproduto);
- // $products_idml = $idx['products_id'];// Isto traz o ID do produto
- $products_idml = $_GET["idml"];// Isto traz o ID do produto
- $pesop=tep_db_query("SELECT products_weight FROM `products` WHERE `products_id` = '".$products_idml."'");
- $pesop = tep_db_fetch_array($pesop);
- $pesop = $pesop["products_weight"];
- $pesoa = str_replace(".", ",", $pesop);
- $cep_origem=tep_db_query("SELECT configuration_value FROM `configuration` WHERE `configuration_key` = 'SHIPPING_ORIGIN_ZIP'");
- $cep = tep_db_fetch_array($cep_origem);
- $cep_origem = $cep["configuration_value"];
- $preco = tep_db_query("SELECT products_price FROM `products` WHERE `products_id` = '".$products_idml."'");
- $preco = tep_db_fetch_array($preco);
- $preco = $preco["products_price"];
- $nomeprodutoml = mysql_query("select * from products_description where products_id = '".$products_idml."'");
- $nomeprodutoml = mysql_fetch_array($nomeprodutoml);
- $nomeprodutoml = $nomeprodutoml['products_name'];//Istro traz o nome do Produto
- $imagemproduto = mysql_query("select * from products where products_id = '".$products_idml."'");
- $imagemproduto = mysql_fetch_array($imagemproduto);
- $imagemproduto = $imagemproduto['products_image'];//Istro traz o nome do Produto
- $ceporigem = $_GET["ceporigem"];
- $cep1 = $_GET["cepdestino1"];
- $cep2 = $_GET["cepdestino2"];
- $cepdestino = $cep1.$cep2;
- $cepdestino = str_replace("-", "", $cepdestino);
- $cepdestino = str_replace(".", "", $cepdestino);
- $mult = $_GET["multiplicador"];
- $peso = $_GET["peso"];
- $peso = bcmul($peso, $mult, 2);
- $pesototal = $peso;
- $valordeclarado = $_GET["valordeclarado"];
- $servico = $_GET["servico"];
- $valorfrete = calcula_frete_correios($ceporigem, $cepdestino, $peso, $valordeclarado, $servico, 1);
- $valorfrete = str_replace(".", ",", $valorfrete);
- $sedex = $servico;
- if ($sedex == '40010') {
- $sedex = 'SEDEX'; }
- if ($sedex == '40045') {
- $sedex = 'SEDEX A COBRAR'; }
- if ($sedex == '41106') {
- $sedex = 'PAC'; }
- if ($sedex == '41017') {
- $sedex = 'ENCOMENDA NORMAL'; }
- if ($multiplicador == '1') {
- $unidplural = 'unidade'; } else {
- $unidplural = 'unidades'; }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html><head><title>Calculo de Frete Mercado Livre</title>
- <link rel="stylesheet" type="text/css" href="frete_stylesheet.css">
- <script>
- function verifica_cep(theform) {
- if (isNaN(frete.cep1.value)) {
- alert( 'O campo CEP deve ser numérico');
- frete.cep1.focus();
- return( false );
- }
- if (isNaN(frete.cep2.value)) {
- alert( 'O campo CEP deve ser numérico');
- frete.cep2.focus();
- return( false );
- }
- if (frete.cep1.value == '') {
- alert( 'Você deve informar seu CEP.');
- frete.cep1.focus();
- return( false );
- }
- if (frete.cep2.value == '') {
- alert( 'Você deve informar seu CEP.');
- frete.cep2.focus();
- return( false );
- }
- if (frete.cep1.value.length != 5){
- alert( 'O campo de CEP deve ter 8 digitos.');
- frete.cep1.focus();
- return( false );
- }
- if (frete.cep2.value.length != 3){
- alert( 'O campo de CEP deve ter 8 digitos.');
- frete.cep2.focus();
- return( false );
- }
- document.form.submit();
- return(true);
- }
- //self.window.toolbar.visible=false;
- //self.window.locationbar.visible false;
- window.resizeTo(screen.width, screen.height - 30);
- window.moveTo( 0 ,0 );
- </script>
- <style type="text/css">
- <!--
- .style1 {
- font-family: Arial, Helvetica, sans-serif;
- font-size: x-small;
- }
- .style2 {
- font-family: Arial, Helvetica, sans-serif;
- font-size: small;
- }
- .style3 {
- font-size: x-large;
- font-family: Arial, Helvetica, sans-serif;
- font-weight: bold;
- color: #0000FF;
- }
- .style4 {
- font-family: Arial, Helvetica, sans-serif;
- font-size: xx-small;
- }
- .style5 {font-size: x-small}
- .style6 {font-family: Arial, Helvetica, sans-serif}
- -->
- </style>
- </head><body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0">
- <? if ($valorfrete == '0') { ?>
- <!-- body //-->
- <table align="center" border="0" cellpadding="0" cellspacing="0" width="752">
- <tbody>
- <tr>
- <td width="225">
- <p align="center"><img src="images/<? echo STORE_LOGO; ?>"></p>
- </td>
- <td width="523">
- <p align="center"><b><font face="Verdana" size="5">Cálculo de Frete</font></b></p></td>
- </tr>
- <tr>
- <td colspan="2" width="750"> </td>
- </tr>
- </tbody>
- </table>
- <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
- <tbody>
- <tr>
- <td><table border="0" cellpadding="0" cellspacing="0" width="750">
- <tbody>
- <tr>
- <td> <form action="" method="get">
- <input type="hidden" name="ceporigem" id="ceporigem" value="<? echo $cep_origem; ?>" />
- <input type="hidden" name="peso" id="peso" value="<? echo $pesop; ?>" />
- <input type="hidden" name="maoPropria" id="maoPropria" value="N" />
- <input type="hidden" name="valordeclarado" id="valordeclarado" value="<? echo $preco; ?>"/>
- <input type="hidden" name="avisarRecebimento" id="avisarRecebimento" value="N" />
- <input type="hidden" name="idml" id="idml" value="<? echo $idml; ?>" />
- <tbody>
- <tr>
- <td align="right" valign="top" width="28%"> </td>
- <td valign="top" width="2%"> </td>
- <td valign="top" width="70%"><font color="#000000" face="Arial" size="2">Prezado cliente, nesta
- página você poderá fazer o cálculo de frete para o
- envio do produto abaixo. Informe o seu CEP,
- a quantidade desejada, escolha o tipo de serviço e depois clique no botão </font><b><font color="#4a766e" face="Arial" size="2">Calcular Frete.</font></b></td>
- </tr>
- <tr height="30">
- <td align="right" height="15"> </td>
- <td height="15"> </td>
- <td height="15"> </td>
- </tr>
- <tr height="30">
- <td align="right" height="10" valign="top"><div align="center"><img src="images/<? echo $imagemproduto; ?>" name="imgp1" border="0" width="150"> </div></td>
- <td height="10" valign="top"> </td>
- <td height="10" valign="top"><table border="0" cellpadding="5" cellspacing="0" width="479">
- <tbody>
- <tr bgcolor="#efefef">
- <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Produto:</b></font></td>
- <td style="border-top: 1px solid silver;" width="343"><b><font color="#000080" face="Arial" size="2"><? echo $nomeprodutoml; ?></font></b></td>
- </tr>
- <tr bgcolor="#f5f5f5">
- <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>CEP de Origem:</b></font></td>
- <td style="border-top: 1px solid silver;" width="343"><b><font color="#000080" face="Arial" size="2"><? echo $cep_origem; ?></font></b></td>
- </tr>
- <tr bgcolor="#efefef">
- <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Peso aproximado (c/ embalagem):</b></font></td>
- <td style="border-top: 1px solid silver;" width="343"><b><font color="#000080" face="Arial" size="2"><? echo $pesoa; ?> Kg</font></b></td>
- </tr>
- <tr bgcolor="#f5f5f5">
- <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Quantidade:</b></font></td>
- <td style="border-top: 1px solid silver;" width="343"><select class="input" style="width: 40px;" name="multiplicador">
- <option value="1" selected="selected">1</option>
- <option value="2">2</option>
- <option value="3">3</option>
- <option value="4">4</option>
- <option value="5">5</option>
- <option value="6">6</option>
- <option value="7">7</option>
- <option value="8">8</option>
- <option value="9">9</option>
- <option value="10">10</option>
- </select></td>
- </tr>
- <tr bgcolor="#efefef">
- <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Tipo de Serviço:</b></font></td>
- <td style="border-top: 1px solid silver;" width="343"><select class="input" name="servico" id="servico" >
- <option value="40010" selected>SEDEX</option>
- <option value="41106">PAC</option>
- <option value="40045">SEDEX A COBRAR</option>
- <option value="41017">NORMAL</option>
- </select></td>
- </tr>
- <tr bgcolor="#f5f5f5">
- <td style="border-top: 1px solid silver; border-bottom: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Informe
- seu CEP:</b></font></td>
- <td style="border-top: 1px solid silver; border-bottom: 1px solid silver;" width="343"><table border="0" cellpadding="0" cellspacing="0" width="100%">
- <tbody>
- <tr>
- <td width="29%"><div align="left">
- <input class="input" style="font-weight: bold; width: 50px;" onkeypress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false; if(event.keyCode == 13)event.returnValue=false;" maxlength="5" size="20" name="cepdestino1" size="7" type="text">
- -
- <input class="input" style="font-weight: bold; width: 30px;" onkeypress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false; if(event.keyCode == 13)event.returnValue=false;" maxlength="3" size="20" name="cepdestino2" size="7" type="text">
- </div></td>
- <td width="65%"><p align="left" class="style6"><font size="2">Não sabe seu CEP ?<br>
- Então
- clique <a href="http://www.correios.com.br/servicos/cep/cep_loc_log.cfm" target="_blank"><b><font color="#0000ff">AQUI</font></b></a></font> </p></td>
- </tr>
- </tbody>
- </table></td>
- </tr>
- </tbody>
- </table></td>
- </tr>
- <tr height="30">
- <td align="right" height="10" valign="top"> </td>
- <td height="10" valign="top"> </td>
- <td height="10" valign="top"><p style="line-height: 100%; margin-top: 0pt; margin-bottom: 0pt;"> </p></td>
- </tr>
- <tr height="30">
- <td align="right" height="30" valign="top"> </td>
- <td height="30" valign="top"> </td>
- <td height="30" valign="top"><input style="width: 180px; height: 24px; color: rgb(255, 255, 255); background-color: rgb(0, 255, 0); font-weight: bold;" onclick="return verifica_cep(this);" value="Calcular Frete" type="submit">
- <input style="width: 180px; height: 24px; color: rgb(255, 255, 255); background-color: rgb(255, 0, 0); font-weight: bold;" value="Limpar" type="reset"> </td>
- </tr>
- </tbody>
- <tbody>
- <tr>
- <td>
- </form>
- </table></td>
- </tr>
- </tbody>
- </table>
- </td>
- </tr>
- </tbody>
- </table>
- <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
- <tbody>
- <tr>
- <td><div align="center">
- <p class="style5 style4 style1"> </p>
- <p class="style5 style4 style1"><a href="http://www.lgz.com.br" class="style7">Cálculo de Frete pelo Sistema LegalLojaML - Lojas Integradas com o Mercado Livre</a></p>
- </div></td>
- </tr>
- </tbody>
- </table>
- <? } else { ?>
- <table align="center" border="0" cellpadding="0" cellspacing="0" width="752">
- <tbody>
- <tr>
- <td width="225">
- <p align="center"><img src="images/<? echo STORE_LOGO; ?>"></p>
- </td>
- <td width="523">
- <p align="center"><b><font face="Verdana" size="5">Valor do Frete</font></b></p></td>
- </tr>
- <tr>
- <td colspan="2" width="750"> </td>
- </tr>
- </tbody>
- </table>
- <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
- <tbody>
- <tr>
- <td><table border="0" cellpadding="0" cellspacing="0" width="750">
- <tbody>
- <tr>
- <td>
- <tbody>
- <tr>
- <td align="right" valign="top" width="28%"> </td>
- <td valign="top" width="2%"> </td>
- <td valign="top" width="70%"><font face="Arial" size="2"><span class="style1">ATENÇÃO:</span></font><font color="#000000" face="Arial" size="2"> Esta página exibe uma SIMULAÇÃO do valor do frete, portanto seu resultado pode ocasionalmente não ser o valor real do frete. Nos reservamos o direito de corrigir eventuais diferenças no cálculo.</font></td>
- </tr>
- <tr height="30">
- <td align="right" height="15"> </td>
- <td height="15"> </td>
- <td height="15"> </td>
- </tr>
- <tr height="30">
- <td align="right" height="10" valign="top"><div align="center"><img src="images/<? echo $imagemproduto; ?>" name="imgp1" border="0" width="150"> </div></td>
- <td height="10" valign="top"> </td>
- <td height="10" valign="top"><p class="infoBoxHeading style2">O valor do frete para <strong> <? echo $multiplicador; ?> </strong><? echo $unidplural; ?> do produto <strong><? echo $nomeprodutoml; ?></strong> com entrega através do serviço de <strong><? echo $sedex; ?></strong> no C.E.P. <strong><? echo $cepdestino; ?></strong> é:</p>
- <p align="center" class="style3">R$ <? echo $valorfrete; ?></p>
- <p align="center" class="style3"> </p>
- <p align="center" class="style3">
- <input style="width: 180px; height: 24px; color: rgb(255, 255, 255); background-color: rgb(0, 0, 255); font-weight: bold;" onclick="history.back()" value="Novo Cálculo" type="submit">
- </p></td>
- </tr>
- <tr height="30"> </tr>
- </tbody>
- <tbody>
- <tr>
- </table></td>
- </tr>
- </tbody>
- </table>
- </td>
- </tr>
- </tbody>
- </table>
- <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
- <tbody>
- <tr>
- <td><div align="center"><span class="style5 style4"><a href="http://www.lgz.com.br" class="style7">Cálculo de Frete pelo Sistema LegalLojaML - Lojas Integradas com o Mercado Livre</a></span></div></td>
- </tr>
- </tbody>
- </table><? } ?>
- </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement