Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Walter Alves

eregi_replace is deprecated

Recommended Posts

Bom estou tendo erro no calculo do frete e vi que a função eregi esta obsoleto e troqui as linhas

$sCepOrigem = eregi_replace("([^0-9])","",$this->_origem);

$sCepDestino = eregi_replace("([^0-9])","",$this->_destino);

 

por

 

$sCepOrigem = preg_replace("/([^0-9])/i","",$this->_destino);

$sCepDestino = preg_replace("/([^0-9])/i","",$this->_destino);

 

saiu o erro de deprecated mais ainda não esta calculando o frete alguém poderia me ajudar por favor

agradeço

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

o padrão de entrada é 80000-000? e saida :80000000?

Compartilhar este post


Link para o post
Compartilhar em outros sites

COMO ASSIM PODERIA ME EXPLICAR MELHOR TA AI O ARQUIVO POR COMPLETO

<?php
	class SHIPPING_CORREIOS extends ISC_SHIPPING
	{

		private $_deliverytype = "";


		private $_destzip = "";


		private $_deliverytypes = array();


		public function __construct()
		{

			parent::__construct();
			$this->_name = 'Correios';
			$this->_image = "images.jpg";
			$this->_description = 'Correios';
			$this->_help = 'correios';
			$this->_height = 315;
			$this->_countries = array("all");
			$this->_showtestlink = false;
		}

public function SetCustomVars()
		{
		
			$this->_variables['displayname'] = array(
		'name'			=> 'Correios do Brasil',
		'type'		=> 'textbox',
		'help'		=> 'Modulo de Envio Correios',
		'default'	=> $this->GetName(),
		'savedvalue'	=> array(),
		'required'	=> true);
		
			$this->_variables['id'] = array("name" => 'ID',
			   "type" => "textbox",
			   "help" => 'Obs apenas para clientes afiliados aos correios',
			   "default" => "",
			   "required" => false
			);
			
		$this->_variables['senha'] = array("name" => 'Senha',
			   "type" => "textbox",
			   "help" => 'Obs apenas para clientes afiliados aos correios',
			   "default" => "",
			   "required" => false
			);

			$this->_variables['meios'] = array("name" => 'Meios',
			   "type" => "dropdown",
			   "help" => 'Meios de Entrega Ultilizados - Sem Senha: PAC, Sedex - Com Senha: Todos',
			   "default" => "no",
				"savedvalue" => array(),
			   "required" => true,
			   "options" => array('PAC' => '41106',
							  'Sedex' => '40010',
							  'Sedex 10' => '40215',
							  'Sedex Hoje' => '40290',
							  'Sedex a Cobrar' => '40045',
							  'e-Sedex' => '81019',
							  'Malote' => '44105',
				),
				"multiselect" => true
			);
			
		}
		
		

		private function GetQuote()
		{

        $this->SetCustomVars();
		
			$this->_id = $this->GetValue("id");
			$this->_senha = $this->GetValue("senha");
			 
			 
				$this->_origem = GetConfig('CompanyZip');
				$sCepOrigem = preg_replace("/([^0-9])/i","",$this->_origem);
				$this->_destino = $this->_destination_zip;
				$sCepDestino = preg_replace("/([^0-9])/i","",$this->_destino);
				$this->_peso = number_format(max(ConvertWeight($this->_weight, 'kgs'), 0.1), 1);

		switch($this->_deliverytype){
		       case'41106':
		$tipo = "PAC";
		break;
				case'40010':
		$tipo = "Sedex";
		break;
				case'40215':
		$tipo = "Sedex 10";
		break;
				case'40290':
		$tipo = "Sedex Hoje";
		break;
				case'40045':
		$tipo = "Sedex a Cobrar";
		break;
				case'81019':
		$tipo = "e-Sedex";
		break;
				case'44105':
		$tipo = "Malote";
		break;
		
		}

$total = $count = 0;

if (isset($_SESSION['CART']['ITEMS'])) {
	foreach ($_SESSION['CART']['ITEMS'] as $item) {
		$total += $item['product_price'] * $item['quantity'];
	}
}
$total = str_replace('.',',',$total);
$correios ="http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?"
."nCdEmpresa=".$this->_id."&"
."sDsSenha=".$this->_senha."&"
."sCepOrigem=".$sCepOrigem."&"
."sCepDestino=".$sCepDestino."&"
."nVlPeso=".$this->_peso."&"
."nCdFormato=1&"
."nVlComprimento=20&"
."nVlAltura=20&"
."nVlLargura=20&"
."sCdMaoPropria=N&"
."nVlValorDeclarado=".$total."&"
."sCdAvisoRecebimento=N&"
."nCdServico=".$this->_deliverytype."&"
."nVlDiametro=0&"
."StrRetorno=xml";
//inicia o curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $correios);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 2);
$html1 = curl_exec ($ch);
curl_close ($ch);
//pega o valor
$html = explode('<Valor>', $html1);
$html2 = explode('</Valor>', $html[1]);
$this->_shippingcost = str_replace(',','.',$html2[0]);
//pega o prazo
$pra = explode('<PrazoEntrega>', $html1);
$prazo = explode('</PrazoEntrega>', $pra[1]);

if($this->_shippingcost > "0") { 
$newQuote = new ISC_SHIPPING_QUOTE($this->GetId(), $this->GetName(), $this->_shippingcost, $tipo);
return $newQuote;
}else{
return false;
}
}

		public function GetServiceQuotes()
		{
			$this->ResetErrors();
			$QuoteList = array();

			// Get the selected delivery types
			$delivery_types = $this->GetValue("meios");

			if(!is_array($delivery_types) && $delivery_types != "") {
				$delivery_types = array($delivery_types);
			}

			foreach($delivery_types as $delivery_type) {

				$this->_deliverytype = $delivery_type;

				// Next actually retrieve the quote
				$err = "";
				$result = $this->GetQuote($err);

				// Was it a valid quote?
				if(is_object($result)) {
					$QuoteList[] = $result;
				// Invalid quote, log the error
				} else {
					foreach($this->GetErrors() as $error) {
						$GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('shipping', $this->GetName()), $this->_deliverytypes[$delivery_type].": " .GetLang('ShippingQuoteError'), $error);
					}
				}
			}

			return $QuoteList;
		}




		public function GetTrackingLink($trackingLink = "")
		{
			return 'http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' . urlencode($trackingLink);
		}
	}

