Version Notes
Módulo de cálculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje e Sedex a Cobrar.
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | PedroTeixeira_Correios |
| Version | 4.1.0 |
| Comparing to | |
| See all releases | |
Code changes from version 4.0.0 to 4.1.0
- app/code/community/PedroTeixeira/Correios/Helper/Data.php +1 -4
- app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +710 -493
- app/code/community/PedroTeixeira/Correios/Model/Source/FreeMethods.php +0 -36
- app/code/community/PedroTeixeira/Correios/Model/Source/PostMethods.php +9 -9
- app/code/community/PedroTeixeira/Correios/etc/config.xml +48 -16
- app/code/community/PedroTeixeira/Correios/etc/system.xml +27 -25
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-install-4.0.0.php +3 -3
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-upgrade-4.0.0-4.1.0.php +29 -0
- package.xml +12 -8
app/code/community/PedroTeixeira/Correios/Helper/Data.php
CHANGED
|
@@ -15,7 +15,4 @@
|
|
| 15 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 16 |
*/
|
| 17 |
|
| 18 |
-
class PedroTeixeira_Correios_Helper_Data extends Mage_Core_Helper_Abstract
|
| 19 |
-
{
|
| 20 |
-
|
| 21 |
-
}
|
| 15 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 16 |
*/
|
| 17 |
|
| 18 |
+
class PedroTeixeira_Correios_Helper_Data extends Mage_Core_Helper_Abstract { }
|
|
|
|
|
|
|
|
|
app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php
CHANGED
|
@@ -16,550 +16,767 @@
|
|
| 16 |
*/
|
| 17 |
|
| 18 |
/**
|
| 19 |
-
*
|
| 20 |
*
|
| 21 |
* @category PedroTeixeira
|
| 22 |
* @package PedroTeixeira_Correios
|
| 23 |
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 24 |
-
*/
|
| 25 |
-
|
| 26 |
-
class ParametersLocaweb { }
|
| 27 |
|
| 28 |
class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
| 29 |
extends Mage_Shipping_Model_Carrier_Abstract
|
| 30 |
implements Mage_Shipping_Model_Carrier_Interface
|
| 31 |
{
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
{
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
return false;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
|
| 73 |
-
$destCountry = $request->getDestCountryId();
|
| 74 |
-
if ($origCountry != "BR" || $destCountry != "BR"){
|
| 75 |
-
//Out of delivery area
|
| 76 |
-
Mage::log('PedroTeixeira_Correios: Out of delivery area');
|
| 77 |
-
return false;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
$result = Mage::getModel('shipping/rate_result');
|
| 83 |
-
$error = Mage::getModel('shipping/rate_result_error');
|
| 84 |
-
|
| 85 |
-
$error->setCarrier($this->_code);
|
| 86 |
-
$error->setCarrierTitle($this->getConfigData('title'));
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
$packagevalue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
|
| 90 |
-
$minorderval = $this->getConfigData('min_order_value');
|
| 91 |
-
$maxorderval = $this->getConfigData('max_order_value');
|
| 92 |
-
if($packagevalue <= $minorderval || $packagevalue >= $maxorderval){
|
| 93 |
-
//Value limits
|
| 94 |
-
Mage::log('PedroTeixeira_Correios: Value limits');
|
| 95 |
-
$error->setErrorMessage($this->getConfigData('valueerror'));
|
| 96 |
-
$result->append($error);
|
| 97 |
-
return $result;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
$frompcode = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
|
| 101 |
-
$topcode = $request->getDestPostcode();
|
| 102 |
-
|
| 103 |
-
//Fix Zip Code
|
| 104 |
-
$frompcode = str_replace('-', '', trim($frompcode));
|
| 105 |
-
$topcode = str_replace('-', '', trim($topcode));
|
| 106 |
-
|
| 107 |
-
if(!preg_match("/^([0-9]{8})$/", $topcode))
|
| 108 |
-
{
|
| 109 |
-
//Invalid Zip Code
|
| 110 |
-
Mage::log('PedroTeixeira_Correios: Invalid Zip Code');
|
| 111 |
-
$error->setErrorMessage($this->getConfigData('zipcodeerror'));
|
| 112 |
-
$result->append($error);
|
| 113 |
-
Mage::helper('customer')->__('Invalid ZIP CODE');
|
| 114 |
-
return $result;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
$
|
| 169 |
-
else
|
| 170 |
-
$itemComprimento = $_product->getData('volume_comprimento');
|
| 171 |
|
| 172 |
-
|
| 173 |
-
$
|
| 174 |
-
$pesoCubicoTotal = $pesoCubicoTotal + $itemPesoCubico;
|
| 175 |
-
$volumeTotal = $volumeTotal + ($itemPesoCubico * 4800);
|
| 176 |
|
| 177 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
}
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
if($pesoCubicoTotal > $sweight){
|
| 182 |
-
$mediaMedidas = round(pow((int)$volumeTotal, (1/3)));
|
| 183 |
-
$volumeComprimento = (($mediaMedidas < 16) ? 16 : $mediaMedidas);
|
| 184 |
-
$volumeAltura = (($mediaMedidas < 2) ? 2 : $mediaMedidas);
|
| 185 |
-
$volumeLargura = (($mediaMedidas < 11) ? 11 : $mediaMedidas);
|
| 186 |
-
}else{
|
| 187 |
-
$volumeComprimento = 16;
|
| 188 |
-
$volumeAltura = 2;
|
| 189 |
-
$volumeLargura = 11;
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
//Define post method
|
| 193 |
-
$shipping_methods = array();
|
| 194 |
-
|
| 195 |
-
$postmethods = explode(",", $this->getConfigData('postmethods'));
|
| 196 |
-
|
| 197 |
-
foreach($postmethods as $methods)
|
| 198 |
-
{
|
| 199 |
-
|
| 200 |
-
switch ($methods){
|
| 201 |
-
case 0:
|
| 202 |
-
$shipping_methods["40010"] = array ("Sedex", "3");
|
| 203 |
-
break;
|
| 204 |
-
case 1:
|
| 205 |
-
$shipping_methods["40096"] = array ("Sedex", "3");
|
| 206 |
-
break;
|
| 207 |
-
case 2:
|
| 208 |
-
$shipping_methods["81019"] = array ("E-Sedex", "3");
|
| 209 |
-
break;
|
| 210 |
-
case 3:
|
| 211 |
-
$shipping_methods["41025"] = array ("PAC", "3");
|
| 212 |
-
break;
|
| 213 |
-
case 4:
|
| 214 |
-
$shipping_methods["41106"] = array ("PAC", "3");
|
| 215 |
-
break;
|
| 216 |
-
case 5:
|
| 217 |
-
$shipping_methods["41068"] = array ("PAC", "3");
|
| 218 |
-
break;
|
| 219 |
-
case 6:
|
| 220 |
-
$shipping_methods["40215"] = array ("Sedex 10", "1");
|
| 221 |
-
break;
|
| 222 |
-
case 7:
|
| 223 |
-
$shipping_methods["40290"] = array ("Sedex HOJE", "1");
|
| 224 |
-
break;
|
| 225 |
-
case 8:
|
| 226 |
-
$shipping_methods["40045"] = array ("Sedex a Cobrar", "5");
|
| 227 |
-
break;
|
| 228 |
-
}
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
foreach($shipping_methods as $shipping_method => $shipping_values){
|
| 232 |
|
| 233 |
-
//
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
|
| 240 |
-
|
| 241 |
-
'trace' => true,
|
| 242 |
-
'exceptions' => true,
|
| 243 |
-
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
|
| 244 |
-
'connection_timeout' => 1000
|
| 245 |
-
));
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
$parms->cepOrigem = utf8_encode($frompcode);
|
| 250 |
-
$parms->cepDestino = utf8_encode($topcode);
|
| 251 |
-
$parms->peso = utf8_encode(str_replace(".",",",$sweight));
|
| 252 |
-
$parms->volume = utf8_encode($volumeTotal);
|
| 253 |
-
$parms->codigo = utf8_encode($shipping_method);
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
|
| 258 |
-
|
|
|
|
| 259 |
|
| 260 |
-
|
|
|
|
| 261 |
|
| 262 |
-
|
| 263 |
|
| 264 |
-
|
|
|
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
$client->setParameterGet('nVlPeso', $sweight);
|
| 272 |
-
$client->setParameterGet('sCepOrigem', $frompcode);
|
| 273 |
-
$client->setParameterGet('sCepDestino', $topcode);
|
| 274 |
-
$client->setParameterGet('nCdFormato',1);
|
| 275 |
-
$client->setParameterGet('nVlComprimento',$volumeComprimento);
|
| 276 |
-
$client->setParameterGet('nVlAltura',$volumeAltura);
|
| 277 |
-
$client->setParameterGet('nVlLargura',$volumeLargura);
|
| 278 |
-
if($this->getConfigData('mao_propria'))
|
| 279 |
-
$client->setParameterGet('sCdMaoPropria','S');
|
| 280 |
-
else
|
| 281 |
-
$client->setParameterGet('sCdMaoPropria','N');
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
else
|
| 286 |
-
$client->setParameterGet('sCdAvisoRecebimento','N');
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
else
|
| 291 |
-
$client->setParameterGet('nVlValorDeclarado',0);
|
| 292 |
|
|
|
|
| 293 |
|
|
|
|
|
|
|
| 294 |
|
| 295 |
-
if($
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
$
|
| 300 |
-
$result->append($error);
|
| 301 |
-
return $result;
|
| 302 |
}else{
|
| 303 |
-
|
| 304 |
-
$client->setParameterGet('sDsSenha',$this->getConfigData('senha_admin'));
|
| 305 |
}
|
| 306 |
}
|
| 307 |
|
| 308 |
-
$
|
| 309 |
-
$
|
| 310 |
-
|
| 311 |
-
if (!stristr($conteudo, "<?xml")){
|
| 312 |
-
throw new Exception("Not XML returned.");
|
| 313 |
-
}
|
| 314 |
|
| 315 |
-
|
| 316 |
-
//URL Error
|
| 317 |
-
Mage::log('PedroTeixeira_Correios: URL Error');
|
| 318 |
-
$error = Mage::getModel('shipping/rate_result_error');
|
| 319 |
-
$error->setCarrier($this->_code);
|
| 320 |
-
$error->setCarrierTitle($this->getConfigData('title'));
|
| 321 |
-
$error->setMethod($shipping_method);
|
| 322 |
-
$error->setErrorMessage($this->getConfigData('urlerror'));
|
| 323 |
-
$result->append($error);
|
| 324 |
-
$shippingPrice = 0;
|
| 325 |
-
|
| 326 |
-
continue;
|
| 327 |
-
};
|
| 328 |
-
|
| 329 |
-
preg_match_all("/<Codigo>(.+)<\/Codigo>/", $conteudo, $xml_servico);
|
| 330 |
-
preg_match_all("/<Valor>(.+)<\/Valor>/", $conteudo, $preco_postal);
|
| 331 |
-
preg_match_all("/<PrazoEntrega>(.+)<\/PrazoEntrega>/", $conteudo, $prazo_postal);
|
| 332 |
-
preg_match_all("/<Erro>(.+)<\/Erro>/", $conteudo, $err_id);
|
| 333 |
-
$err_id = str_replace('-', '', $err_id[1][0]);
|
| 334 |
-
$err_id = (int)$err_id;
|
| 335 |
-
preg_match_all("/<MsgErro>(.+)<\/MsgErro>/", $conteudo, $err_msg);
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
$correiosReturn = array(
|
| 339 |
-
"prazo" => $prazo_postal[1][0]
|
| 340 |
-
);
|
| 341 |
|
| 342 |
-
if(trim($err_id) == "0"){
|
| 343 |
-
$shippingPrice = floatval(str_replace(",",".",$preco_postal[1][0]));
|
| 344 |
}else{
|
| 345 |
-
|
| 346 |
-
$ignorar = explode(',',$this->getConfigData('ignorar_erro'));
|
| 347 |
-
$ignorar = array_flip($ignorar);
|
| 348 |
-
if(!array_key_exists($err_id, $ignorar)){
|
| 349 |
-
//Error
|
| 350 |
-
$error = Mage::getModel('shipping/rate_result_error');
|
| 351 |
-
$error->setCarrier($this->_code);
|
| 352 |
-
$error->setCarrierTitle($this->getConfigData('title'));
|
| 353 |
-
$error->setMethod($shipping_method);
|
| 354 |
-
|
| 355 |
-
// Correios Error
|
| 356 |
-
Mage::log('PedroTeixeira_Correios: Correios Error');
|
| 357 |
-
$error->setErrorMessage(sprintf($this->getConfigData('correioserror'), $shipping_values[0], $err_msg[1][0], $err_id));
|
| 358 |
-
$result->append($error);
|
| 359 |
-
$shippingPrice = 0;
|
| 360 |
-
}else{
|
| 361 |
-
$shippingPrice = 0;
|
| 362 |
-
}
|
| 363 |
}
|
|
|
|
| 364 |
|
|
|
|
|
|
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
Mage::log('PedroTeixeira_Correios: URL method undefined');
|
| 370 |
-
$error->setErrorMessage($this->getConfigData('urlerror'));
|
| 371 |
-
$result->append($error);
|
| 372 |
-
return $result;
|
| 373 |
-
}
|
| 374 |
-
|
| 375 |
-
if($shippingPrice <= 0){
|
| 376 |
continue;
|
| 377 |
-
|
| 378 |
|
| 379 |
-
|
|
|
|
|
|
|
| 380 |
|
| 381 |
-
|
| 382 |
-
$method->setCarrierTitle($this->getConfigData('title'));
|
| 383 |
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
-
|
|
|
|
|
|
|
| 387 |
|
| 388 |
-
|
| 389 |
-
if($correiosReturn['prazo'] > 0){
|
| 390 |
-
$method->setMethodTitle(sprintf($this->getConfigData('msgprazo'), $shipping_values[0], (int)$correiosReturn['prazo'] + $this->getConfigData('add_prazo')));
|
| 391 |
-
}else{
|
| 392 |
-
$method->setMethodTitle(sprintf($this->getConfigData('msgprazo'), $shipping_values[0], $shipping_values[1] + $this->getConfigData('add_prazo')));
|
| 393 |
-
}
|
| 394 |
-
}else{
|
| 395 |
-
$method->setMethodTitle(sprintf($this->getConfigData('msgprazo'), $shipping_values[0], $shipping_values[1] + $this->getConfigData('add_prazo')));
|
| 396 |
-
}
|
| 397 |
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
-
|
|
|
|
| 405 |
|
| 406 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
$this->_updateFreeMethodQuote($request);
|
| 415 |
-
|
| 416 |
-
return $this->_result;
|
| 417 |
-
}
|
| 418 |
-
|
| 419 |
-
/**
|
| 420 |
-
* Get Tracking Info
|
| 421 |
-
*
|
| 422 |
-
* @param mixed $tracking
|
| 423 |
-
* @return mixed
|
| 424 |
-
*/
|
| 425 |
-
public function getTrackingInfo($tracking) {
|
| 426 |
-
$result = $this->getTracking($tracking);
|
| 427 |
-
if ($result instanceof Mage_Shipping_Model_Tracking_Result){
|
| 428 |
-
if ($trackings = $result->getAllTrackings()) {
|
| 429 |
-
return $trackings[0];
|
| 430 |
-
}
|
| 431 |
-
} elseif (is_string($result) && !empty($result)) {
|
| 432 |
-
return $result;
|
| 433 |
-
}
|
| 434 |
-
|
| 435 |
-
return false;
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
/**
|
| 439 |
-
* Get Tracking
|
| 440 |
-
*
|
| 441 |
-
* @param array $trackings
|
| 442 |
-
* @return Mage_Shipping_Model_Tracking_Result
|
| 443 |
-
*/
|
| 444 |
-
public function getTracking($trackings) {
|
| 445 |
-
$this->_result = Mage::getModel('shipping/tracking_result');
|
| 446 |
-
foreach ((array) $trackings as $code) {
|
| 447 |
-
$this->_getTracking($code);
|
| 448 |
-
}
|
| 449 |
-
return $this->_result;
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
/**
|
| 453 |
-
* Protected Get Tracking, opens the request to Correios
|
| 454 |
-
*
|
| 455 |
-
* @param string $code
|
| 456 |
-
* @return boolean
|
| 457 |
-
*/
|
| 458 |
-
protected function _getTracking($code) {
|
| 459 |
-
$error = Mage::getModel('shipping/tracking_result_error');
|
| 460 |
-
$error->setTracking($code);
|
| 461 |
-
$error->setCarrier($this->_code);
|
| 462 |
-
$error->setCarrierTitle($this->getConfigData('title'));
|
| 463 |
-
$error->setErrorMessage($this->getConfigData('urlerror'));
|
| 464 |
-
|
| 465 |
-
$url = 'http://websro.correios.com.br/sro_bin/txect01$.QueryList';
|
| 466 |
-
$url .= '?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' . $code;
|
| 467 |
-
try {
|
| 468 |
-
$client = new Zend_Http_Client();
|
| 469 |
-
$client->setUri($url);
|
| 470 |
-
$content = $client->request();
|
| 471 |
-
$body = $content->getBody();
|
| 472 |
-
} catch (Exception $e) {
|
| 473 |
-
$this->_result->append($error);
|
| 474 |
-
return false;
|
| 475 |
-
}
|
| 476 |
-
|
| 477 |
-
if (!preg_match('#<table ([^>]+)>(.*?)</table>#is', $body, $matches)) {
|
| 478 |
-
$this->_result->append($error);
|
| 479 |
-
return false;
|
| 480 |
-
}
|
| 481 |
-
$table = $matches[2];
|
| 482 |
-
|
| 483 |
-
if (!preg_match_all('/<tr>(.*)<\/tr>/i', $table, $columns, PREG_SET_ORDER)) {
|
| 484 |
-
$this->_result->append($error);
|
| 485 |
-
return false;
|
| 486 |
-
}
|
| 487 |
-
|
| 488 |
-
$progress = array();
|
| 489 |
-
for ($i = 0; $i < count($columns); $i++) {
|
| 490 |
-
$column = $columns[$i][1];
|
| 491 |
-
|
| 492 |
-
$description = '';
|
| 493 |
-
$found = false;
|
| 494 |
-
if (preg_match('/<td rowspan="?2"?/i', $column) && preg_match('/<td rowspan="?2"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i', $column, $matches)) {
|
| 495 |
-
if (preg_match('/<td colspan="?2"?>(.*)<\/td>/i', $columns[$i+1][1], $matchesDescription)) {
|
| 496 |
-
$description = str_replace(' ', '', $matchesDescription[1]);
|
| 497 |
-
}
|
| 498 |
-
|
| 499 |
-
$found = true;
|
| 500 |
-
} elseif (preg_match('/<td rowspan="?1"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i', $column, $matches)) {
|
| 501 |
-
$found = true;
|
| 502 |
-
}
|
| 503 |
-
|
| 504 |
-
if ($found) {
|
| 505 |
-
$datetime = split(' ', $matches[1]);
|
| 506 |
-
|
| 507 |
-
$locale = new Zend_Locale('pt_BR');
|
| 508 |
-
$date='';
|
| 509 |
-
$date = new Zend_Date($datetime[0], 'dd/MM/YYYY', $locale);
|
| 510 |
-
|
| 511 |
-
$track = array(
|
| 512 |
-
'deliverydate' => $date->toString('YYYY-MM-dd'),
|
| 513 |
-
'deliverytime' => $datetime[1] . ':00',
|
| 514 |
-
'deliverylocation' => htmlentities($matches[2]),
|
| 515 |
-
'status' => htmlentities($matches[3]),
|
| 516 |
-
'activity' => htmlentities($matches[3])
|
| 517 |
-
);
|
| 518 |
-
|
| 519 |
-
if ($description !== '') {
|
| 520 |
-
$track['activity'] = $matches[3] . ' - ' . htmlentities($description);
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
$progress[] = $track;
|
| 524 |
-
}
|
| 525 |
-
}
|
| 526 |
-
|
| 527 |
-
if (!empty($progress)) {
|
| 528 |
-
$track = $progress[0];
|
| 529 |
-
$track['progressdetail'] = $progress;
|
| 530 |
-
|
| 531 |
-
$tracking = Mage::getModel('shipping/tracking_result_status');
|
| 532 |
-
$tracking->setTracking($code);
|
| 533 |
-
$tracking->setCarrier('correios');
|
| 534 |
-
$tracking->setCarrierTitle($this->getConfigData('title'));
|
| 535 |
-
$tracking->addData($track);
|
| 536 |
-
|
| 537 |
-
$this->_result->append($tracking);
|
| 538 |
-
return true;
|
| 539 |
-
} else {
|
| 540 |
-
$this->_result->append($error);
|
| 541 |
-
return false;
|
| 542 |
-
}
|
| 543 |
-
}
|
| 544 |
-
|
| 545 |
-
/**
|
| 546 |
-
* Returns the allowed carrier methods
|
| 547 |
-
*
|
| 548 |
-
* @return array
|
| 549 |
-
*/
|
| 550 |
-
public function getAllowedMethods()
|
| 551 |
-
{
|
| 552 |
-
return array($this->_code => $this->getConfigData('title'));
|
| 553 |
-
}
|
| 554 |
-
|
| 555 |
-
/**
|
| 556 |
-
* Define ZIP Code as required
|
| 557 |
-
*
|
| 558 |
-
* @return boolean
|
| 559 |
-
*/
|
| 560 |
-
public function isZipCodeRequired()
|
| 561 |
-
{
|
| 562 |
-
return true;
|
| 563 |
-
}
|
| 564 |
|
| 565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
*/
|
| 17 |
|
| 18 |
/**
|
| 19 |
+
* PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
| 20 |
*
|
| 21 |
* @category PedroTeixeira
|
| 22 |
* @package PedroTeixeira_Correios
|
| 23 |
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 24 |
+
*/
|
|
|
|
|
|
|
| 25 |
|
| 26 |
class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
| 27 |
extends Mage_Shipping_Model_Carrier_Abstract
|
| 28 |
implements Mage_Shipping_Model_Carrier_Interface
|
| 29 |
{
|
| 30 |
|
| 31 |
+
/**
|
| 32 |
+
* _code property
|
| 33 |
+
*
|
| 34 |
+
* @var string
|
| 35 |
+
*/
|
| 36 |
+
protected $_code = 'pedroteixeira_correios';
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* _result property
|
| 40 |
+
*
|
| 41 |
+
* @var Mage_Shipping_Model_Rate_Result / Mage_Shipping_Model_Tracking_Result
|
| 42 |
+
*/
|
| 43 |
+
protected $_result = null;
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* ZIP code vars
|
| 47 |
+
*/
|
| 48 |
+
protected $_fromZip = null;
|
| 49 |
+
protected $_toZip = null;
|
| 50 |
+
|
| 51 |
+
/**
|
| 52 |
+
* Value and Weight
|
| 53 |
+
*/
|
| 54 |
+
protected $_packageValue = null;
|
| 55 |
+
protected $_packageWeight = null;
|
| 56 |
+
protected $_pacWeight = null;
|
| 57 |
+
protected $_freeMethodWeight = null;
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Post methods
|
| 61 |
+
*/
|
| 62 |
+
protected $_postMethods = null;
|
| 63 |
+
protected $_postMethodsFixed = null;
|
| 64 |
+
protected $_postMethodsExplode = null;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Free method request
|
| 68 |
+
*/
|
| 69 |
+
protected $_freeMethodRequest = false;
|
| 70 |
+
protected $_freeMethodRequestResult = null;
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* Collect Rates
|
| 74 |
+
*
|
| 75 |
+
* @param Mage_Shipping_Model_Rate_Request $request
|
| 76 |
+
* @return Mage_Shipping_Model_Rate_Result
|
| 77 |
+
*/
|
| 78 |
+
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
|
| 79 |
+
{
|
| 80 |
+
// Do initial check
|
| 81 |
+
if($this->_inicialCheck($request) === false)
|
| 82 |
+
{
|
| 83 |
+
return false;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Check package value
|
| 87 |
+
if($this->_packageValue < $this->getConfigData('min_order_value') || $this->_packageValue > $this->getConfigData('max_order_value'))
|
| 88 |
+
{
|
| 89 |
+
//Value limits
|
| 90 |
+
$this->_throwError('valueerror', 'Value limits', __LINE__);
|
| 91 |
+
return $this->_result;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// Check ZIP Code
|
| 95 |
+
if(!preg_match("/^([0-9]{8})$/", $this->_toZip))
|
| 96 |
{
|
| 97 |
+
//Invalid Zip Code
|
| 98 |
+
$this->_throwError('zipcodeerror', 'Invalid Zip Code', __LINE__);
|
| 99 |
+
return $this->_result;
|
| 100 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
// Fix weight
|
| 103 |
+
$weightCompare = $this->getConfigData('maxweight');
|
| 104 |
+
if($this->getConfigData('weight_type') == 'gr')
|
| 105 |
+
{
|
| 106 |
+
$this->_packageWeight = number_format($this->_packageWeight/1000, 2, '.', '');
|
| 107 |
+
$weightCompare = number_format($weightCompare/1000, 2, '.', '');
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// Check weght
|
| 111 |
+
if ($this->_packageWeight > $weightCompare)
|
| 112 |
+
{
|
| 113 |
+
//Weight exceeded limit
|
| 114 |
+
$this->_throwError('maxweighterror', 'Weight exceeded limit', __LINE__);
|
| 115 |
+
return $this->_result;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// Check weight zero
|
| 119 |
+
if ($this->_packageWeight <= 0)
|
| 120 |
+
{
|
| 121 |
+
//Weight zero
|
| 122 |
+
$this->_throwError('weightzeroerror', 'Weight zero', __LINE__);
|
| 123 |
+
return $this->_result;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Generate PAC Weight
|
| 127 |
+
$this->_generatePacWeight();
|
| 128 |
+
|
| 129 |
+
// Get post methods
|
| 130 |
+
$this->_postMethods = $this->getConfigData('postmethods');
|
| 131 |
+
$this->_postMethodsFixed = $this->_postMethods;
|
| 132 |
+
$this->_postMethodsExplode = explode(",", $this->getConfigData('postmethods'));
|
| 133 |
+
|
| 134 |
+
// Get quotes
|
| 135 |
+
if($this->_getQuotes()->getError()) {
|
| 136 |
+
return $this->_result;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// Use descont codes
|
| 140 |
+
$this->_updateFreeMethodQuote($request);
|
| 141 |
+
|
| 142 |
+
// Return rates / errors
|
| 143 |
+
return $this->_result;
|
| 144 |
+
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* Get shipping quote
|
| 149 |
+
*
|
| 150 |
+
* @return bool
|
| 151 |
+
*/
|
| 152 |
+
protected function _getQuotes(){
|
| 153 |
+
|
| 154 |
+
$pacCodes = explode(",", $this->getConfigData('pac_codes'));
|
| 155 |
+
$contratoCodes = explode(",", $this->getConfigData('contrato_codes'));
|
| 156 |
+
$dieErrors = explode(",", $this->getConfigData('die_errors'));
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
//Define URL method
|
| 160 |
+
switch ($this->getConfigData('urlmethod')){
|
| 161 |
+
|
| 162 |
+
//Locaweb
|
| 163 |
+
case 1:
|
| 164 |
+
|
| 165 |
+
foreach ($this->_postMethodsExplode as $postmethod){
|
| 166 |
+
|
| 167 |
+
try{
|
| 168 |
+
$soap = new SoapClient($this->getConfigData('url_ws_locaweb'), array(
|
| 169 |
+
'trace' => true,
|
| 170 |
+
'exceptions' => true,
|
| 171 |
+
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
|
| 172 |
+
'connection_timeout' => $this->getConfigData('ws_timeout')
|
| 173 |
+
));
|
| 174 |
+
|
| 175 |
+
// Postagem dos parâmetros
|
| 176 |
+
$parms = new Varien_Object();
|
| 177 |
+
$parms->cepOrigem = utf8_encode($this->_fromZip);
|
| 178 |
+
$parms->cepDestino = utf8_encode($this->_toZip);
|
| 179 |
+
|
| 180 |
+
// If PAC use PAC weight
|
| 181 |
+
if(in_array($postmethod, $pacCodes) && $this->_pacWeight > $this->_packageWeight){
|
| 182 |
+
$parms->peso = utf8_encode(str_replace(".",",",$this->_pacWeight));
|
| 183 |
+
}else{
|
| 184 |
+
$parms->peso = utf8_encode(str_replace(".",",",$this->_packageWeight));
|
| 185 |
+
}
|
| 186 |
|
| 187 |
+
$parms->volume = utf8_encode(1);
|
| 188 |
+
$parms->codigo = utf8_encode($postmethod);
|
|
|
|
|
|
|
| 189 |
|
| 190 |
+
// Resgata o valor calculado
|
| 191 |
+
$resposta = $soap->Correios($parms);
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
$shippingPrice = floatval(str_replace(",",".",$resposta->CorreiosResult));
|
| 194 |
+
|
| 195 |
+
}catch(Exception $e){
|
| 196 |
+
//URL Error
|
| 197 |
+
$this->_throwError('urlerror', 'URL Error - ' . $e->getMessage(), __LINE__);
|
| 198 |
+
return $this->_result;
|
| 199 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
+
//URL Error
|
| 202 |
+
if($shippingPrice == 0){
|
| 203 |
+
//URL Error
|
| 204 |
+
$this->_throwError('urlerror', 'URL Error', __LINE__);
|
| 205 |
+
return $this->_result;
|
| 206 |
+
}
|
| 207 |
|
| 208 |
+
$this->_apendShippingReturn($postmethod, $shippingPrice);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
}
|
| 211 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
+
//Correios
|
| 214 |
+
case 0:
|
| 215 |
|
| 216 |
+
$correiosReturn = $this->_getCorreiosReturn();
|
| 217 |
+
if($correiosReturn !== false){
|
| 218 |
|
| 219 |
+
// Check if exist return from Correios
|
| 220 |
+
$existReturn = false;
|
| 221 |
|
| 222 |
+
foreach($correiosReturn as $servicos){
|
| 223 |
|
| 224 |
+
// Get Correios error
|
| 225 |
+
$errorId = $this->_cleanCorreiosError((string)$servicos->Erro);
|
| 226 |
|
| 227 |
+
if($errorId != 0){
|
| 228 |
+
// Error, throw error message
|
| 229 |
+
if(in_array($errorId, $dieErrors)){
|
| 230 |
+
$this->_throwError('correioserror', 'Correios Error: ' . (string)$servicos->MsgErro . ' [Cod. ' . $errorId . '] [Serv. ' . (string)$servicos->Codigo . ']' , __LINE__, (string)$servicos->MsgErro . ' (Cod. ' . $errorId . ')');
|
| 231 |
+
return $this->_result;
|
| 232 |
+
}else{
|
| 233 |
+
continue;
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
|
| 237 |
+
// If PAC, make a new call to WS
|
| 238 |
+
if(in_array((string)$servicos->Codigo, $pacCodes) && $this->_pacWeight > $this->_packageWeight && !in_array($this->_postMethodsFixed, $pacCodes)){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
+
$this->_postMethods = (string)$servicos->Codigo;
|
| 241 |
+
$this->_postMethodsExplode = array((string)$servicos->Codigo);
|
|
|
|
|
|
|
| 242 |
|
| 243 |
+
$correiosReturnPac = $this->_getCorreiosReturn();
|
| 244 |
+
if($correiosReturnPac !== false){
|
|
|
|
|
|
|
| 245 |
|
| 246 |
+
foreach($correiosReturnPac as $servicosPac){
|
| 247 |
|
| 248 |
+
// Get Correios error
|
| 249 |
+
$errorId = $this->_cleanCorreiosError((string)$servicosPac->Erro);
|
| 250 |
|
| 251 |
+
if($errorId != 0){
|
| 252 |
+
// Error, throw error message
|
| 253 |
+
if(in_array($errorId, $dieErrors)){
|
| 254 |
+
$this->_throwError('correioserror', 'Correios Error: ' . (string)$servicosPac->MsgErro . ' (Cod. ' . $errorId . ')', __LINE__, (string)$servicosPac->MsgErro . ' (Cod. ' . $errorId . ')');
|
| 255 |
+
return $this->_result;
|
|
|
|
|
|
|
| 256 |
}else{
|
| 257 |
+
continue;
|
|
|
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
| 261 |
+
$shippingPrice = floatval(str_replace(",",".",(string)$servicosPac->Valor));
|
| 262 |
+
$shippingDelivery = (int)$servicosPac->PrazoEntrega;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
|
|
|
|
|
|
| 266 |
}else{
|
| 267 |
+
return $this->_result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
}
|
| 269 |
+
}else{
|
| 270 |
|
| 271 |
+
$shippingPrice = floatval(str_replace(",",".",(string)$servicos->Valor));
|
| 272 |
+
$shippingDelivery = (int)$servicos->PrazoEntrega;
|
| 273 |
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
if($shippingPrice <= 0){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
continue;
|
| 278 |
+
}
|
| 279 |
|
| 280 |
+
// Apend shipping
|
| 281 |
+
$this->_apendShippingReturn((string)$servicos->Codigo, $shippingPrice, $shippingDelivery);
|
| 282 |
+
$existReturn = true;
|
| 283 |
|
| 284 |
+
}
|
|
|
|
| 285 |
|
| 286 |
+
// All services are ignored
|
| 287 |
+
if($existReturn === false){
|
| 288 |
+
$this->_throwError('urlerror', 'URL Error, all services return with error', __LINE__);
|
| 289 |
+
return $this->_result;
|
| 290 |
+
}
|
| 291 |
|
| 292 |
+
}else{
|
| 293 |
+
// Error on HTTP Correios
|
| 294 |
+
return $this->_result;
|
| 295 |
|
| 296 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
+
break;
|
| 299 |
+
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
// Success
|
| 303 |
+
if($this->_freeMethodRequest === true){
|
| 304 |
+
return $this->_freeMethodRequestResult;
|
| 305 |
+
}else{
|
| 306 |
+
return $this->_result;
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
/**
|
| 312 |
+
* Make initial checks and iniciate module variables
|
| 313 |
+
*
|
| 314 |
+
* @param Mage_Shipping_Model_Rate_Request $request
|
| 315 |
+
* @return boolean
|
| 316 |
+
*/
|
| 317 |
+
protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request){
|
| 318 |
+
|
| 319 |
+
if (!$this->getConfigFlag('active'))
|
| 320 |
+
{
|
| 321 |
+
//Disabled
|
| 322 |
+
Mage::log('PedroTeixeira_Correios: Disabled');
|
| 323 |
+
return false;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
|
| 328 |
+
$destCountry = $request->getDestCountryId();
|
| 329 |
+
if ($origCountry != "BR" || $destCountry != "BR"){
|
| 330 |
+
//Out of delivery area
|
| 331 |
+
Mage::log('PedroTeixeira_Correios: Out of delivery area');
|
| 332 |
+
return false;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// ZIP Code
|
| 336 |
+
$this->_fromZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
|
| 337 |
+
$this->_toZip = $request->getDestPostcode();
|
| 338 |
+
|
| 339 |
+
//Fix Zip Code
|
| 340 |
+
$this->_fromZip = str_replace('-', '', trim($this->_fromZip));
|
| 341 |
+
$this->_toZip = str_replace('-', '', trim($this->_toZip));
|
| 342 |
+
|
| 343 |
+
if(!preg_match("/^([0-9]{8})$/", $this->_fromZip)){
|
| 344 |
+
//From zip code error
|
| 345 |
+
Mage::log('PedroTeixeira_Correios: From ZIP Code Error');
|
| 346 |
+
return false;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
// Result model
|
| 350 |
+
$this->_result = Mage::getModel('shipping/rate_result');
|
| 351 |
+
|
| 352 |
+
// Value
|
| 353 |
+
$this->_packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
|
| 354 |
+
|
| 355 |
+
// Weight
|
| 356 |
+
$this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', '');
|
| 357 |
+
|
| 358 |
+
// Free method weight
|
| 359 |
+
$this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', '');
|
| 360 |
+
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
/**
|
| 364 |
+
* Get Correios return
|
| 365 |
+
*
|
| 366 |
+
* @return bool
|
| 367 |
+
*/
|
| 368 |
+
protected function _getCorreiosReturn(){
|
| 369 |
+
|
| 370 |
+
$filename = $this->getConfigData('url_ws_correios');
|
| 371 |
+
|
| 372 |
+
$pacCodes = explode(",", $this->getConfigData('pac_codes'));
|
| 373 |
+
$contratoCodes = explode(",", $this->getConfigData('contrato_codes'));
|
| 374 |
+
|
| 375 |
+
try {
|
| 376 |
+
$client = new Zend_Http_Client($filename);
|
| 377 |
+
$client->setConfig(array(
|
| 378 |
+
'timeout' => $this->getConfigData('ws_timeout')
|
| 379 |
+
));
|
| 380 |
+
|
| 381 |
+
$client->setParameterGet('StrRetorno', 'xml');
|
| 382 |
+
$client->setParameterGet('nCdServico', $this->_postMethods);
|
| 383 |
+
|
| 384 |
+
if(in_array($this->_postMethods, $pacCodes) && $this->_pacWeight > $this->_packageWeight){
|
| 385 |
+
$client->setParameterGet('nVlPeso', $this->_pacWeight);
|
| 386 |
+
}else{
|
| 387 |
+
$client->setParameterGet('nVlPeso', $this->_packageWeight);
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
$client->setParameterGet('sCepOrigem', $this->_fromZip);
|
| 391 |
+
$client->setParameterGet('sCepDestino', $this->_toZip);
|
| 392 |
+
$client->setParameterGet('nCdFormato',1);
|
| 393 |
+
$client->setParameterGet('nVlComprimento',$this->getConfigData('comprimento_sent'));
|
| 394 |
+
$client->setParameterGet('nVlAltura',$this->getConfigData('altura_sent'));
|
| 395 |
+
$client->setParameterGet('nVlLargura',$this->getConfigData('largura_sent'));
|
| 396 |
+
|
| 397 |
+
if($this->getConfigData('mao_propria')){
|
| 398 |
+
$client->setParameterGet('sCdMaoPropria','S');
|
| 399 |
+
}else{
|
| 400 |
+
$client->setParameterGet('sCdMaoPropria','N');
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
if($this->getConfigData('aviso_recebimento')){
|
| 404 |
+
$client->setParameterGet('sCdAvisoRecebimento','S');
|
| 405 |
+
}else{
|
| 406 |
+
$client->setParameterGet('sCdAvisoRecebimento','N');
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
if($this->getConfigData('valor_declarado') || in_array($this->getConfigData('acobrar_code'), $this->_postMethodsExplode)){
|
| 410 |
+
$client->setParameterGet('nVlValorDeclarado',number_format($this->_packageValue, 2, ',', '.'));
|
| 411 |
+
}else{
|
| 412 |
+
$client->setParameterGet('nVlValorDeclarado',0);
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
$contrato = false;
|
| 416 |
+
foreach($contratoCodes as $contratoEach){
|
| 417 |
+
if(in_array($contratoEach, $this->_postMethodsExplode)){
|
| 418 |
+
$contrato = true;
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
|
| 422 |
+
if($contrato){
|
| 423 |
+
if($this->getConfigData('cod_admin') == '' || $this->getConfigData('senha_admin') == ''){
|
| 424 |
+
// Need correios admin data
|
| 425 |
+
$this->_throwError('coderror', 'Need correios admin data', __LINE__);
|
| 426 |
+
return false;
|
| 427 |
+
}else{
|
| 428 |
+
$client->setParameterGet('nCdEmpresa',$this->getConfigData('cod_admin'));
|
| 429 |
+
$client->setParameterGet('sDsSenha',$this->getConfigData('senha_admin'));
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
|
| 433 |
+
$content = $client->request();
|
| 434 |
+
$conteudo = $content->getBody();
|
| 435 |
|
| 436 |
+
if ($conteudo == ""){
|
| 437 |
+
throw new Exception("No XML returned [" . __LINE__ . "]");
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
libxml_use_internal_errors(true);
|
| 441 |
+
$sxe = simplexml_load_string($conteudo);
|
| 442 |
+
if (!$sxe) {
|
| 443 |
+
throw new Exception("Bad XML [" . __LINE__ . "]");
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
// Load XML
|
| 447 |
+
$xml = new SimpleXMLElement($conteudo);
|
| 448 |
+
|
| 449 |
+
if(count($xml->cServico) <= 0){
|
| 450 |
+
throw new Exception("No tag cServico in Correios XML [" . __LINE__ . "]");
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
return $xml->cServico;
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
} catch (Exception $e) {
|
| 457 |
+
//URL Error
|
| 458 |
+
$this->_throwError('urlerror', 'URL Error - ' . $e->getMessage(), __LINE__);
|
| 459 |
+
return false;
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
/**
|
| 466 |
+
* Apend shipping value to return
|
| 467 |
+
*
|
| 468 |
+
* @param $shipping_method string
|
| 469 |
+
* @param $shippingPrice float
|
| 470 |
+
* @param $correiosReturn array
|
| 471 |
+
*/
|
| 472 |
+
protected function _apendShippingReturn($shipping_method, $shippingPrice = 0, $correiosDelivery = 0){
|
| 473 |
+
|
| 474 |
+
$method = Mage::getModel('shipping/rate_result_method');
|
| 475 |
+
$method->setCarrier($this->_code);
|
| 476 |
+
$method->setCarrierTitle($this->getConfigData('title'));
|
| 477 |
+
$method->setMethod($shipping_method);
|
| 478 |
+
|
| 479 |
+
$shippingCost = $shippingPrice;
|
| 480 |
+
$shippingPrice = $shippingPrice + $this->getConfigData('handling_fee');
|
| 481 |
+
|
| 482 |
+
$shipping_data = explode(',', $this->getConfigData('serv_' . $shipping_method));
|
| 483 |
+
|
| 484 |
+
if($shipping_method == $this->getConfigData('acobrar_code')){
|
| 485 |
+
$shipping_data[0] = $shipping_data[0] . ' ( R$' . number_format($shippingPrice, 2, ',', '.') . ' )';
|
| 486 |
+
$shippingPrice = 0;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
// Show delivery days
|
| 491 |
+
if ($this->getConfigFlag('prazo_entrega')){
|
| 492 |
+
|
| 493 |
+
// Delivery days from WS
|
| 494 |
+
if($correiosDelivery > 0){
|
| 495 |
+
$method->setMethodTitle(sprintf($this->getConfigData('msgprazo'), $shipping_data[0], (int)($correiosDelivery + $this->getConfigData('add_prazo'))));
|
| 496 |
+
}else{
|
| 497 |
+
$method->setMethodTitle(sprintf($this->getConfigData('msgprazo'), $shipping_data[0], (int)($shipping_data[1] + $this->getConfigData('add_prazo'))));
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
}else{
|
| 502 |
+
$method->setMethodTitle($shipping_data[0]);
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
$method->setPrice($shippingPrice);
|
| 506 |
+
$method->setCost($shippingCost);
|
| 507 |
+
|
| 508 |
+
if($this->_freeMethodRequest === true){
|
| 509 |
+
$this->_freeMethodRequestResult->append($method);
|
| 510 |
+
}else{
|
| 511 |
+
$this->_result->append($method);
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
/**
|
| 516 |
+
* Throw error
|
| 517 |
+
*
|
| 518 |
+
* @param $message string
|
| 519 |
+
* @param $log string
|
| 520 |
+
* @param $line int
|
| 521 |
+
* @param $custom string
|
| 522 |
+
*/
|
| 523 |
+
protected function _throwError($message, $log = null, $line = 'NO LINE', $custom = null){
|
| 524 |
+
|
| 525 |
+
$this->_result = null;
|
| 526 |
+
$this->_result = Mage::getModel('shipping/rate_result');
|
| 527 |
+
|
| 528 |
+
// Get error model
|
| 529 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
| 530 |
+
$error->setCarrier($this->_code);
|
| 531 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
| 532 |
+
|
| 533 |
+
if(is_null($custom)){
|
| 534 |
+
//Log error
|
| 535 |
+
Mage::log($this->_code . ' [' . $line . ']: ' . $log);
|
| 536 |
+
$error->setErrorMessage($this->getConfigData($message));
|
| 537 |
+
}else{
|
| 538 |
+
//Log error
|
| 539 |
+
Mage::log($this->_code . ' [' . $line . ']: ' . $log);
|
| 540 |
+
$error->setErrorMessage(sprintf($this->getConfigData($message), $custom));
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// Apend error
|
| 544 |
+
$this->_result->append($error);
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
/**
|
| 548 |
+
* Generate PAC weight
|
| 549 |
+
*/
|
| 550 |
+
protected function _generatePacWeight(){
|
| 551 |
+
//Create PAC weight
|
| 552 |
+
$pesoCubicoTotal = 0;
|
| 553 |
+
|
| 554 |
+
// Get all visible itens from quote
|
| 555 |
+
$items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
|
| 556 |
+
|
| 557 |
+
foreach($items as $item){
|
| 558 |
+
|
| 559 |
+
$while = 0;
|
| 560 |
+
$itemAltura= 0;
|
| 561 |
+
$itemLargura = 0;
|
| 562 |
+
$itemComprimento = 0;
|
| 563 |
+
|
| 564 |
+
$_product = $item->getProduct();
|
| 565 |
+
|
| 566 |
+
if($_product->getData('volume_altura') == '' || (int)$_product->getData('volume_altura') == 0)
|
| 567 |
+
$itemAltura = $this->getConfigData('altura_padrao');
|
| 568 |
+
else
|
| 569 |
+
$itemAltura = $_product->getData('volume_altura');
|
| 570 |
+
|
| 571 |
+
if($_product->getData('volume_largura') == '' || (int)$_product->getData('volume_largura') == 0)
|
| 572 |
+
$itemLargura = $this->getConfigData('largura_padrao');
|
| 573 |
+
else
|
| 574 |
+
$itemLargura = $_product->getData('volume_largura');
|
| 575 |
+
|
| 576 |
+
if($_product->getData('volume_comprimento') == '' || (int)$_product->getData('volume_comprimento') == 0)
|
| 577 |
+
$itemComprimento = $this->getConfigData('comprimento_padrao');
|
| 578 |
+
else
|
| 579 |
+
$itemComprimento = $_product->getData('volume_comprimento');
|
| 580 |
+
|
| 581 |
+
while($while < $item->getQty()){
|
| 582 |
+
$itemPesoCubico = 0;
|
| 583 |
+
$itemPesoCubico = ($itemAltura * $itemLargura * $itemComprimento)/4800;
|
| 584 |
+
$pesoCubicoTotal = $pesoCubicoTotal + $itemPesoCubico;
|
| 585 |
+
$while ++;
|
| 586 |
+
}
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
$this->_pacWeight = number_format($pesoCubicoTotal, 2, '.', '');
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
/**
|
| 593 |
+
* Generate free shipping for a product
|
| 594 |
+
*
|
| 595 |
+
* @param string $freeMethod
|
| 596 |
+
*/
|
| 597 |
+
protected function _setFreeMethodRequest($freeMethod)
|
| 598 |
+
{
|
| 599 |
+
// Set request as free method request
|
| 600 |
+
$this->_freeMethodRequest = true;
|
| 601 |
+
$this->_freeMethodRequestResult = Mage::getModel('shipping/rate_result');
|
| 602 |
+
|
| 603 |
+
$this->_postMethods = $freeMethod;
|
| 604 |
+
$this->_postMethodsExplode = array($freeMethod);
|
| 605 |
+
|
| 606 |
+
// Tranform free shipping weight
|
| 607 |
+
if($this->getConfigData('weight_type') == 'gr')
|
| 608 |
+
{
|
| 609 |
+
$this->_freeMethodWeight = number_format($this->_freeMethodWeight/1000, 2, '.', '');
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
$this->_packageWeight = $this->_freeMethodWeight;
|
| 613 |
+
$this->_pacWeight = $this->_freeMethodWeight;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
/**
|
| 617 |
+
* Clean correios error code, usualy with "-" before the code
|
| 618 |
+
*
|
| 619 |
+
* @param string $error
|
| 620 |
+
* @return int
|
| 621 |
+
*/
|
| 622 |
+
protected function _cleanCorreiosError($error){
|
| 623 |
+
$error = str_replace('-', '', $error);
|
| 624 |
+
$error = (int)$error;
|
| 625 |
+
return $error;
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
/**
|
| 630 |
+
* Check if current carrier offer support to tracking
|
| 631 |
+
*
|
| 632 |
+
* @return boolean true
|
| 633 |
+
*/
|
| 634 |
+
public function isTrackingAvailable() {
|
| 635 |
+
return true;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
/**
|
| 639 |
+
* Get Tracking Info
|
| 640 |
+
*
|
| 641 |
+
* @param mixed $tracking
|
| 642 |
+
* @return mixed
|
| 643 |
+
*/
|
| 644 |
+
public function getTrackingInfo($tracking) {
|
| 645 |
+
$result = $this->getTracking($tracking);
|
| 646 |
+
if ($result instanceof Mage_Shipping_Model_Tracking_Result){
|
| 647 |
+
if ($trackings = $result->getAllTrackings()) {
|
| 648 |
+
return $trackings[0];
|
| 649 |
+
}
|
| 650 |
+
} elseif (is_string($result) && !empty($result)) {
|
| 651 |
+
return $result;
|
| 652 |
+
}
|
| 653 |
+
return false;
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
/**
|
| 657 |
+
* Get Tracking
|
| 658 |
+
*
|
| 659 |
+
* @param array $trackings
|
| 660 |
+
* @return Mage_Shipping_Model_Tracking_Result
|
| 661 |
+
*/
|
| 662 |
+
public function getTracking($trackings) {
|
| 663 |
+
$this->_result = Mage::getModel('shipping/tracking_result');
|
| 664 |
+
foreach ((array) $trackings as $code) {
|
| 665 |
+
$this->_getTracking($code);
|
| 666 |
+
}
|
| 667 |
+
return $this->_result;
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
/**
|
| 671 |
+
* Protected Get Tracking, opens the request to Correios
|
| 672 |
+
*
|
| 673 |
+
* @param string $code
|
| 674 |
+
* @return boolean
|
| 675 |
+
*/
|
| 676 |
+
protected function _getTracking($code) {
|
| 677 |
+
$error = Mage::getModel('shipping/tracking_result_error');
|
| 678 |
+
$error->setTracking($code);
|
| 679 |
+
$error->setCarrier($this->_code);
|
| 680 |
+
$error->setCarrierTitle($this->getConfigData('title'));
|
| 681 |
+
$error->setErrorMessage($this->getConfigData('urlerror'));
|
| 682 |
+
|
| 683 |
+
$url = 'http://websro.correios.com.br/sro_bin/txect01$.QueryList';
|
| 684 |
+
$url .= '?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' . $code;
|
| 685 |
+
try {
|
| 686 |
+
$client = new Zend_Http_Client();
|
| 687 |
+
$client->setUri($url);
|
| 688 |
+
$content = $client->request();
|
| 689 |
+
$body = $content->getBody();
|
| 690 |
+
} catch (Exception $e) {
|
| 691 |
+
$this->_result->append($error);
|
| 692 |
+
return false;
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
if (!preg_match('#<table ([^>]+)>(.*?)</table>#is', $body, $matches)) {
|
| 696 |
+
$this->_result->append($error);
|
| 697 |
+
return false;
|
| 698 |
+
}
|
| 699 |
+
$table = $matches[2];
|
| 700 |
+
|
| 701 |
+
if (!preg_match_all('/<tr>(.*)<\/tr>/i', $table, $columns, PREG_SET_ORDER)) {
|
| 702 |
+
$this->_result->append($error);
|
| 703 |
+
return false;
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
$progress = array();
|
| 707 |
+
for ($i = 0; $i < count($columns); $i++) {
|
| 708 |
+
$column = $columns[$i][1];
|
| 709 |
+
|
| 710 |
+
$description = '';
|
| 711 |
+
$found = false;
|
| 712 |
+
if (preg_match('/<td rowspan="?2"?/i', $column) && preg_match('/<td rowspan="?2"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i', $column, $matches)) {
|
| 713 |
+
if (preg_match('/<td colspan="?2"?>(.*)<\/td>/i', $columns[$i+1][1], $matchesDescription)) {
|
| 714 |
+
$description = str_replace(' ', '', $matchesDescription[1]);
|
| 715 |
+
}
|
| 716 |
|
| 717 |
+
$found = true;
|
| 718 |
+
} elseif (preg_match('/<td rowspan="?1"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i', $column, $matches)) {
|
| 719 |
+
$found = true;
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
if ($found) {
|
| 723 |
+
$datetime = explode(' ', $matches[1]);
|
| 724 |
+
$locale = new Zend_Locale('pt_BR');
|
| 725 |
+
$date='';
|
| 726 |
+
$date = new Zend_Date($datetime[0], 'dd/MM/YYYY', $locale);
|
| 727 |
+
|
| 728 |
+
$track = array(
|
| 729 |
+
'deliverydate' => $date->toString('YYYY-MM-dd'),
|
| 730 |
+
'deliverytime' => $datetime[1] . ':00',
|
| 731 |
+
'deliverylocation' => htmlentities($matches[2]),
|
| 732 |
+
'status' => htmlentities($matches[3]),
|
| 733 |
+
'activity' => htmlentities($matches[3])
|
| 734 |
+
);
|
| 735 |
|
| 736 |
+
if ($description !== '') {
|
| 737 |
+
$track['activity'] = $matches[3] . ' - ' . htmlentities($description);
|
| 738 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
|
| 740 |
+
$progress[] = $track;
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
if (!empty($progress)) {
|
| 745 |
+
$track = $progress[0];
|
| 746 |
+
$track['progressdetail'] = $progress;
|
| 747 |
+
|
| 748 |
+
$tracking = Mage::getModel('shipping/tracking_result_status');
|
| 749 |
+
$tracking->setTracking($code);
|
| 750 |
+
$tracking->setCarrier('correios');
|
| 751 |
+
$tracking->setCarrierTitle($this->getConfigData('title'));
|
| 752 |
+
$tracking->addData($track);
|
| 753 |
+
|
| 754 |
+
$this->_result->append($tracking);
|
| 755 |
+
return true;
|
| 756 |
+
} else {
|
| 757 |
+
$this->_result->append($error);
|
| 758 |
+
return false;
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
/**
|
| 763 |
+
* Returns the allowed carrier methods
|
| 764 |
+
*
|
| 765 |
+
* @return array
|
| 766 |
+
*/
|
| 767 |
+
public function getAllowedMethods()
|
| 768 |
+
{
|
| 769 |
+
return array($this->_code => $this->getConfigData('title'));
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
/**
|
| 773 |
+
* Define ZIP Code as required
|
| 774 |
+
*
|
| 775 |
+
* @return boolean
|
| 776 |
+
*/
|
| 777 |
+
public function isZipCodeRequired()
|
| 778 |
+
{
|
| 779 |
+
return true;
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
}
|
app/code/community/PedroTeixeira/Correios/Model/Source/FreeMethods.php
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Pedro Teixeira
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the Open Software License (OSL).
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://opensource.org/licenses/osl-3.0.php
|
| 10 |
-
*
|
| 11 |
-
* @category PedroTeixeira
|
| 12 |
-
* @package PedroTeixeira_Correios
|
| 13 |
-
* @copyright Copyright (c) 2010 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 14 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 15 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 16 |
-
*/
|
| 17 |
-
|
| 18 |
-
class PedroTeixeira_Correios_Model_Source_FreeMethods
|
| 19 |
-
{
|
| 20 |
-
|
| 21 |
-
public function toOptionArray()
|
| 22 |
-
{
|
| 23 |
-
return array(
|
| 24 |
-
array('value'=>40010, 'label'=>Mage::helper('adminhtml')->__('Sedex Sem Contrato (Correios)')),
|
| 25 |
-
array('value'=>40096, 'label'=>Mage::helper('adminhtml')->__('Sedex Com Contrato (Correios/Locaweb)')),
|
| 26 |
-
array('value'=>81019, 'label'=>Mage::helper('adminhtml')->__('E-Sedex Com Contrato (Correios/Locaweb)')),
|
| 27 |
-
array('value'=>41025, 'label'=>Mage::helper('adminhtml')->__('PAC Normal (Locaweb)')),
|
| 28 |
-
array('value'=>41106, 'label'=>Mage::helper('adminhtml')->__('PAC Sem Contrato (Correios)')),
|
| 29 |
-
array('value'=>41068, 'label'=>Mage::helper('adminhtml')->__('PAC Com Contrato (Correios/Locaweb)')),
|
| 30 |
-
array('value'=>40215, 'label'=>Mage::helper('adminhtml')->__('Sedex 10 (Correios)')),
|
| 31 |
-
array('value'=>40290, 'label'=>Mage::helper('adminhtml')->__('Sedex HOJE (Correios)')),
|
| 32 |
-
array('value'=>40045, 'label'=>Mage::helper('adminhtml')->__('Sedex a Cobrar (Correios)')),
|
| 33 |
-
);
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/PedroTeixeira/Correios/Model/Source/PostMethods.php
CHANGED
|
@@ -21,15 +21,15 @@ class PedroTeixeira_Correios_Model_Source_PostMethods
|
|
| 21 |
public function toOptionArray()
|
| 22 |
{
|
| 23 |
return array(
|
| 24 |
-
array('value'=>
|
| 25 |
-
array('value'=>
|
| 26 |
-
array('value'=>
|
| 27 |
-
array('value'=>
|
| 28 |
-
array('value'=>
|
| 29 |
-
array('value'=>
|
| 30 |
-
array('value'=>
|
| 31 |
-
array('value'=>
|
| 32 |
-
array('value'=>
|
| 33 |
);
|
| 34 |
}
|
| 35 |
|
| 21 |
public function toOptionArray()
|
| 22 |
{
|
| 23 |
return array(
|
| 24 |
+
array('value'=>40010, 'label'=>Mage::helper('adminhtml')->__('Sedex Sem Contrato (Correios)')),
|
| 25 |
+
array('value'=>40096, 'label'=>Mage::helper('adminhtml')->__('Sedex Com Contrato (Correios/Locaweb)')),
|
| 26 |
+
array('value'=>81019, 'label'=>Mage::helper('adminhtml')->__('E-Sedex Com Contrato (Correios/Locaweb)')),
|
| 27 |
+
array('value'=>41025, 'label'=>Mage::helper('adminhtml')->__('PAC Normal (Locaweb)')),
|
| 28 |
+
array('value'=>41106, 'label'=>Mage::helper('adminhtml')->__('PAC Sem Contrato (Correios)')),
|
| 29 |
+
array('value'=>41068, 'label'=>Mage::helper('adminhtml')->__('PAC Com Contrato (Correios/Locaweb)')),
|
| 30 |
+
array('value'=>40215, 'label'=>Mage::helper('adminhtml')->__('Sedex 10 (Correios)')),
|
| 31 |
+
array('value'=>40290, 'label'=>Mage::helper('adminhtml')->__('Sedex HOJE (Correios)')),
|
| 32 |
+
array('value'=>40045, 'label'=>Mage::helper('adminhtml')->__('Sedex a Cobrar (Correios)')),
|
| 33 |
);
|
| 34 |
}
|
| 35 |
|
app/code/community/PedroTeixeira/Correios/etc/config.xml
CHANGED
|
@@ -19,7 +19,7 @@
|
|
| 19 |
<config>
|
| 20 |
<modules>
|
| 21 |
<PedroTeixeira_Correios>
|
| 22 |
-
<version>4.
|
| 23 |
<depends>
|
| 24 |
<Mage_Shipping />
|
| 25 |
</depends>
|
|
@@ -39,7 +39,7 @@
|
|
| 39 |
</sales>
|
| 40 |
<models>
|
| 41 |
<pedroteixeira_correios>
|
| 42 |
-
|
| 43 |
</pedroteixeira_correios>
|
| 44 |
</models>
|
| 45 |
<resources>
|
|
@@ -54,7 +54,7 @@
|
|
| 54 |
</resources>
|
| 55 |
<helpers>
|
| 56 |
<pedroteixeira_correios>
|
| 57 |
-
|
| 58 |
</pedroteixeira_correios>
|
| 59 |
</helpers>
|
| 60 |
<sales>
|
|
@@ -71,35 +71,67 @@
|
|
| 71 |
<default>
|
| 72 |
<carriers>
|
| 73 |
<pedroteixeira_correios>
|
|
|
|
| 74 |
<active>1</active>
|
| 75 |
<model>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</model>
|
| 76 |
<title>Correios</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
<mao_propria>0</mao_propria>
|
| 78 |
<aviso_recebimento>0</aviso_recebimento>
|
| 79 |
<valor_declarado>0</valor_declarado>
|
| 80 |
-
|
|
|
|
| 81 |
<altura_padrao>2</altura_padrao>
|
| 82 |
<comprimento_padrao>16</comprimento_padrao>
|
| 83 |
<largura_padrao>11</largura_padrao>
|
| 84 |
-
<
|
| 85 |
-
<
|
| 86 |
-
<
|
| 87 |
-
|
|
|
|
| 88 |
<urlmethod>0</urlmethod>
|
|
|
|
| 89 |
<weight_type>kg</weight_type>
|
| 90 |
-
<maxweight>30</maxweight>
|
| 91 |
-
<handling_fee>0</handling_fee>
|
| 92 |
<add_prazo>0</add_prazo>
|
|
|
|
|
|
|
|
|
|
| 93 |
<msgprazo>%s - Em média %d dia(s)</msgprazo>
|
| 94 |
-
<
|
| 95 |
-
<
|
| 96 |
-
<valueerror>Valor de compra a cima do permitido pelos Correios. Por favor entre em contato conosco.</valueerror>
|
| 97 |
<zipcodeerror>Por favor, corrija o CEP digitado, ele não está correto.</zipcodeerror>
|
| 98 |
-
<maxweighterror>Peso dos produtos
|
| 99 |
<weightzeroerror>Lojista: O peso do produto deverá ser maior que zero. Se você está usando a media de peso como gramas, o peso mínimo é de 10 gramas.</weightzeroerror>
|
| 100 |
-
<urlerror>Esse método de envio está fora do ar. Por favor entre em contato conosco.</urlerror>
|
| 101 |
<coderror>Lojista: Para calcular esse serviço você precisa ter contrato com os Correios.</coderror>
|
| 102 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
</pedroteixeira_correios>
|
| 104 |
</carriers>
|
| 105 |
</default>
|
| 19 |
<config>
|
| 20 |
<modules>
|
| 21 |
<PedroTeixeira_Correios>
|
| 22 |
+
<version>4.1.0</version>
|
| 23 |
<depends>
|
| 24 |
<Mage_Shipping />
|
| 25 |
</depends>
|
| 39 |
</sales>
|
| 40 |
<models>
|
| 41 |
<pedroteixeira_correios>
|
| 42 |
+
<class>PedroTeixeira_Correios_Model</class>
|
| 43 |
</pedroteixeira_correios>
|
| 44 |
</models>
|
| 45 |
<resources>
|
| 54 |
</resources>
|
| 55 |
<helpers>
|
| 56 |
<pedroteixeira_correios>
|
| 57 |
+
<class>PedroTeixeira_Correios_Helper</class>
|
| 58 |
</pedroteixeira_correios>
|
| 59 |
</helpers>
|
| 60 |
<sales>
|
| 71 |
<default>
|
| 72 |
<carriers>
|
| 73 |
<pedroteixeira_correios>
|
| 74 |
+
<!-- GENERAL -->
|
| 75 |
<active>1</active>
|
| 76 |
<model>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</model>
|
| 77 |
<title>Correios</title>
|
| 78 |
+
<postmethods>40010</postmethods>
|
| 79 |
+
<die_errors>1,2,3,4,5,33,34,35,36,37,38,888,7,99</die_errors>
|
| 80 |
+
<prazo_entrega>0</prazo_entrega>
|
| 81 |
+
<min_order_value>0</min_order_value>
|
| 82 |
+
<max_order_value>10000</max_order_value>
|
| 83 |
+
<maxweight>30</maxweight>
|
| 84 |
+
<handling_fee>0</handling_fee>
|
| 85 |
+
<ws_timeout>30</ws_timeout>
|
| 86 |
+
|
| 87 |
+
<!-- OPTIONS -->
|
| 88 |
<mao_propria>0</mao_propria>
|
| 89 |
<aviso_recebimento>0</aviso_recebimento>
|
| 90 |
<valor_declarado>0</valor_declarado>
|
| 91 |
+
|
| 92 |
+
<!-- PAC -->
|
| 93 |
<altura_padrao>2</altura_padrao>
|
| 94 |
<comprimento_padrao>16</comprimento_padrao>
|
| 95 |
<largura_padrao>11</largura_padrao>
|
| 96 |
+
<altura_sent>2</altura_sent>
|
| 97 |
+
<comprimento_sent>16</comprimento_sent>
|
| 98 |
+
<largura_sent>11</largura_sent>
|
| 99 |
+
|
| 100 |
+
<!-- CONFIG -->
|
| 101 |
<urlmethod>0</urlmethod>
|
| 102 |
+
<free_method>40010</free_method>
|
| 103 |
<weight_type>kg</weight_type>
|
|
|
|
|
|
|
| 104 |
<add_prazo>0</add_prazo>
|
| 105 |
+
<showmethod>1</showmethod>
|
| 106 |
+
|
| 107 |
+
<!-- MESSAGES -->
|
| 108 |
<msgprazo>%s - Em média %d dia(s)</msgprazo>
|
| 109 |
+
<correioserror>Houve um erro inesperado, por favor entre em contato. %s</correioserror>
|
| 110 |
+
<valueerror>Valor de compra fora do permitido pelos Correios. Por favor entre em contato conosco.</valueerror>
|
|
|
|
| 111 |
<zipcodeerror>Por favor, corrija o CEP digitado, ele não está correto.</zipcodeerror>
|
| 112 |
+
<maxweighterror>Peso dos produtos acima do permitido pelos Correios. Por favor entre em contato conosco.</maxweighterror>
|
| 113 |
<weightzeroerror>Lojista: O peso do produto deverá ser maior que zero. Se você está usando a media de peso como gramas, o peso mínimo é de 10 gramas.</weightzeroerror>
|
|
|
|
| 114 |
<coderror>Lojista: Para calcular esse serviço você precisa ter contrato com os Correios.</coderror>
|
| 115 |
+
<urlerror>Esse método de envio está fora do ar. Por favor entre em contato conosco.</urlerror>
|
| 116 |
+
|
| 117 |
+
<!-- SYSTEM -->
|
| 118 |
+
<serv_40010>Sedex,3</serv_40010>
|
| 119 |
+
<serv_40096>Sedex,3</serv_40096>
|
| 120 |
+
<serv_81019>E-Sedex,3</serv_81019>
|
| 121 |
+
<serv_41025>PAC,3</serv_41025>
|
| 122 |
+
<serv_41106>PAC,3</serv_41106>
|
| 123 |
+
<serv_41068>PAC,3</serv_41068>
|
| 124 |
+
<serv_40215>Sedex 10,1</serv_40215>
|
| 125 |
+
<serv_40290>Sedex HOJE,1</serv_40290>
|
| 126 |
+
<serv_40045>Sedex a Cobrar,5</serv_40045>
|
| 127 |
+
|
| 128 |
+
<pac_codes>41025,41106,41068</pac_codes>
|
| 129 |
+
<acobrar_code>40045</acobrar_code>
|
| 130 |
+
<contrato_codes>40096,81019,41068</contrato_codes>
|
| 131 |
+
|
| 132 |
+
<url_ws_correios>http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx</url_ws_correios>
|
| 133 |
+
<url_ws_locaweb>http://comercio.locaweb.com.br/correios/frete.asmx?WSDL</url_ws_locaweb>
|
| 134 |
+
|
| 135 |
</pedroteixeira_correios>
|
| 136 |
</carriers>
|
| 137 |
</default>
|
app/code/community/PedroTeixeira/Correios/etc/system.xml
CHANGED
|
@@ -33,13 +33,14 @@
|
|
| 33 |
<br />
|
| 34 |
<strong style="font-size:14px">Informações Importantes</strong><br /><br />
|
| 35 |
Você pode tirar dúvidas ou sugerir melhorias do módulo através do site <a href="http://www.pteixeira.com.br/" target="_blank">www.pteixeira.com.br</a>.<br /><br />
|
| 36 |
-
Na versão 4.
|
| 37 |
-
correção do problema de getBody(), correção do problema de ereg(), nova forma de passar o volume para cálculo do PAC, log de erros e outras funcionalidades.<br /><br />
|
| 38 |
Para um bom funcionamento do módulo, é necessário que você configure os serviços que deseja disponibilizar em sua loja e escolher a fonte de cálculo de acordo com os serviços habilitados.
|
| 39 |
-
Por exemplo, se você habilitar "Sedex Com Contrato (Correios)" lembre-se de configurar a fonte de cálculo como Correios, já se habilitar "PAC Normal (Locaweb)"
|
|
|
|
| 40 |
Lembre-se de configurar as "Definições de Envio" no menu ao lado esquerdo.<br /><br />
|
| 41 |
Para serviços que tenham em seu nome "Com Contrato", é necessário configurar o "Código Administrativo dos Correios" e "Senha Administrativa dos Correios".<br /><br />
|
| 42 |
A lista completa de códigos de erros está disponibilizada no site do desenvolvedor.<br /><br />
|
|
|
|
| 43 |
<b>Importante:</b> Para utilização da função de tracking é necessário corrigir alguns erros do próprio Magento, veja mais informações no site do desenvolvedor.
|
| 44 |
<br /><br /><hr /><br /><br />
|
| 45 |
</div>
|
|
@@ -73,6 +74,17 @@
|
|
| 73 |
<show_in_store>1</show_in_store>
|
| 74 |
<comment>Serviços que estarão disponíveis, lembre-se de usar os serviços correspondentes a fonte configurada.</comment>
|
| 75 |
</postmethods>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
<urlmethod translate="label">
|
| 77 |
<label>Fonte de Cálculo</label>
|
| 78 |
<frontend_type>select</frontend_type>
|
|
@@ -146,15 +158,6 @@
|
|
| 146 |
<show_in_website>1</show_in_website>
|
| 147 |
<show_in_store>1</show_in_store>
|
| 148 |
</valor_declarado>
|
| 149 |
-
<ignorar_erro translate="label">
|
| 150 |
-
<label>Ignorar os seguintes erros dos Correios</label>
|
| 151 |
-
<frontend_type>text</frontend_type>
|
| 152 |
-
<sort_order>66</sort_order>
|
| 153 |
-
<show_in_default>1</show_in_default>
|
| 154 |
-
<show_in_website>1</show_in_website>
|
| 155 |
-
<show_in_store>1</show_in_store>
|
| 156 |
-
<comment>Códigos separados por vírgula.</comment>
|
| 157 |
-
</ignorar_erro>
|
| 158 |
<altura_padrao translate="label">
|
| 159 |
<label>Altura Padrão (cm)</label>
|
| 160 |
<frontend_type>text</frontend_type>
|
|
@@ -240,18 +243,7 @@
|
|
| 240 |
<show_in_default>1</show_in_default>
|
| 241 |
<show_in_website>1</show_in_website>
|
| 242 |
<show_in_store>1</show_in_store>
|
| 243 |
-
</msgprazo>
|
| 244 |
-
<free_method translate="label">
|
| 245 |
-
<label>Serviço para entrega gratuita</label>
|
| 246 |
-
<frontend_type>select</frontend_type>
|
| 247 |
-
<frontend_class>free-method</frontend_class>
|
| 248 |
-
<source_model>PedroTeixeira_Correios_Model_Source_FreeMethods</source_model>
|
| 249 |
-
<sort_order>150</sort_order>
|
| 250 |
-
<show_in_default>1</show_in_default>
|
| 251 |
-
<show_in_website>1</show_in_website>
|
| 252 |
-
<show_in_store>1</show_in_store>
|
| 253 |
-
<comment>Quando usar um cupom oferecendo frete gratuito, qual serviço será gratuito. Lembre-se de habilitar o serviço.</comment>
|
| 254 |
-
</free_method>
|
| 255 |
<valueerror translate="label">
|
| 256 |
<label>Mensagem de valor fora do permitido</label>
|
| 257 |
<frontend_type>textarea</frontend_type>
|
|
@@ -299,7 +291,17 @@
|
|
| 299 |
<show_in_default>1</show_in_default>
|
| 300 |
<show_in_website>1</show_in_website>
|
| 301 |
<show_in_store>1</show_in_store>
|
| 302 |
-
</coderror>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
<sort_order translate="label">
|
| 304 |
<label>Ordenar por</label>
|
| 305 |
<frontend_type>text</frontend_type>
|
| 33 |
<br />
|
| 34 |
<strong style="font-size:14px">Informações Importantes</strong><br /><br />
|
| 35 |
Você pode tirar dúvidas ou sugerir melhorias do módulo através do site <a href="http://www.pteixeira.com.br/" target="_blank">www.pteixeira.com.br</a>.<br /><br />
|
| 36 |
+
Na versão <b>4.1.0</b> o módulo de cálculo de frete conta com chamada única ao WebService dos Correios para cálculo de todos os serviços, novos filtros para evitar erros no frontend, nomes dos serviços e prazos de entrega configuráveis por xml, integração total com as regras de desconto, novos logs de erros mais completos, desconsiderando duplicidade de produtos configuráveis dentre várias outras modificações.<br /><br />
|
|
|
|
| 37 |
Para um bom funcionamento do módulo, é necessário que você configure os serviços que deseja disponibilizar em sua loja e escolher a fonte de cálculo de acordo com os serviços habilitados.
|
| 38 |
+
Por exemplo, se você habilitar "Sedex Com Contrato (Correios)" lembre-se de configurar a fonte de cálculo como Correios, já se habilitar "PAC Normal (Locaweb)"
|
| 39 |
+
lembre-se de configurar a fonte como "Locaweb".<br /><br />
|
| 40 |
Lembre-se de configurar as "Definições de Envio" no menu ao lado esquerdo.<br /><br />
|
| 41 |
Para serviços que tenham em seu nome "Com Contrato", é necessário configurar o "Código Administrativo dos Correios" e "Senha Administrativa dos Correios".<br /><br />
|
| 42 |
A lista completa de códigos de erros está disponibilizada no site do desenvolvedor.<br /><br />
|
| 43 |
+
Para utilizar as regras de desconto de frete, você deve configurar o "Serviço para entrega gratuita", lembre-se de habilitar o serviço.<br /><br />
|
| 44 |
<b>Importante:</b> Para utilização da função de tracking é necessário corrigir alguns erros do próprio Magento, veja mais informações no site do desenvolvedor.
|
| 45 |
<br /><br /><hr /><br /><br />
|
| 46 |
</div>
|
| 74 |
<show_in_store>1</show_in_store>
|
| 75 |
<comment>Serviços que estarão disponíveis, lembre-se de usar os serviços correspondentes a fonte configurada.</comment>
|
| 76 |
</postmethods>
|
| 77 |
+
<free_method translate="label">
|
| 78 |
+
<label>Serviço para entrega gratuita</label>
|
| 79 |
+
<frontend_type>select</frontend_type>
|
| 80 |
+
<frontend_class>free-method</frontend_class>
|
| 81 |
+
<source_model>PedroTeixeira_Correios_Model_Source_PostMethods</source_model>
|
| 82 |
+
<sort_order>21</sort_order>
|
| 83 |
+
<show_in_default>1</show_in_default>
|
| 84 |
+
<show_in_website>1</show_in_website>
|
| 85 |
+
<show_in_store>1</show_in_store>
|
| 86 |
+
<comment>Quando usar um cupom oferecendo frete gratuito, qual serviço será gratuito. Lembre-se de habilitar o serviço.</comment>
|
| 87 |
+
</free_method>
|
| 88 |
<urlmethod translate="label">
|
| 89 |
<label>Fonte de Cálculo</label>
|
| 90 |
<frontend_type>select</frontend_type>
|
| 158 |
<show_in_website>1</show_in_website>
|
| 159 |
<show_in_store>1</show_in_store>
|
| 160 |
</valor_declarado>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
<altura_padrao translate="label">
|
| 162 |
<label>Altura Padrão (cm)</label>
|
| 163 |
<frontend_type>text</frontend_type>
|
| 243 |
<show_in_default>1</show_in_default>
|
| 244 |
<show_in_website>1</show_in_website>
|
| 245 |
<show_in_store>1</show_in_store>
|
| 246 |
+
</msgprazo>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
<valueerror translate="label">
|
| 248 |
<label>Mensagem de valor fora do permitido</label>
|
| 249 |
<frontend_type>textarea</frontend_type>
|
| 291 |
<show_in_default>1</show_in_default>
|
| 292 |
<show_in_website>1</show_in_website>
|
| 293 |
<show_in_store>1</show_in_store>
|
| 294 |
+
</coderror>
|
| 295 |
+
<showmethod translate="label">
|
| 296 |
+
<label>Mostrar método mesmo se não aplicável</label>
|
| 297 |
+
<frontend_type>select</frontend_type>
|
| 298 |
+
<sort_order>200</sort_order>
|
| 299 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 300 |
+
<show_in_default>1</show_in_default>
|
| 301 |
+
<show_in_website>1</show_in_website>
|
| 302 |
+
<show_in_store>1</show_in_store>
|
| 303 |
+
<comment>Se houver um erro ou o método não for aplicável naquela situação, mesmo assim mostrar as mensagens de erro?</comment>
|
| 304 |
+
</showmethod>
|
| 305 |
<sort_order translate="label">
|
| 306 |
<label>Ordenar por</label>
|
| 307 |
<frontend_type>text</frontend_type>
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-install-4.0.0.php
CHANGED
|
@@ -22,7 +22,7 @@ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
|
| 22 |
|
| 23 |
$installer->startSetup();
|
| 24 |
|
| 25 |
-
//
|
| 26 |
$codigo = 'volume_comprimento';
|
| 27 |
$config = array(
|
| 28 |
'position' => 1,
|
|
@@ -36,7 +36,7 @@ $config = array(
|
|
| 36 |
|
| 37 |
$setup->addAttribute('catalog_product', $codigo , $config);
|
| 38 |
|
| 39 |
-
//
|
| 40 |
$codigo = 'volume_altura';
|
| 41 |
$config = array(
|
| 42 |
'position' => 1,
|
|
@@ -50,7 +50,7 @@ $config = array(
|
|
| 50 |
|
| 51 |
$setup->addAttribute('catalog_product', $codigo , $config);
|
| 52 |
|
| 53 |
-
//
|
| 54 |
$codigo = 'volume_largura';
|
| 55 |
$config = array(
|
| 56 |
'position' => 1,
|
| 22 |
|
| 23 |
$installer->startSetup();
|
| 24 |
|
| 25 |
+
// Add volume to prduct attribute set
|
| 26 |
$codigo = 'volume_comprimento';
|
| 27 |
$config = array(
|
| 28 |
'position' => 1,
|
| 36 |
|
| 37 |
$setup->addAttribute('catalog_product', $codigo , $config);
|
| 38 |
|
| 39 |
+
// Add volume to prduct attribute set
|
| 40 |
$codigo = 'volume_altura';
|
| 41 |
$config = array(
|
| 42 |
'position' => 1,
|
| 50 |
|
| 51 |
$setup->addAttribute('catalog_product', $codigo , $config);
|
| 52 |
|
| 53 |
+
// Add volume to prduct attribute set
|
| 54 |
$codigo = 'volume_largura';
|
| 55 |
$config = array(
|
| 56 |
'position' => 1,
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-upgrade-4.0.0-4.1.0.php
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Pedro Teixeira
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL).
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 10 |
+
*
|
| 11 |
+
* @category PedroTeixeira
|
| 12 |
+
* @package PedroTeixeira_Correios
|
| 13 |
+
* @copyright Copyright (c) 2010 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 14 |
+
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 15 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
$installer = $this;
|
| 19 |
+
$installer->startSetup();
|
| 20 |
+
|
| 21 |
+
// Delete unused or edited config data
|
| 22 |
+
$installer->deleteConfigData('carriers/pedroteixeira_correios/ignorar_erro');
|
| 23 |
+
$installer->deleteConfigData('carriers/pedroteixeira_correios/correioserror');
|
| 24 |
+
$installer->deleteConfigData('carriers/pedroteixeira_correios/maxweighterror');
|
| 25 |
+
$installer->deleteConfigData('carriers/pedroteixeira_correios/valueerror');
|
| 26 |
+
$installer->deleteConfigData('carriers/pedroteixeira_correios/showmethod');
|
| 27 |
+
|
| 28 |
+
$installer->endSetup();
|
| 29 |
+
?>
|
package.xml
CHANGED
|
@@ -1,13 +1,17 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>PedroTeixeira_Correios</name>
|
| 4 |
-
<version>4.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>GNU General Public License (GPL)</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Módulo de cálculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje e Sedex a Cobrar.</summary>
|
| 10 |
-
<description>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
- Sedex Sem Contrato
|
| 13 |
- Sedex Com Contrato
|
|
@@ -18,16 +22,16 @@
|
|
| 18 |
- Sedex HOJE
|
| 19 |
- Sedex a Cobrar
|
| 20 |
|
| 21 |
-
Conta com identificação de erros dos Correios,
|
| 22 |
|
| 23 |
-
Na nova versão conta com
|
| 24 |
|
| 25 |
-
Mais informações em http://www.pteixeira.com.br
|
| 26 |
<notes>Módulo de cálculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje e Sedex a Cobrar.</notes>
|
| 27 |
<authors><author><name>Pedro Teixeira</name><user>auto-converted</user><email>teixeira.pedro@gmail.com</email></author></authors>
|
| 28 |
-
<date>2010-
|
| 29 |
-
<time>
|
| 30 |
-
<contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="PedroTeixeira_Correios.xml" hash="f00c1a1ffcf9a08f67dbbdbd96da4eaf"/></dir></dir></dir></target><target name="magecommunity"><dir name="PedroTeixeira"><dir name="Correios"><dir name="etc"><file name="config.xml" hash="
|
| 31 |
<compatible/>
|
| 32 |
<dependencies/>
|
| 33 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>PedroTeixeira_Correios</name>
|
| 4 |
+
<version>4.1.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>GNU General Public License (GPL)</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Módulo de cálculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje e Sedex a Cobrar.</summary>
|
| 10 |
+
<description>Versão 4.1.0 do módulo de cálculo de frete para Magento.
|
| 11 |
+
|
| 12 |
+
Módulo totalmente compatível com o novo WebService dos Correios e agora realizando apenas uma consulta para todos os serviços.
|
| 13 |
+
|
| 14 |
+
Também é integrado com o WebService de cálculo de frete da Locaweb e hoje conta com os seguintes serviços:
|
| 15 |
|
| 16 |
- Sedex Sem Contrato
|
| 17 |
- Sedex Com Contrato
|
| 22 |
- Sedex HOJE
|
| 23 |
- Sedex a Cobrar
|
| 24 |
|
| 25 |
+
Conta com identificação de erros dos Correios, mão própria, aviso de recebimento, valor declarado, captura do prazo de entrega dos Correios, adicionar mais dias ao prazo dos Correios, identifica o volume dos produtos por atributo e Tracking em tempo real.
|
| 26 |
|
| 27 |
+
Na nova versão conta com apenas uma chamada para todos os serviços, integração total com as regras de desconto, integração com a nova versão do Magento e correção de alguns bugs.
|
| 28 |
|
| 29 |
+
Mais informações em http://www.pteixeira.com.br.</description>
|
| 30 |
<notes>Módulo de cálculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje e Sedex a Cobrar.</notes>
|
| 31 |
<authors><author><name>Pedro Teixeira</name><user>auto-converted</user><email>teixeira.pedro@gmail.com</email></author></authors>
|
| 32 |
+
<date>2010-08-11</date>
|
| 33 |
+
<time>02:40:07</time>
|
| 34 |
+
<contents><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="PedroTeixeira_Correios.xml" hash="f00c1a1ffcf9a08f67dbbdbd96da4eaf"/></dir></dir></dir></target><target name="magecommunity"><dir name="PedroTeixeira"><dir name="Correios"><dir name="etc"><file name="config.xml" hash="65b33aa38fb1ad4441127db3a369ffb2"/><file name="system.xml" hash="a80c16dc09de838f4036a501abd09550"/></dir><dir name="Helper"><file name="Data.php" hash="ce1c4fba4a0accdd6b1210ba63734ef7"/></dir><dir name="Model"><dir name="Carrier"><file name="CorreiosMethod.php" hash="38ff7aac6b0bc65c89a0f318138dffe9"/></dir><dir name="Source"><file name="PostMethods.php" hash="6e23f605ca7eca17dc277f0b9d83467f"/><file name="UrlMethods.php" hash="02bf735b441af7bf9266632a978b0e62"/><file name="WeightType.php" hash="e77ee1d2fed0c623064dfc539e2ab8fe"/></dir></dir><dir name="sql"><dir name="pedroteixeira_correios_setup"><file name="mysql4-install-4.0.0.php" hash="0641513355706a69c50e5ff1a253aa16"/><file name="mysql4-upgrade-4.0.0-4.1.0.php" hash="d2b1492e4019a296029fdea05a89b891"/></dir></dir></dir></dir></target></contents>
|
| 35 |
<compatible/>
|
| 36 |
<dependencies/>
|
| 37 |
</package>
|