Compartilhar este post


Link para o post
Compartilhar em outros sites

$sCepOrigem = preg_replace("/([^0-9])/i","",$this->_destino);

$sCepDestino = preg_replace("/([^0-9])/i","",$this->_destino);

Foi só um erro de "Ctrl + C / Ctrl + V" ou você esqueceu de colocar na linha de cima $this->origem ao invés de $this->destino?

Compartilhar este post


Link para o post
Compartilhar em outros sites

de um print_r() em $this->_origem e $this->_destino e poste o resultado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não esse erro ai foi só quando eu fui posta aqui mais la ta normal em relação ao $this->origem e $this->destino

e ainda sem calcular

e ainda estou sem entender o que Shini quer, poderia ser mais especifico ainda sou amador em php

Compartilhar este post


Link para o post
Compartilhar em outros sites

deixe seu codigo assim:

 

 

$sCepOrigem = preg_replace("/([^0-9])/i","",$this->_origem);
$this->_destino = $this->_destination_zip;
$sCepDestino = preg_replace("/([^0-9])/i","",$this->_destino);

echo '<pre>';
print_r($this->_destino);
print_r($this->_origem);

Compartilhar este post


Link para o post
Compartilhar em outros sites

apareceu assim sendo que o cep 63020-000 foi eu que coloquei


63020-00089032-600
63020-00089032-600

Infelizmente não entregamos em sua localização.
Por favor selecione outra localização e tente novamente.

Compartilhar este post


Link para o post
Compartilhar em outros sites

 

 

 

<?php
class SHIPPING_CORREIOS extends ISC_SHIPPING{
private $_deliverytype = "";
private $_destzip = "";
private $_deliverytypes = array(
'PAC' => '41106',
'Sedex' => '40010',
'Sedex 10' => '40215',
'Sedex Hoje' => '40290',
'Sedex a Cobrar'=> '40045',
'e-Sedex' => '81019',
'Malote' => '44105'
);
 
public function __construct(){
parent::__construct();
$this->_name = 'Correios';
$this->_image = "images.jpg";
$this->_description = 'Correios';
$this->_help = 'correios';
$this->_height = 315;
$this->_countries = array("all");
$this->_showtestlink = false;
$this->SetCustomVars();
}
 
public function SetCustomVars(){
$this->_variables['displayname'] = array(
'name' => 'Correios do Brasil',
'type' => 'textbox',
'help' => 'Modulo de Envio Correios',
'default' => $this->GetName(),
'savedvalue'=> array(),
'required' => true
 );
 
$this->_variables['id'] = array(
"name" => 'ID',
   "type" => "textbox",
"help" => 'Obs apenas para clientes afiliados aos correios',
"default" => "",
"required" => false
);
 
$this->_variables['senha'] = array(
"name" => 'Senha',
"type" => "textbox",
"help" => 'Obs apenas para clientes afiliados aos correios',
"default" => "",
"required" => false
);
 
$this->_variables['meios'] = array(
"name" => 'Meios',
"type" => "dropdown",
"help" => 'Meios de Entrega Ultilizados - Sem Senha: PAC, Sedex - Com Senha: Todos',
"default" => "no",
"savedvalue" => array(),
"required" => true,
"options"  => $this->_deliverytypes ,
"multiselect" => true
);
 
}
 
 
 
private function GetQuote(){
$cepPattern = "/([^0-9])/i";
 
$this->_id = $this->GetValue("id");
$this->_senha = $this->GetValue("senha");
$this->_origem = GetConfig('CompanyZip');
 
$sCepOrigem = preg_replace($cepPattern , "" , $this->_origem);
$sCepDestino = preg_replace($cepPattern , "" , $this->_destino);
 
$this->_destino = $this->_destination_zip;
$this->_peso = number_format(max(ConvertWeight($this->_weight, 'kgs'), 0.1), 1);
 
$tipo = array_keys($this->_deliverytypes[$this->_deliverytype]);
 
$total = 0;
 
if (isset($_SESSION['CART']['ITEMS'])){
foreach ($_SESSION['CART']['ITEMS'] as $item) {
$total += $item['product_price'] * $item['quantity'];
}
}
 
$totalReplace = str_replace('.' , ',' , $total) ;
 
$correios = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?
nCdEmpresa={$this->_id}&
sDsSenha={$this->_senha}&
sCepOrigem={$sCepOrigem}&
sCepDestino={$sCepDestino}&
    nVlPeso={$this->_peso}&
nCdFormato=1&
nVlComprimento=20&
nVlAltura=20&
nVlLargura=20&
sCdMaoPropria=N&
nVlValorDeclarado={$totalReplace}&
sCdAvisoRecebimento=N&
nCdServico={$this->_deliverytype}&
nVlDiametro=0&
StrRetorno=xml";
 
//inicia o curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $correios);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 2);
$html1 = curl_exec ($ch);
curl_close ($ch);
 
//pega o valor
$html = explode('<Valor>', $html1);
$html2 = explode('</Valor>', $html[1]);
$this->_shippingcost = str_replace(',' , '.' , $html2[0]);
 
//pega o prazo
$pra = explode('<PrazoEntrega>', $html1);
$prazo = explode('</PrazoEntrega>', $pra[1]);
 
if($this->_shippingcost > 0){
$newQuote = new ISC_SHIPPING_QUOTE($this->GetId(), $this->GetName(), $this->_shippingcost, $tipo);
return $newQuote;
}else
return false;
}
 
public function GetServiceQuotes(){
$this->ResetErrors();
$QuoteList = array();
 
// Get the selected delivery types
$delivery_types = $this->GetValue("meios");
 
if(!is_array($delivery_types) && $delivery_types != "") {
$delivery_types = array($delivery_types);
}
 
foreach($delivery_types as $delivery_type){
 
$this->_deliverytype = $delivery_type;
 
// Next actually retrieve the quote
$err = "";
$result = $this->GetQuote($err);
 
// Was it a valid quote?
if(is_object($result))
$QuoteList[] = $result;
// Invalid quote, log the error
else{
foreach($this->GetErrors() as $error) {
$GLOBALS['ISC_CLASS_LOG']->LogSystemError(array('shipping', $this->GetName()), $this->_deliverytypes[$delivery_type].": " .GetLang('ShippingQuoteError'), $error);
}
}
}
return $QuoteList;
}
 
public function GetTrackingLink($trackingLink = ""){
return 'http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' . urlencode($trackingLink);
}
}

 

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

no codigo de rafael barros aparareceu esse erros

 

Notice: Undefined property: SHIPPING_CORREIOS::$_destino in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 76

 

Notice: Undefined index: 41106 in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 81

 

Warning: array_keys() expects parameter 1 to be array, null given in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 81

 

Notice: Undefined offset: 1 in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 119

 

Notice: Undefined offset: 1 in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 124

 

Notice: Undefined index: 40010 in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 81

 

Warning: array_keys() expects parameter 1 to be array, null given in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 81

 

Notice: Undefined offset: 1 in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 119

 

Notice: Undefined offset: 1 in /home2/marinaeg/public_html/loja/modules/shipping/correios/module.correios.php on line 124

Infelizmente não entregamos em sua localização.

Por favor selecione outra localização e tente novamente.

 

 

acho que o erro pode ser na forma do resultado pois no print exibe

 

 

63020-00089032-600

63020-00089032-600

Infelizmente não entregamos em sua localização.

Por favor selecione outra localização e tente novamente.

 

o certo acho que seria no segundo valor

 

6302000089032600 sem hifen

 

 

alguém poderia da mais opiniões ainda não consegui resolver o problema

 

 

 

 

coloquei um str_replace mais inda continua errado e sem calcular agora aparece assim

 

 

6302000089032-600

6302000089032-600

mesmo colocando o comando str_replace tanto na origem quanto no destino

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.