Version Notes
Bugfix:
- Assinatura do método isZipCodeRequired() foi alterada
Feature:
- Revisão do code style
- Documentação em markdown
- Novos códigos de erros dos Correios
- Novos limites de dimensão dos Correios
Download this release
Release Info
| Developer | Pedro Teixeira |
| Extension | PedroTeixeira_Correios |
| Version | 4.3.0 |
| Comparing to | |
| See all releases | |
Code changes from version 4.2.0 to 4.3.0
- app/code/community/PedroTeixeira/Correios/Helper/Data.php +11 -14
- app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +234 -272
- app/code/community/PedroTeixeira/Correios/Model/Source/PostMethods.php +19 -23
- app/code/community/PedroTeixeira/Correios/Model/Source/WeightType.php +18 -16
- app/code/community/PedroTeixeira/Correios/etc/config.xml +17 -21
- app/code/community/PedroTeixeira/Correios/etc/system.xml +42 -38
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.0.0.php +63 -0
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-install-4.0.0.php +0 -67
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-upgrade-4.1.0-4.2.0.php +0 -46
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/{mysql4-upgrade-4.0.0-4.1.0.php → upgrade-4.0.0-4.1.0.php} +9 -12
- app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.1.0-4.2.0.php +66 -0
- app/etc/modules/PedroTeixeira_Correios.xml +7 -12
- package.xml +35 -26
app/code/community/PedroTeixeira/Correios/Helper/Data.php
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
-
*
|
|
|
|
| 4 |
*
|
| 5 |
-
*
|
| 6 |
-
*
|
| 7 |
-
*
|
| 8 |
-
*
|
| 9 |
-
* http://
|
| 10 |
-
*
|
| 11 |
-
* @category PedroTeixeira
|
| 12 |
-
* @package PedroTeixeira_Correios
|
| 13 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 14 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 15 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 16 |
*/
|
| 17 |
-
|
| 18 |
-
|
|
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
*/
|
| 13 |
+
class PedroTeixeira_Correios_Helper_Data extends Mage_Core_Helper_Abstract
|
| 14 |
+
{
|
| 15 |
+
}
|
app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php
CHANGED
|
@@ -1,412 +1,374 @@
|
|
| 1 |
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Pedro Teixeira
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the New BSD License.
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://www.pteixeira.com.br/new-bsd-license/
|
| 10 |
-
*
|
| 11 |
-
* @category PedroTeixeira
|
| 12 |
-
* @package PedroTeixeira_Correios
|
| 13 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 14 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 15 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 16 |
-
*/
|
| 17 |
|
| 18 |
/**
|
| 19 |
-
*
|
|
|
|
| 20 |
*
|
| 21 |
-
* @category
|
| 22 |
-
* @package
|
| 23 |
-
* @
|
|
|
|
|
|
|
| 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
|
| 37 |
|
| 38 |
/**
|
| 39 |
* _result property
|
| 40 |
*
|
| 41 |
-
* @var Mage_Shipping_Model_Rate_Result
|
| 42 |
*/
|
| 43 |
-
protected $_result
|
| 44 |
|
| 45 |
/**
|
| 46 |
* ZIP code vars
|
| 47 |
*/
|
| 48 |
-
protected $_fromZip
|
| 49 |
-
protected $_toZip
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Value and Weight
|
| 53 |
*/
|
| 54 |
-
protected $_packageValue
|
| 55 |
-
protected $_packageWeight
|
| 56 |
-
protected $_volumeWeight
|
| 57 |
-
protected $_freeMethodWeight
|
| 58 |
|
| 59 |
/**
|
| 60 |
* Post methods
|
| 61 |
*/
|
| 62 |
-
protected $_postMethods
|
| 63 |
-
protected $_postMethodsFixed
|
| 64 |
-
protected $_postMethodsExplode
|
| 65 |
|
| 66 |
/**
|
| 67 |
* Free method request
|
| 68 |
*/
|
| 69 |
-
protected $_freeMethodRequest
|
| 70 |
protected $_freeMethodRequestResult = null;
|
| 71 |
|
| 72 |
/**
|
| 73 |
* Collect Rates
|
| 74 |
*
|
| 75 |
* @param Mage_Shipping_Model_Rate_Request $request
|
| 76 |
-
*
|
|
|
|
| 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')
|
| 88 |
-
|
| 89 |
-
|
| 90 |
$this->_throwError('valueerror', 'Value limits', __LINE__);
|
| 91 |
return $this->_result;
|
| 92 |
}
|
| 93 |
|
| 94 |
// Check ZIP Code
|
| 95 |
-
if(!preg_match(
|
| 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') ==
|
| 105 |
-
|
| 106 |
-
$
|
| 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 Volume Weight
|
| 127 |
-
if($this->_generateVolumeWeight() === false)
|
| 128 |
-
{
|
| 129 |
-
// Dimension error
|
| 130 |
$this->_throwError('dimensionerror', 'Dimension error', __LINE__);
|
| 131 |
return $this->_result;
|
| 132 |
}
|
| 133 |
|
| 134 |
-
|
| 135 |
-
$this->
|
| 136 |
-
$this->
|
| 137 |
-
$this->_postMethodsExplode = explode(",", $this->getConfigData('postmethods'));
|
| 138 |
|
| 139 |
-
|
| 140 |
-
if($this->_getQuotes()->getError()) {
|
| 141 |
return $this->_result;
|
| 142 |
}
|
| 143 |
|
| 144 |
// Use descont codes
|
| 145 |
$this->_updateFreeMethodQuote($request);
|
| 146 |
|
| 147 |
-
// Return rates / errors
|
| 148 |
return $this->_result;
|
| 149 |
-
|
| 150 |
}
|
| 151 |
|
| 152 |
/**
|
| 153 |
* Get shipping quote
|
| 154 |
-
*
|
| 155 |
-
* @return
|
| 156 |
*/
|
| 157 |
-
protected function _getQuotes()
|
| 158 |
-
|
| 159 |
-
$
|
| 160 |
-
|
| 161 |
-
// Call Correios
|
| 162 |
$correiosReturn = $this->_getCorreiosReturn();
|
| 163 |
|
| 164 |
-
if($correiosReturn !== false){
|
| 165 |
|
| 166 |
-
// Check if exist return from Correios
|
| 167 |
$existReturn = false;
|
| 168 |
|
| 169 |
-
foreach($correiosReturn as $servicos){
|
| 170 |
|
| 171 |
-
|
| 172 |
-
$errorId = $this->_cleanCorreiosError((string)$servicos->Erro);
|
| 173 |
|
| 174 |
-
if($errorId != 0){
|
| 175 |
-
|
| 176 |
-
if(in_array($errorId, $dieErrors)){
|
| 177 |
-
$this->_throwError('correioserror', 'Correios Error: ' . (string)$servicos->MsgErro . ' [Cod. ' . $errorId . '] [Serv. ' . (string)$servicos->Codigo . ']' , __LINE__, (string)$servicos->MsgErro . ' (Cod. ' . $errorId . ')');
|
| 178 |
-
return $this->_result;
|
| 179 |
-
}else{
|
| 180 |
-
continue;
|
| 181 |
-
}
|
| 182 |
}
|
| 183 |
-
|
| 184 |
-
$shippingPrice = floatval(str_replace(",",".",(string)$servicos->Valor));
|
| 185 |
-
$shippingDelivery = (int)$servicos->PrazoEntrega;
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
| 188 |
continue;
|
| 189 |
}
|
| 190 |
|
| 191 |
-
|
| 192 |
-
$this->_apendShippingReturn((string)$servicos->Codigo, $shippingPrice, $shippingDelivery);
|
| 193 |
$existReturn = true;
|
| 194 |
}
|
| 195 |
|
| 196 |
-
|
| 197 |
-
if($existReturn === false){
|
| 198 |
$this->_throwError('urlerror', 'URL Error, all services return with error', __LINE__);
|
| 199 |
return $this->_result;
|
| 200 |
}
|
| 201 |
-
|
| 202 |
-
}else{
|
| 203 |
-
// Error on HTTP Correios
|
| 204 |
return $this->_result;
|
| 205 |
}
|
| 206 |
|
| 207 |
-
|
| 208 |
-
if($this->_freeMethodRequest === true){
|
| 209 |
return $this->_freeMethodRequestResult;
|
| 210 |
-
}else{
|
| 211 |
return $this->_result;
|
| 212 |
}
|
| 213 |
}
|
| 214 |
|
| 215 |
-
|
| 216 |
/**
|
| 217 |
* Make initial checks and iniciate module variables
|
| 218 |
*
|
| 219 |
* @param Mage_Shipping_Model_Rate_Request $request
|
| 220 |
-
*
|
|
|
|
| 221 |
*/
|
| 222 |
-
protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request)
|
|
|
|
| 223 |
|
| 224 |
-
if (!$this->getConfigFlag('active'))
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
Mage::log('PedroTeixeira_Correios: Disabled');
|
| 228 |
return false;
|
| 229 |
}
|
| 230 |
|
| 231 |
-
|
| 232 |
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
|
| 233 |
$destCountry = $request->getDestCountryId();
|
| 234 |
-
if ($origCountry !=
|
| 235 |
-
//Out of delivery area
|
| 236 |
-
Mage::log('
|
| 237 |
return false;
|
| 238 |
}
|
| 239 |
|
| 240 |
-
// ZIP Code
|
| 241 |
$this->_fromZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
|
| 242 |
-
$this->_toZip
|
| 243 |
|
| 244 |
-
//Fix
|
| 245 |
-
$this->_fromZip = str_replace(array('-','.'), '', trim($this->_fromZip));
|
| 246 |
-
$this->_toZip
|
| 247 |
|
| 248 |
-
if(!preg_match(
|
| 249 |
-
|
| 250 |
-
Mage::log('PedroTeixeira_Correios: From ZIP Code Error');
|
| 251 |
return false;
|
| 252 |
}
|
| 253 |
|
| 254 |
-
// Result model
|
| 255 |
$this->_result = Mage::getModel('shipping/rate_result');
|
| 256 |
-
|
| 257 |
-
// Value
|
| 258 |
$this->_packageValue = $request->getBaseCurrency()->convert(
|
| 259 |
$request->getPackageValue(),
|
| 260 |
$request->getPackageCurrency()
|
| 261 |
);
|
| 262 |
|
| 263 |
-
|
| 264 |
-
$this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', '');
|
| 265 |
-
|
| 266 |
-
// Free method weight
|
| 267 |
$this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', '');
|
| 268 |
-
|
| 269 |
}
|
| 270 |
|
| 271 |
/**
|
| 272 |
* Get Correios return
|
| 273 |
*
|
| 274 |
-
* @return bool
|
| 275 |
*/
|
| 276 |
-
protected function _getCorreiosReturn()
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
-
$filename = $this->getConfigData('url_ws_correios');
|
| 279 |
-
$contratoCodes = explode(",", $this->getConfigData('contrato_codes'));
|
| 280 |
-
|
| 281 |
try {
|
| 282 |
$client = new Zend_Http_Client($filename);
|
| 283 |
-
$client->setConfig(
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
| 286 |
|
| 287 |
$client->setParameterGet('StrRetorno', 'xml');
|
| 288 |
$client->setParameterGet('nCdServico', $this->_postMethods);
|
| 289 |
|
| 290 |
-
if($this->_volumeWeight > $this->getConfigData('volume_weight_min')
|
|
|
|
|
|
|
| 291 |
$client->setParameterGet('nVlPeso', $this->_volumeWeight);
|
| 292 |
-
}else{
|
| 293 |
$client->setParameterGet('nVlPeso', $this->_packageWeight);
|
| 294 |
}
|
| 295 |
|
| 296 |
$client->setParameterGet('sCepOrigem', $this->_fromZip);
|
| 297 |
$client->setParameterGet('sCepDestino', $this->_toZip);
|
| 298 |
-
$client->setParameterGet('nCdFormato',1);
|
| 299 |
-
$client->setParameterGet('nVlComprimento'
|
| 300 |
-
$client->setParameterGet('nVlAltura'
|
| 301 |
-
$client->setParameterGet('nVlLargura'
|
| 302 |
-
|
| 303 |
-
if($this->getConfigData('mao_propria')){
|
| 304 |
-
$client->setParameterGet('sCdMaoPropria','S');
|
| 305 |
-
}else{
|
| 306 |
-
$client->setParameterGet('sCdMaoPropria','N');
|
| 307 |
}
|
| 308 |
|
| 309 |
-
if($this->getConfigData('aviso_recebimento')){
|
| 310 |
-
$client->setParameterGet('sCdAvisoRecebimento','S');
|
| 311 |
-
}else{
|
| 312 |
-
$client->setParameterGet('sCdAvisoRecebimento','N');
|
| 313 |
}
|
| 314 |
|
| 315 |
-
if($this->getConfigData('valor_declarado')
|
| 316 |
-
$
|
| 317 |
-
|
| 318 |
-
$client->setParameterGet('nVlValorDeclarado',
|
|
|
|
|
|
|
| 319 |
}
|
| 320 |
|
| 321 |
$contrato = false;
|
| 322 |
-
foreach($contratoCodes as $contratoEach){
|
| 323 |
-
if(in_array($contratoEach, $this->_postMethodsExplode)){
|
| 324 |
$contrato = true;
|
| 325 |
}
|
| 326 |
}
|
| 327 |
|
| 328 |
-
if($contrato){
|
| 329 |
-
if($this->getConfigData('cod_admin') == '' || $this->getConfigData('senha_admin') == ''){
|
| 330 |
-
// Need correios admin data
|
| 331 |
$this->_throwError('coderror', 'Need correios admin data', __LINE__);
|
| 332 |
return false;
|
| 333 |
-
}else{
|
| 334 |
-
$client->setParameterGet('nCdEmpresa'
|
| 335 |
-
$client->setParameterGet('sDsSenha'
|
| 336 |
}
|
| 337 |
}
|
| 338 |
|
| 339 |
$content = $client->request()->getBody();
|
| 340 |
|
| 341 |
-
if ($content ==
|
| 342 |
-
throw new Exception(
|
| 343 |
}
|
| 344 |
|
| 345 |
libxml_use_internal_errors(true);
|
| 346 |
$sxe = simplexml_load_string($content);
|
| 347 |
if (!$sxe) {
|
| 348 |
-
throw new Exception(
|
| 349 |
}
|
| 350 |
|
| 351 |
-
// Load XML
|
| 352 |
$xml = new SimpleXMLElement($content);
|
| 353 |
|
| 354 |
-
if(count($xml->cServico) <= 0){
|
| 355 |
-
throw new Exception(
|
| 356 |
}
|
| 357 |
|
| 358 |
return $xml->cServico;
|
| 359 |
-
|
| 360 |
} catch (Exception $e) {
|
| 361 |
-
//URL Error
|
| 362 |
$this->_throwError('urlerror', 'URL Error - ' . $e->getMessage(), __LINE__);
|
| 363 |
return false;
|
| 364 |
-
}
|
| 365 |
}
|
| 366 |
|
| 367 |
/**
|
| 368 |
* Apend shipping value to return
|
| 369 |
*
|
| 370 |
-
* @param $shipping_method
|
| 371 |
-
* @param $shippingPrice
|
| 372 |
-
* @param $
|
|
|
|
| 373 |
* @return void
|
| 374 |
*/
|
| 375 |
-
protected function _apendShippingReturn($shipping_method, $shippingPrice = 0, $correiosDelivery = 0)
|
|
|
|
| 376 |
|
| 377 |
$method = Mage::getModel('shipping/rate_result_method');
|
| 378 |
$method->setCarrier($this->_code);
|
| 379 |
$method->setCarrierTitle($this->getConfigData('title'));
|
| 380 |
$method->setMethod($shipping_method);
|
| 381 |
|
| 382 |
-
$shippingCost
|
| 383 |
$shippingPrice = $shippingPrice + $this->getConfigData('handling_fee');
|
| 384 |
|
| 385 |
$shipping_data = explode(',', $this->getConfigData('serv_' . $shipping_method));
|
| 386 |
|
| 387 |
-
if($shipping_method == $this->getConfigData('acobrar_code')){
|
| 388 |
$shipping_data[0] = $shipping_data[0] . ' ( R$' . number_format($shippingPrice, 2, ',', '.') . ' )';
|
| 389 |
-
$shippingPrice
|
| 390 |
}
|
| 391 |
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
}
|
| 400 |
-
}else{
|
| 401 |
$method->setMethodTitle($shipping_data[0]);
|
| 402 |
}
|
| 403 |
|
| 404 |
$method->setPrice($shippingPrice);
|
| 405 |
$method->setCost($shippingCost);
|
| 406 |
|
| 407 |
-
if($this->_freeMethodRequest === true){
|
| 408 |
$this->_freeMethodRequestResult->append($method);
|
| 409 |
-
}else{
|
| 410 |
$this->_result->append($method);
|
| 411 |
}
|
| 412 |
}
|
|
@@ -414,86 +376,80 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 414 |
/**
|
| 415 |
* Throw error
|
| 416 |
*
|
| 417 |
-
* @param $message
|
| 418 |
-
* @param $log
|
| 419 |
-
* @param $line
|
| 420 |
-
* @param $custom
|
| 421 |
-
* @return void
|
| 422 |
*/
|
| 423 |
-
protected function _throwError($message, $log = null, $line = 'NO LINE', $custom = null)
|
| 424 |
-
|
| 425 |
$this->_result = null;
|
| 426 |
$this->_result = Mage::getModel('shipping/rate_result');
|
| 427 |
|
| 428 |
-
// Get error model
|
| 429 |
$error = Mage::getModel('shipping/rate_result_error');
|
| 430 |
$error->setCarrier($this->_code);
|
| 431 |
$error->setCarrierTitle($this->getConfigData('title'));
|
| 432 |
|
| 433 |
-
if(is_null($custom) || $this->getConfigData($message) == ''){
|
| 434 |
-
//Log error
|
| 435 |
Mage::log($this->_code . ' [' . $line . ']: ' . $log);
|
| 436 |
$error->setErrorMessage($this->getConfigData($message));
|
| 437 |
-
}else{
|
| 438 |
-
//Log error
|
| 439 |
Mage::log($this->_code . ' [' . $line . ']: ' . $log);
|
| 440 |
$error->setErrorMessage(sprintf($this->getConfigData($message), $custom));
|
| 441 |
-
}
|
| 442 |
|
| 443 |
-
// Apend error
|
| 444 |
$this->_result->append($error);
|
| 445 |
}
|
| 446 |
|
| 447 |
/**
|
| 448 |
* Generate Volume weight
|
| 449 |
*
|
|
|
|
|
|
|
| 450 |
* @return bool
|
| 451 |
*/
|
| 452 |
-
protected function _generateVolumeWeight()
|
| 453 |
-
|
| 454 |
$pesoCubicoTotal = 0;
|
| 455 |
|
| 456 |
-
// Get all visible itens from quote
|
| 457 |
$items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
|
| 458 |
|
| 459 |
-
foreach($items as $item){
|
| 460 |
-
|
| 461 |
-
$itemAltura= 0;
|
| 462 |
-
$itemLargura = 0;
|
| 463 |
-
$itemComprimento = 0;
|
| 464 |
-
|
| 465 |
$_product = $item->getProduct();
|
| 466 |
|
| 467 |
-
if($_product->getData('volume_altura') == '' || (int)$_product->getData('volume_altura') == 0)
|
| 468 |
$itemAltura = $this->getConfigData('altura_padrao');
|
| 469 |
-
else
|
| 470 |
$itemAltura = $_product->getData('volume_altura');
|
|
|
|
| 471 |
|
| 472 |
-
if($_product->getData('volume_largura') == '' || (int)$_product->getData('volume_largura') == 0)
|
| 473 |
$itemLargura = $this->getConfigData('largura_padrao');
|
| 474 |
-
else
|
| 475 |
$itemLargura = $_product->getData('volume_largura');
|
|
|
|
| 476 |
|
| 477 |
-
if($_product->getData('volume_comprimento') == '' || (int)$_product->getData('volume_comprimento') == 0)
|
| 478 |
$itemComprimento = $this->getConfigData('comprimento_padrao');
|
| 479 |
-
else
|
| 480 |
$itemComprimento = $_product->getData('volume_comprimento');
|
|
|
|
| 481 |
|
| 482 |
-
if($this->getConfigFlag('check_dimensions')){
|
| 483 |
-
if(
|
| 484 |
-
$itemAltura > $this->getConfigData('volume_validation/altura_max')
|
| 485 |
|| $itemAltura < $this->getConfigData('volume_validation/altura_min')
|
| 486 |
|| $itemLargura > $this->getConfigData('volume_validation/largura_max')
|
| 487 |
|| $itemLargura < $this->getConfigData('volume_validation/largura_min')
|
| 488 |
|| $itemComprimento > $this->getConfigData('volume_validation/comprimento_max')
|
| 489 |
|| $itemComprimento < $this->getConfigData('volume_validation/comprimento_min')
|
| 490 |
-
|| ($itemAltura
|
| 491 |
-
|
|
|
|
| 492 |
return false;
|
| 493 |
}
|
| 494 |
}
|
| 495 |
|
| 496 |
-
$pesoCubicoTotal += (($itemAltura
|
| 497 |
}
|
| 498 |
|
| 499 |
$this->_volumeWeight = number_format($pesoCubicoTotal, 2, '.', '');
|
|
@@ -505,46 +461,32 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 505 |
* Generate free shipping for a product
|
| 506 |
*
|
| 507 |
* @param string $freeMethod
|
|
|
|
| 508 |
* @return void
|
| 509 |
*/
|
| 510 |
protected function _setFreeMethodRequest($freeMethod)
|
| 511 |
{
|
| 512 |
-
|
| 513 |
-
$this->_freeMethodRequest = true;
|
| 514 |
$this->_freeMethodRequestResult = Mage::getModel('shipping/rate_result');
|
| 515 |
|
| 516 |
-
$this->_postMethods
|
| 517 |
-
$this->_postMethodsExplode = array($freeMethod);
|
| 518 |
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
{
|
| 522 |
-
$this->_freeMethodWeight = number_format($this->_freeMethodWeight/1000, 2, '.', '');
|
| 523 |
}
|
| 524 |
-
|
| 525 |
-
$this->_packageWeight = $this->_freeMethodWeight;
|
| 526 |
-
$this->_pacWeight = $this->_freeMethodWeight;
|
| 527 |
-
}
|
| 528 |
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
*
|
| 532 |
-
* @param string $error
|
| 533 |
-
* @return int
|
| 534 |
-
*/
|
| 535 |
-
protected function _cleanCorreiosError($error){
|
| 536 |
-
$error = str_replace('-', '', $error);
|
| 537 |
-
$error = (int)$error;
|
| 538 |
-
return $error;
|
| 539 |
}
|
| 540 |
|
| 541 |
-
|
| 542 |
/**
|
| 543 |
* Check if current carrier offer support to tracking
|
| 544 |
*
|
| 545 |
-
* @return
|
| 546 |
*/
|
| 547 |
-
public function isTrackingAvailable()
|
|
|
|
| 548 |
return true;
|
| 549 |
}
|
| 550 |
|
|
@@ -552,17 +494,20 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 552 |
* Get Tracking Info
|
| 553 |
*
|
| 554 |
* @param mixed $tracking
|
|
|
|
| 555 |
* @return mixed
|
| 556 |
*/
|
| 557 |
-
public function getTrackingInfo($tracking)
|
|
|
|
| 558 |
$result = $this->getTracking($tracking);
|
| 559 |
-
if ($result instanceof Mage_Shipping_Model_Tracking_Result){
|
| 560 |
if ($trackings = $result->getAllTrackings()) {
|
| 561 |
-
|
| 562 |
}
|
| 563 |
} elseif (is_string($result) && !empty($result)) {
|
| 564 |
return $result;
|
| 565 |
}
|
|
|
|
| 566 |
return false;
|
| 567 |
}
|
| 568 |
|
|
@@ -570,13 +515,16 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 570 |
* Get Tracking
|
| 571 |
*
|
| 572 |
* @param array $trackings
|
|
|
|
| 573 |
* @return Mage_Shipping_Model_Tracking_Result
|
| 574 |
*/
|
| 575 |
-
public function getTracking($trackings)
|
|
|
|
| 576 |
$this->_result = Mage::getModel('shipping/tracking_result');
|
| 577 |
foreach ((array) $trackings as $code) {
|
| 578 |
$this->_getTracking($code);
|
| 579 |
}
|
|
|
|
| 580 |
return $this->_result;
|
| 581 |
}
|
| 582 |
|
|
@@ -584,9 +532,11 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 584 |
* Protected Get Tracking, opens the request to Correios
|
| 585 |
*
|
| 586 |
* @param string $code
|
| 587 |
-
*
|
|
|
|
| 588 |
*/
|
| 589 |
-
protected function _getTracking($code)
|
|
|
|
| 590 |
$error = Mage::getModel('shipping/tracking_result_error');
|
| 591 |
$error->setTracking($code);
|
| 592 |
$error->setCarrier($this->_code);
|
|
@@ -599,7 +549,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 599 |
$client = new Zend_Http_Client();
|
| 600 |
$client->setUri($url);
|
| 601 |
$content = $client->request();
|
| 602 |
-
$body
|
| 603 |
} catch (Exception $e) {
|
| 604 |
$this->_result->append($error);
|
| 605 |
return false;
|
|
@@ -621,30 +571,40 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 621 |
$column = $columns[$i][1];
|
| 622 |
|
| 623 |
$description = '';
|
| 624 |
-
$found
|
| 625 |
-
if (preg_match('/<td rowspan="?2"?/i', $column) && preg_match(
|
| 626 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
$description = str_replace(' ', '', $matchesDescription[1]);
|
| 628 |
}
|
| 629 |
|
| 630 |
$found = true;
|
| 631 |
-
} elseif (preg_match(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
$found = true;
|
| 633 |
}
|
| 634 |
|
| 635 |
if ($found) {
|
| 636 |
$datetime = explode(' ', $matches[1]);
|
| 637 |
-
$locale
|
| 638 |
-
$date='';
|
| 639 |
-
$date
|
| 640 |
|
| 641 |
$track = array(
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
|
| 649 |
if ($description !== '') {
|
| 650 |
$track['activity'] = $matches[3] . ' - ' . htmlentities($description);
|
|
@@ -655,7 +615,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 655 |
}
|
| 656 |
|
| 657 |
if (!empty($progress)) {
|
| 658 |
-
$track
|
| 659 |
$track['progressdetail'] = $progress;
|
| 660 |
|
| 661 |
$tracking = Mage::getModel('shipping/tracking_result_status');
|
|
@@ -685,9 +645,11 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
|
| 685 |
/**
|
| 686 |
* Define ZIP Code as required
|
| 687 |
*
|
| 688 |
-
* @
|
|
|
|
|
|
|
| 689 |
*/
|
| 690 |
-
public function isZipCodeRequired()
|
| 691 |
{
|
| 692 |
return true;
|
| 693 |
}
|
| 1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
| 12 |
*/
|
|
|
|
| 13 |
class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
|
| 14 |
extends Mage_Shipping_Model_Carrier_Abstract
|
| 15 |
implements Mage_Shipping_Model_Carrier_Interface
|
| 16 |
{
|
|
|
|
| 17 |
/**
|
| 18 |
* _code property
|
| 19 |
*
|
| 20 |
* @var string
|
| 21 |
*/
|
| 22 |
+
protected $_code = 'pedroteixeira_correios';
|
| 23 |
|
| 24 |
/**
|
| 25 |
* _result property
|
| 26 |
*
|
| 27 |
+
* @var Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result
|
| 28 |
*/
|
| 29 |
+
protected $_result = null;
|
| 30 |
|
| 31 |
/**
|
| 32 |
* ZIP code vars
|
| 33 |
*/
|
| 34 |
+
protected $_fromZip = null;
|
| 35 |
+
protected $_toZip = null;
|
| 36 |
|
| 37 |
/**
|
| 38 |
* Value and Weight
|
| 39 |
*/
|
| 40 |
+
protected $_packageValue = null;
|
| 41 |
+
protected $_packageWeight = null;
|
| 42 |
+
protected $_volumeWeight = null;
|
| 43 |
+
protected $_freeMethodWeight = null;
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Post methods
|
| 47 |
*/
|
| 48 |
+
protected $_postMethods = null;
|
| 49 |
+
protected $_postMethodsFixed = null;
|
| 50 |
+
protected $_postMethodsExplode = null;
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Free method request
|
| 54 |
*/
|
| 55 |
+
protected $_freeMethodRequest = false;
|
| 56 |
protected $_freeMethodRequestResult = null;
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Collect Rates
|
| 60 |
*
|
| 61 |
* @param Mage_Shipping_Model_Rate_Request $request
|
| 62 |
+
*
|
| 63 |
+
* @return bool|Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result
|
| 64 |
*/
|
| 65 |
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
|
| 66 |
+
{
|
| 67 |
// Do initial check
|
| 68 |
+
if ($this->_inicialCheck($request) === false) {
|
|
|
|
| 69 |
return false;
|
| 70 |
}
|
| 71 |
|
| 72 |
// Check package value
|
| 73 |
+
if ($this->_packageValue < $this->getConfigData('min_order_value')
|
| 74 |
+
|| $this->_packageValue > $this->getConfigData('max_order_value')
|
| 75 |
+
) {
|
| 76 |
$this->_throwError('valueerror', 'Value limits', __LINE__);
|
| 77 |
return $this->_result;
|
| 78 |
}
|
| 79 |
|
| 80 |
// Check ZIP Code
|
| 81 |
+
if (!preg_match('/^([0-9]{8})$/', $this->_toZip)) {
|
|
|
|
|
|
|
| 82 |
$this->_throwError('zipcodeerror', 'Invalid Zip Code', __LINE__);
|
| 83 |
return $this->_result;
|
| 84 |
}
|
| 85 |
+
|
| 86 |
// Fix weight
|
| 87 |
$weightCompare = $this->getConfigData('maxweight');
|
| 88 |
+
if ($this->getConfigData('weight_type') == PedroTeixeira_Correios_Model_Source_WeightType::WEIGHT_GR) {
|
| 89 |
+
$this->_packageWeight = number_format($this->_packageWeight / 1000, 2, '.', '');
|
| 90 |
+
$weightCompare = number_format($weightCompare / 1000, 2, '.', '');
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
// Check weght
|
| 94 |
+
if ($this->_packageWeight > $weightCompare) {
|
|
|
|
|
|
|
| 95 |
$this->_throwError('maxweighterror', 'Weight exceeded limit', __LINE__);
|
| 96 |
return $this->_result;
|
| 97 |
}
|
| 98 |
|
| 99 |
// Check weight zero
|
| 100 |
+
if ($this->_packageWeight <= 0) {
|
|
|
|
|
|
|
| 101 |
$this->_throwError('weightzeroerror', 'Weight zero', __LINE__);
|
| 102 |
return $this->_result;
|
| 103 |
+
}
|
| 104 |
|
| 105 |
// Generate Volume Weight
|
| 106 |
+
if ($this->_generateVolumeWeight() === false) {
|
|
|
|
|
|
|
| 107 |
$this->_throwError('dimensionerror', 'Dimension error', __LINE__);
|
| 108 |
return $this->_result;
|
| 109 |
}
|
| 110 |
|
| 111 |
+
$this->_postMethods = $this->getConfigData('postmethods');
|
| 112 |
+
$this->_postMethodsFixed = $this->_postMethods;
|
| 113 |
+
$this->_postMethodsExplode = explode(',', $this->getConfigData('postmethods'));
|
|
|
|
| 114 |
|
| 115 |
+
if ($this->_getQuotes()->getError()) {
|
|
|
|
| 116 |
return $this->_result;
|
| 117 |
}
|
| 118 |
|
| 119 |
// Use descont codes
|
| 120 |
$this->_updateFreeMethodQuote($request);
|
| 121 |
|
|
|
|
| 122 |
return $this->_result;
|
|
|
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Get shipping quote
|
| 127 |
+
*
|
| 128 |
+
* @return Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result
|
| 129 |
*/
|
| 130 |
+
protected function _getQuotes()
|
| 131 |
+
{
|
| 132 |
+
$softErrors = explode(',', $this->getConfigData('soft_errors'));
|
|
|
|
|
|
|
| 133 |
$correiosReturn = $this->_getCorreiosReturn();
|
| 134 |
|
| 135 |
+
if ($correiosReturn !== false) {
|
| 136 |
|
|
|
|
| 137 |
$existReturn = false;
|
| 138 |
|
| 139 |
+
foreach ($correiosReturn as $servicos) {
|
| 140 |
|
| 141 |
+
$errorId = (string) $servicos->Erro;
|
|
|
|
| 142 |
|
| 143 |
+
if ($errorId != '0' && !in_array($errorId, $softErrors)) {
|
| 144 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
+
$shippingPrice = floatval(str_replace(',', '.', (string) $servicos->Valor));
|
| 148 |
+
$shippingDelivery = (int) $servicos->PrazoEntrega;
|
| 149 |
+
|
| 150 |
+
if ($shippingPrice <= 0) {
|
| 151 |
continue;
|
| 152 |
}
|
| 153 |
|
| 154 |
+
$this->_apendShippingReturn((string) $servicos->Codigo, $shippingPrice, $shippingDelivery);
|
|
|
|
| 155 |
$existReturn = true;
|
| 156 |
}
|
| 157 |
|
| 158 |
+
if ($existReturn === false) {
|
|
|
|
| 159 |
$this->_throwError('urlerror', 'URL Error, all services return with error', __LINE__);
|
| 160 |
return $this->_result;
|
| 161 |
}
|
| 162 |
+
} else {
|
|
|
|
|
|
|
| 163 |
return $this->_result;
|
| 164 |
}
|
| 165 |
|
| 166 |
+
if ($this->_freeMethodRequest === true) {
|
|
|
|
| 167 |
return $this->_freeMethodRequestResult;
|
| 168 |
+
} else {
|
| 169 |
return $this->_result;
|
| 170 |
}
|
| 171 |
}
|
| 172 |
|
|
|
|
| 173 |
/**
|
| 174 |
* Make initial checks and iniciate module variables
|
| 175 |
*
|
| 176 |
* @param Mage_Shipping_Model_Rate_Request $request
|
| 177 |
+
*
|
| 178 |
+
* @return bool
|
| 179 |
*/
|
| 180 |
+
protected function _inicialCheck(Mage_Shipping_Model_Rate_Request $request)
|
| 181 |
+
{
|
| 182 |
|
| 183 |
+
if (!$this->getConfigFlag('active')) {
|
| 184 |
+
// Disabled
|
| 185 |
+
Mage::log('pedroteixeira_correios: Disabled');
|
|
|
|
| 186 |
return false;
|
| 187 |
}
|
| 188 |
|
|
|
|
| 189 |
$origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
|
| 190 |
$destCountry = $request->getDestCountryId();
|
| 191 |
+
if ($origCountry != 'BR' || $destCountry != 'BR') {
|
| 192 |
+
// Out of delivery area
|
| 193 |
+
Mage::log('pedroteixeira_correios: Out of delivery area');
|
| 194 |
return false;
|
| 195 |
}
|
| 196 |
|
|
|
|
| 197 |
$this->_fromZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
|
| 198 |
+
$this->_toZip = $request->getDestPostcode();
|
| 199 |
|
| 200 |
+
// Fix ZIP code
|
| 201 |
+
$this->_fromZip = str_replace(array('-', '.'), '', trim($this->_fromZip));
|
| 202 |
+
$this->_toZip = str_replace(array('-', '.'), '', trim($this->_toZip));
|
| 203 |
|
| 204 |
+
if (!preg_match('/^([0-9]{8})$/', $this->_fromZip)) {
|
| 205 |
+
Mage::log('pedroteixeira_correios: From ZIP Code Error');
|
|
|
|
| 206 |
return false;
|
| 207 |
}
|
| 208 |
|
|
|
|
| 209 |
$this->_result = Mage::getModel('shipping/rate_result');
|
|
|
|
|
|
|
| 210 |
$this->_packageValue = $request->getBaseCurrency()->convert(
|
| 211 |
$request->getPackageValue(),
|
| 212 |
$request->getPackageCurrency()
|
| 213 |
);
|
| 214 |
|
| 215 |
+
$this->_packageWeight = number_format($request->getPackageWeight(), 2, '.', '');
|
|
|
|
|
|
|
|
|
|
| 216 |
$this->_freeMethodWeight = number_format($request->getFreeMethodWeight(), 2, '.', '');
|
|
|
|
| 217 |
}
|
| 218 |
|
| 219 |
/**
|
| 220 |
* Get Correios return
|
| 221 |
*
|
| 222 |
+
* @return bool|SimpleXMLElement[]
|
| 223 |
*/
|
| 224 |
+
protected function _getCorreiosReturn()
|
| 225 |
+
{
|
| 226 |
+
$filename = $this->getConfigData('url_ws_correios');
|
| 227 |
+
$contratoCodes = explode(',', $this->getConfigData('contrato_codes'));
|
| 228 |
|
|
|
|
|
|
|
|
|
|
| 229 |
try {
|
| 230 |
$client = new Zend_Http_Client($filename);
|
| 231 |
+
$client->setConfig(
|
| 232 |
+
array(
|
| 233 |
+
'timeout' => $this->getConfigData('ws_timeout')
|
| 234 |
+
)
|
| 235 |
+
);
|
| 236 |
|
| 237 |
$client->setParameterGet('StrRetorno', 'xml');
|
| 238 |
$client->setParameterGet('nCdServico', $this->_postMethods);
|
| 239 |
|
| 240 |
+
if ($this->_volumeWeight > $this->getConfigData('volume_weight_min')
|
| 241 |
+
&& $this->_volumeWeight > $this->_packageWeight
|
| 242 |
+
) {
|
| 243 |
$client->setParameterGet('nVlPeso', $this->_volumeWeight);
|
| 244 |
+
} else {
|
| 245 |
$client->setParameterGet('nVlPeso', $this->_packageWeight);
|
| 246 |
}
|
| 247 |
|
| 248 |
$client->setParameterGet('sCepOrigem', $this->_fromZip);
|
| 249 |
$client->setParameterGet('sCepDestino', $this->_toZip);
|
| 250 |
+
$client->setParameterGet('nCdFormato', 1);
|
| 251 |
+
$client->setParameterGet('nVlComprimento', $this->getConfigData('comprimento_sent'));
|
| 252 |
+
$client->setParameterGet('nVlAltura', $this->getConfigData('altura_sent'));
|
| 253 |
+
$client->setParameterGet('nVlLargura', $this->getConfigData('largura_sent'));
|
| 254 |
+
|
| 255 |
+
if ($this->getConfigData('mao_propria')) {
|
| 256 |
+
$client->setParameterGet('sCdMaoPropria', 'S');
|
| 257 |
+
} else {
|
| 258 |
+
$client->setParameterGet('sCdMaoPropria', 'N');
|
| 259 |
}
|
| 260 |
|
| 261 |
+
if ($this->getConfigData('aviso_recebimento')) {
|
| 262 |
+
$client->setParameterGet('sCdAvisoRecebimento', 'S');
|
| 263 |
+
} else {
|
| 264 |
+
$client->setParameterGet('sCdAvisoRecebimento', 'N');
|
| 265 |
}
|
| 266 |
|
| 267 |
+
if ($this->getConfigData('valor_declarado')
|
| 268 |
+
|| in_array($this->getConfigData('acobrar_code'), $this->_postMethodsExplode)
|
| 269 |
+
) {
|
| 270 |
+
$client->setParameterGet('nVlValorDeclarado', number_format($this->_packageValue, 2, ',', '.'));
|
| 271 |
+
} else {
|
| 272 |
+
$client->setParameterGet('nVlValorDeclarado', 0);
|
| 273 |
}
|
| 274 |
|
| 275 |
$contrato = false;
|
| 276 |
+
foreach ($contratoCodes as $contratoEach) {
|
| 277 |
+
if (in_array($contratoEach, $this->_postMethodsExplode)) {
|
| 278 |
$contrato = true;
|
| 279 |
}
|
| 280 |
}
|
| 281 |
|
| 282 |
+
if ($contrato) {
|
| 283 |
+
if ($this->getConfigData('cod_admin') == '' || $this->getConfigData('senha_admin') == '') {
|
|
|
|
| 284 |
$this->_throwError('coderror', 'Need correios admin data', __LINE__);
|
| 285 |
return false;
|
| 286 |
+
} else {
|
| 287 |
+
$client->setParameterGet('nCdEmpresa', $this->getConfigData('cod_admin'));
|
| 288 |
+
$client->setParameterGet('sDsSenha', $this->getConfigData('senha_admin'));
|
| 289 |
}
|
| 290 |
}
|
| 291 |
|
| 292 |
$content = $client->request()->getBody();
|
| 293 |
|
| 294 |
+
if ($content == '') {
|
| 295 |
+
throw new Exception('No XML returned [' . __LINE__ . ']');
|
| 296 |
}
|
| 297 |
|
| 298 |
libxml_use_internal_errors(true);
|
| 299 |
$sxe = simplexml_load_string($content);
|
| 300 |
if (!$sxe) {
|
| 301 |
+
throw new Exception('Bad XML [' . __LINE__ . ']');
|
| 302 |
}
|
| 303 |
|
|
|
|
| 304 |
$xml = new SimpleXMLElement($content);
|
| 305 |
|
| 306 |
+
if (count($xml->cServico) <= 0) {
|
| 307 |
+
throw new Exception('No tag cServico in Correios XML [' . __LINE__ . ']');
|
| 308 |
}
|
| 309 |
|
| 310 |
return $xml->cServico;
|
|
|
|
| 311 |
} catch (Exception $e) {
|
|
|
|
| 312 |
$this->_throwError('urlerror', 'URL Error - ' . $e->getMessage(), __LINE__);
|
| 313 |
return false;
|
| 314 |
+
}
|
| 315 |
}
|
| 316 |
|
| 317 |
/**
|
| 318 |
* Apend shipping value to return
|
| 319 |
*
|
| 320 |
+
* @param string $shipping_method
|
| 321 |
+
* @param int $shippingPrice
|
| 322 |
+
* @param int $correiosDelivery
|
| 323 |
+
*
|
| 324 |
* @return void
|
| 325 |
*/
|
| 326 |
+
protected function _apendShippingReturn($shipping_method, $shippingPrice = 0, $correiosDelivery = 0)
|
| 327 |
+
{
|
| 328 |
|
| 329 |
$method = Mage::getModel('shipping/rate_result_method');
|
| 330 |
$method->setCarrier($this->_code);
|
| 331 |
$method->setCarrierTitle($this->getConfigData('title'));
|
| 332 |
$method->setMethod($shipping_method);
|
| 333 |
|
| 334 |
+
$shippingCost = $shippingPrice;
|
| 335 |
$shippingPrice = $shippingPrice + $this->getConfigData('handling_fee');
|
| 336 |
|
| 337 |
$shipping_data = explode(',', $this->getConfigData('serv_' . $shipping_method));
|
| 338 |
|
| 339 |
+
if ($shipping_method == $this->getConfigData('acobrar_code')) {
|
| 340 |
$shipping_data[0] = $shipping_data[0] . ' ( R$' . number_format($shippingPrice, 2, ',', '.') . ' )';
|
| 341 |
+
$shippingPrice = 0;
|
| 342 |
}
|
| 343 |
|
| 344 |
+
if ($this->getConfigFlag('prazo_entrega')) {
|
| 345 |
+
if ($correiosDelivery > 0) {
|
| 346 |
+
$method->setMethodTitle(
|
| 347 |
+
sprintf(
|
| 348 |
+
$this->getConfigData('msgprazo'),
|
| 349 |
+
$shipping_data[0],
|
| 350 |
+
(int) ($correiosDelivery + $this->getConfigData('add_prazo'))
|
| 351 |
+
)
|
| 352 |
+
);
|
| 353 |
+
} else {
|
| 354 |
+
$method->setMethodTitle(
|
| 355 |
+
sprintf(
|
| 356 |
+
$this->getConfigData('msgprazo'),
|
| 357 |
+
$shipping_data[0],
|
| 358 |
+
(int) ($shipping_data[1] + $this->getConfigData('add_prazo'))
|
| 359 |
+
)
|
| 360 |
+
);
|
| 361 |
}
|
| 362 |
+
} else {
|
| 363 |
$method->setMethodTitle($shipping_data[0]);
|
| 364 |
}
|
| 365 |
|
| 366 |
$method->setPrice($shippingPrice);
|
| 367 |
$method->setCost($shippingCost);
|
| 368 |
|
| 369 |
+
if ($this->_freeMethodRequest === true) {
|
| 370 |
$this->_freeMethodRequestResult->append($method);
|
| 371 |
+
} else {
|
| 372 |
$this->_result->append($method);
|
| 373 |
}
|
| 374 |
}
|
| 376 |
/**
|
| 377 |
* Throw error
|
| 378 |
*
|
| 379 |
+
* @param string $message
|
| 380 |
+
* @param string $log
|
| 381 |
+
* @param string|int $line
|
| 382 |
+
* @param string $custom
|
|
|
|
| 383 |
*/
|
| 384 |
+
protected function _throwError($message, $log = null, $line = 'NO LINE', $custom = null)
|
| 385 |
+
{
|
| 386 |
$this->_result = null;
|
| 387 |
$this->_result = Mage::getModel('shipping/rate_result');
|
| 388 |
|
|
|
|
| 389 |
$error = Mage::getModel('shipping/rate_result_error');
|
| 390 |
$error->setCarrier($this->_code);
|
| 391 |
$error->setCarrierTitle($this->getConfigData('title'));
|
| 392 |
|
| 393 |
+
if (is_null($custom) || $this->getConfigData($message) == '') {
|
|
|
|
| 394 |
Mage::log($this->_code . ' [' . $line . ']: ' . $log);
|
| 395 |
$error->setErrorMessage($this->getConfigData($message));
|
| 396 |
+
} else {
|
|
|
|
| 397 |
Mage::log($this->_code . ' [' . $line . ']: ' . $log);
|
| 398 |
$error->setErrorMessage(sprintf($this->getConfigData($message), $custom));
|
| 399 |
+
}
|
| 400 |
|
|
|
|
| 401 |
$this->_result->append($error);
|
| 402 |
}
|
| 403 |
|
| 404 |
/**
|
| 405 |
* Generate Volume weight
|
| 406 |
*
|
| 407 |
+
* @see http://www.correios.com.br/para-sua-empresa/comercio-eletronico/como-calcular-precos-e-prazos-de-entrega-em-sua-loja-on-line
|
| 408 |
+
*
|
| 409 |
* @return bool
|
| 410 |
*/
|
| 411 |
+
protected function _generateVolumeWeight()
|
| 412 |
+
{
|
| 413 |
$pesoCubicoTotal = 0;
|
| 414 |
|
|
|
|
| 415 |
$items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
|
| 416 |
|
| 417 |
+
foreach ($items as $item) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
$_product = $item->getProduct();
|
| 419 |
|
| 420 |
+
if ($_product->getData('volume_altura') == '' || (int) $_product->getData('volume_altura') == 0) {
|
| 421 |
$itemAltura = $this->getConfigData('altura_padrao');
|
| 422 |
+
} else {
|
| 423 |
$itemAltura = $_product->getData('volume_altura');
|
| 424 |
+
}
|
| 425 |
|
| 426 |
+
if ($_product->getData('volume_largura') == '' || (int) $_product->getData('volume_largura') == 0) {
|
| 427 |
$itemLargura = $this->getConfigData('largura_padrao');
|
| 428 |
+
} else {
|
| 429 |
$itemLargura = $_product->getData('volume_largura');
|
| 430 |
+
}
|
| 431 |
|
| 432 |
+
if ($_product->getData('volume_comprimento') == '' || (int) $_product->getData('volume_comprimento') == 0) {
|
| 433 |
$itemComprimento = $this->getConfigData('comprimento_padrao');
|
| 434 |
+
} else {
|
| 435 |
$itemComprimento = $_product->getData('volume_comprimento');
|
| 436 |
+
}
|
| 437 |
|
| 438 |
+
if ($this->getConfigFlag('check_dimensions')) {
|
| 439 |
+
if ($itemAltura > $this->getConfigData('volume_validation/altura_max')
|
|
|
|
| 440 |
|| $itemAltura < $this->getConfigData('volume_validation/altura_min')
|
| 441 |
|| $itemLargura > $this->getConfigData('volume_validation/largura_max')
|
| 442 |
|| $itemLargura < $this->getConfigData('volume_validation/largura_min')
|
| 443 |
|| $itemComprimento > $this->getConfigData('volume_validation/comprimento_max')
|
| 444 |
|| $itemComprimento < $this->getConfigData('volume_validation/comprimento_min')
|
| 445 |
+
|| ($itemAltura + $itemLargura + $itemComprimento) > $this->getConfigData('volume_validation/sum_max')
|
| 446 |
+
|| ($itemAltura + $itemLargura + $itemComprimento) < $this->getConfigData('volume_validation/sum_min')
|
| 447 |
+
) {
|
| 448 |
return false;
|
| 449 |
}
|
| 450 |
}
|
| 451 |
|
| 452 |
+
$pesoCubicoTotal += (($itemAltura * $itemLargura * $itemComprimento) * $item->getQty()) / $this->getConfigData('coeficiente_volume');
|
| 453 |
}
|
| 454 |
|
| 455 |
$this->_volumeWeight = number_format($pesoCubicoTotal, 2, '.', '');
|
| 461 |
* Generate free shipping for a product
|
| 462 |
*
|
| 463 |
* @param string $freeMethod
|
| 464 |
+
*
|
| 465 |
* @return void
|
| 466 |
*/
|
| 467 |
protected function _setFreeMethodRequest($freeMethod)
|
| 468 |
{
|
| 469 |
+
$this->_freeMethodRequest = true;
|
|
|
|
| 470 |
$this->_freeMethodRequestResult = Mage::getModel('shipping/rate_result');
|
| 471 |
|
| 472 |
+
$this->_postMethods = $freeMethod;
|
| 473 |
+
$this->_postMethodsExplode = array($freeMethod);
|
| 474 |
|
| 475 |
+
if ($this->getConfigData('weight_type') == PedroTeixeira_Correios_Model_Source_WeightType::WEIGHT_GR) {
|
| 476 |
+
$this->_freeMethodWeight = number_format($this->_freeMethodWeight / 1000, 2, '.', '');
|
|
|
|
|
|
|
| 477 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
|
| 479 |
+
$this->_packageWeight = $this->_freeMethodWeight;
|
| 480 |
+
$this->_pacWeight = $this->_freeMethodWeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
}
|
| 482 |
|
|
|
|
| 483 |
/**
|
| 484 |
* Check if current carrier offer support to tracking
|
| 485 |
*
|
| 486 |
+
* @return bool true
|
| 487 |
*/
|
| 488 |
+
public function isTrackingAvailable()
|
| 489 |
+
{
|
| 490 |
return true;
|
| 491 |
}
|
| 492 |
|
| 494 |
* Get Tracking Info
|
| 495 |
*
|
| 496 |
* @param mixed $tracking
|
| 497 |
+
*
|
| 498 |
* @return mixed
|
| 499 |
*/
|
| 500 |
+
public function getTrackingInfo($tracking)
|
| 501 |
+
{
|
| 502 |
$result = $this->getTracking($tracking);
|
| 503 |
+
if ($result instanceof Mage_Shipping_Model_Tracking_Result) {
|
| 504 |
if ($trackings = $result->getAllTrackings()) {
|
| 505 |
+
return $trackings[0];
|
| 506 |
}
|
| 507 |
} elseif (is_string($result) && !empty($result)) {
|
| 508 |
return $result;
|
| 509 |
}
|
| 510 |
+
|
| 511 |
return false;
|
| 512 |
}
|
| 513 |
|
| 515 |
* Get Tracking
|
| 516 |
*
|
| 517 |
* @param array $trackings
|
| 518 |
+
*
|
| 519 |
* @return Mage_Shipping_Model_Tracking_Result
|
| 520 |
*/
|
| 521 |
+
public function getTracking($trackings)
|
| 522 |
+
{
|
| 523 |
$this->_result = Mage::getModel('shipping/tracking_result');
|
| 524 |
foreach ((array) $trackings as $code) {
|
| 525 |
$this->_getTracking($code);
|
| 526 |
}
|
| 527 |
+
|
| 528 |
return $this->_result;
|
| 529 |
}
|
| 530 |
|
| 532 |
* Protected Get Tracking, opens the request to Correios
|
| 533 |
*
|
| 534 |
* @param string $code
|
| 535 |
+
*
|
| 536 |
+
* @return bool
|
| 537 |
*/
|
| 538 |
+
protected function _getTracking($code)
|
| 539 |
+
{
|
| 540 |
$error = Mage::getModel('shipping/tracking_result_error');
|
| 541 |
$error->setTracking($code);
|
| 542 |
$error->setCarrier($this->_code);
|
| 549 |
$client = new Zend_Http_Client();
|
| 550 |
$client->setUri($url);
|
| 551 |
$content = $client->request();
|
| 552 |
+
$body = $content->getBody();
|
| 553 |
} catch (Exception $e) {
|
| 554 |
$this->_result->append($error);
|
| 555 |
return false;
|
| 571 |
$column = $columns[$i][1];
|
| 572 |
|
| 573 |
$description = '';
|
| 574 |
+
$found = false;
|
| 575 |
+
if (preg_match('/<td rowspan="?2"?/i', $column) && preg_match(
|
| 576 |
+
'/<td rowspan="?2"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i',
|
| 577 |
+
$column,
|
| 578 |
+
$matches
|
| 579 |
+
)
|
| 580 |
+
) {
|
| 581 |
+
if (preg_match('/<td colspan="?2"?>(.*)<\/td>/i', $columns[$i + 1][1], $matchesDescription)) {
|
| 582 |
$description = str_replace(' ', '', $matchesDescription[1]);
|
| 583 |
}
|
| 584 |
|
| 585 |
$found = true;
|
| 586 |
+
} elseif (preg_match(
|
| 587 |
+
'/<td rowspan="?1"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i',
|
| 588 |
+
$column,
|
| 589 |
+
$matches
|
| 590 |
+
)
|
| 591 |
+
) {
|
| 592 |
$found = true;
|
| 593 |
}
|
| 594 |
|
| 595 |
if ($found) {
|
| 596 |
$datetime = explode(' ', $matches[1]);
|
| 597 |
+
$locale = new Zend_Locale('pt_BR');
|
| 598 |
+
$date = '';
|
| 599 |
+
$date = new Zend_Date($datetime[0], 'dd/MM/YYYY', $locale);
|
| 600 |
|
| 601 |
$track = array(
|
| 602 |
+
'deliverydate' => $date->toString('YYYY-MM-dd'),
|
| 603 |
+
'deliverytime' => $datetime[1] . ':00',
|
| 604 |
+
'deliverylocation' => htmlentities($matches[2]),
|
| 605 |
+
'status' => htmlentities($matches[3]),
|
| 606 |
+
'activity' => htmlentities($matches[3])
|
| 607 |
+
);
|
| 608 |
|
| 609 |
if ($description !== '') {
|
| 610 |
$track['activity'] = $matches[3] . ' - ' . htmlentities($description);
|
| 615 |
}
|
| 616 |
|
| 617 |
if (!empty($progress)) {
|
| 618 |
+
$track = $progress[0];
|
| 619 |
$track['progressdetail'] = $progress;
|
| 620 |
|
| 621 |
$tracking = Mage::getModel('shipping/tracking_result_status');
|
| 645 |
/**
|
| 646 |
* Define ZIP Code as required
|
| 647 |
*
|
| 648 |
+
* @param string $countryId
|
| 649 |
+
*
|
| 650 |
+
* @return bool
|
| 651 |
*/
|
| 652 |
+
public function isZipCodeRequired($countryId = null)
|
| 653 |
{
|
| 654 |
return true;
|
| 655 |
}
|
app/code/community/PedroTeixeira/Correios/Model/Source/PostMethods.php
CHANGED
|
@@ -1,35 +1,31 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
-
*
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the New BSD License.
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://www.pteixeira.com.br/new-bsd-license/
|
| 10 |
*
|
| 11 |
-
* @category
|
| 12 |
-
* @package
|
| 13 |
-
* @copyright
|
| 14 |
-
* @author
|
| 15 |
-
* @license
|
| 16 |
*/
|
| 17 |
-
|
| 18 |
class PedroTeixeira_Correios_Model_Source_PostMethods
|
| 19 |
{
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
public function toOptionArray()
|
| 22 |
{
|
| 23 |
return array(
|
| 24 |
-
array('value'=>40010, 'label'=>Mage::helper('adminhtml')->__('Sedex Sem Contrato (40010)')),
|
| 25 |
-
array('value'=>40096, 'label'=>Mage::helper('adminhtml')->__('Sedex Com Contrato (40096)')),
|
| 26 |
-
array('value'=>81019, 'label'=>Mage::helper('adminhtml')->__('E-Sedex Com Contrato (81019)')),
|
| 27 |
-
array('value'=>41106, 'label'=>Mage::helper('adminhtml')->__('PAC Sem Contrato (41106)')),
|
| 28 |
-
array('value'=>41068, 'label'=>Mage::helper('adminhtml')->__('PAC Com Contrato (41068)')),
|
| 29 |
-
array('value'=>40215, 'label'=>Mage::helper('adminhtml')->__('Sedex 10 (40215)')),
|
| 30 |
-
array('value'=>40290, 'label'=>Mage::helper('adminhtml')->__('Sedex HOJE (40290)')),
|
| 31 |
-
array('value'=>40045, 'label'=>Mage::helper('adminhtml')->__('Sedex a Cobrar (40045)')),
|
| 32 |
);
|
| 33 |
}
|
| 34 |
-
|
| 35 |
}
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
| 12 |
*/
|
|
|
|
| 13 |
class PedroTeixeira_Correios_Model_Source_PostMethods
|
| 14 |
{
|
| 15 |
+
/**
|
| 16 |
+
* @return array
|
| 17 |
+
*/
|
| 18 |
public function toOptionArray()
|
| 19 |
{
|
| 20 |
return array(
|
| 21 |
+
array('value' => 40010, 'label' => Mage::helper('adminhtml')->__('Sedex Sem Contrato (40010)')),
|
| 22 |
+
array('value' => 40096, 'label' => Mage::helper('adminhtml')->__('Sedex Com Contrato (40096)')),
|
| 23 |
+
array('value' => 81019, 'label' => Mage::helper('adminhtml')->__('E-Sedex Com Contrato (81019)')),
|
| 24 |
+
array('value' => 41106, 'label' => Mage::helper('adminhtml')->__('PAC Sem Contrato (41106)')),
|
| 25 |
+
array('value' => 41068, 'label' => Mage::helper('adminhtml')->__('PAC Com Contrato (41068)')),
|
| 26 |
+
array('value' => 40215, 'label' => Mage::helper('adminhtml')->__('Sedex 10 (40215)')),
|
| 27 |
+
array('value' => 40290, 'label' => Mage::helper('adminhtml')->__('Sedex HOJE (40290)')),
|
| 28 |
+
array('value' => 40045, 'label' => Mage::helper('adminhtml')->__('Sedex a Cobrar (40045)')),
|
| 29 |
);
|
| 30 |
}
|
|
|
|
| 31 |
}
|
app/code/community/PedroTeixeira/Correios/Model/Source/WeightType.php
CHANGED
|
@@ -1,29 +1,31 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
-
*
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the New BSD License.
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://www.pteixeira.com.br/new-bsd-license/
|
| 10 |
*
|
| 11 |
-
* @category
|
| 12 |
-
* @package
|
| 13 |
-
* @copyright
|
| 14 |
-
* @author
|
| 15 |
-
* @license
|
| 16 |
*/
|
| 17 |
-
|
| 18 |
class PedroTeixeira_Correios_Model_Source_WeightType
|
| 19 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
public function toOptionArray()
|
| 22 |
{
|
| 23 |
return array(
|
| 24 |
-
array('value'=>
|
| 25 |
-
array('value'=>
|
| 26 |
);
|
| 27 |
}
|
| 28 |
-
|
| 29 |
}
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
| 12 |
*/
|
|
|
|
| 13 |
class PedroTeixeira_Correios_Model_Source_WeightType
|
| 14 |
{
|
| 15 |
+
/**
|
| 16 |
+
* Constants for weight
|
| 17 |
+
*/
|
| 18 |
+
const WEIGHT_GR = 'gr';
|
| 19 |
+
const WEIGHT_KG = 'kg';
|
| 20 |
|
| 21 |
+
/**
|
| 22 |
+
* @return array
|
| 23 |
+
*/
|
| 24 |
public function toOptionArray()
|
| 25 |
{
|
| 26 |
return array(
|
| 27 |
+
array('value' => self::WEIGHT_GR, 'label' => Mage::helper('adminhtml')->__('Gramas')),
|
| 28 |
+
array('value' => self::WEIGHT_KG, 'label' => Mage::helper('adminhtml')->__('Kilos')),
|
| 29 |
);
|
| 30 |
}
|
|
|
|
| 31 |
}
|
app/code/community/PedroTeixeira/Correios/etc/config.xml
CHANGED
|
@@ -1,19 +1,14 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
-
*
|
|
|
|
| 5 |
*
|
| 6 |
-
*
|
| 7 |
-
*
|
| 8 |
-
*
|
| 9 |
-
*
|
| 10 |
-
* http://
|
| 11 |
-
*
|
| 12 |
-
* @category PedroTeixeira
|
| 13 |
-
* @package PedroTeixeira_Correios
|
| 14 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 15 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 16 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 17 |
*/
|
| 18 |
-->
|
| 19 |
<config>
|
|
@@ -21,7 +16,7 @@
|
|
| 21 |
<PedroTeixeira_Correios>
|
| 22 |
<version>4.2.0</version>
|
| 23 |
<depends>
|
| 24 |
-
<Mage_Shipping
|
| 25 |
</depends>
|
| 26 |
</PedroTeixeira_Correios>
|
| 27 |
</modules>
|
|
@@ -37,11 +32,11 @@
|
|
| 37 |
</item>
|
| 38 |
</quote>
|
| 39 |
</sales>
|
| 40 |
-
|
| 41 |
<pedroteixeira_correios>
|
| 42 |
<class>PedroTeixeira_Correios_Model</class>
|
| 43 |
</pedroteixeira_correios>
|
| 44 |
-
|
| 45 |
<resources>
|
| 46 |
<pedroteixeira_correios_setup>
|
| 47 |
<setup>
|
|
@@ -76,7 +71,7 @@
|
|
| 76 |
<model>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</model>
|
| 77 |
<title>Correios</title>
|
| 78 |
<postmethods>40010</postmethods>
|
| 79 |
-
<
|
| 80 |
<prazo_entrega>0</prazo_entrega>
|
| 81 |
<check_dimensions>1</check_dimensions>
|
| 82 |
<min_order_value>0</min_order_value>
|
|
@@ -98,15 +93,16 @@
|
|
| 98 |
<comprimento_sent>16</comprimento_sent>
|
| 99 |
<largura_sent>11</largura_sent>
|
| 100 |
|
| 101 |
-
<!-- http://
|
| 102 |
<volume_validation>
|
| 103 |
-
<altura_max>
|
| 104 |
<altura_min>2</altura_min>
|
| 105 |
-
<comprimento_max>
|
| 106 |
<comprimento_min>16</comprimento_min>
|
| 107 |
-
<largura_max>
|
| 108 |
<largura_min>11</largura_min>
|
| 109 |
-
<sum_max>
|
|
|
|
| 110 |
</volume_validation>
|
| 111 |
|
| 112 |
<!-- CONFIG -->
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
*/
|
| 13 |
-->
|
| 14 |
<config>
|
| 16 |
<PedroTeixeira_Correios>
|
| 17 |
<version>4.2.0</version>
|
| 18 |
<depends>
|
| 19 |
+
<Mage_Shipping/>
|
| 20 |
</depends>
|
| 21 |
</PedroTeixeira_Correios>
|
| 22 |
</modules>
|
| 32 |
</item>
|
| 33 |
</quote>
|
| 34 |
</sales>
|
| 35 |
+
<models>
|
| 36 |
<pedroteixeira_correios>
|
| 37 |
<class>PedroTeixeira_Correios_Model</class>
|
| 38 |
</pedroteixeira_correios>
|
| 39 |
+
</models>
|
| 40 |
<resources>
|
| 41 |
<pedroteixeira_correios_setup>
|
| 42 |
<setup>
|
| 71 |
<model>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</model>
|
| 72 |
<title>Correios</title>
|
| 73 |
<postmethods>40010</postmethods>
|
| 74 |
+
<soft_errors>009,010,011</soft_errors>
|
| 75 |
<prazo_entrega>0</prazo_entrega>
|
| 76 |
<check_dimensions>1</check_dimensions>
|
| 77 |
<min_order_value>0</min_order_value>
|
| 93 |
<comprimento_sent>16</comprimento_sent>
|
| 94 |
<largura_sent>11</largura_sent>
|
| 95 |
|
| 96 |
+
<!-- http://www2.correios.com.br/sistemas/precosprazos/Formato.cfm -->
|
| 97 |
<volume_validation>
|
| 98 |
+
<altura_max>105</altura_max>
|
| 99 |
<altura_min>2</altura_min>
|
| 100 |
+
<comprimento_max>105</comprimento_max>
|
| 101 |
<comprimento_min>16</comprimento_min>
|
| 102 |
+
<largura_max>105</largura_max>
|
| 103 |
<largura_min>11</largura_min>
|
| 104 |
+
<sum_max>200</sum_max>
|
| 105 |
+
<sum_min>29</sum_min>
|
| 106 |
</volume_validation>
|
| 107 |
|
| 108 |
<!-- CONFIG -->
|
app/code/community/PedroTeixeira/Correios/etc/system.xml
CHANGED
|
@@ -1,19 +1,14 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
-
*
|
|
|
|
| 5 |
*
|
| 6 |
-
*
|
| 7 |
-
*
|
| 8 |
-
*
|
| 9 |
-
*
|
| 10 |
-
* http://
|
| 11 |
-
*
|
| 12 |
-
* @category PedroTeixeira
|
| 13 |
-
* @package PedroTeixeira_Correios
|
| 14 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 15 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 16 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 17 |
*/
|
| 18 |
-->
|
| 19 |
<config>
|
|
@@ -30,21 +25,15 @@
|
|
| 30 |
<comment>
|
| 31 |
<![CDATA[
|
| 32 |
<div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
-
<a href="http://www.pteixeira.com.br/" target="_blank">www.pteixeira.com.br</a>.<br /><br />
|
| 37 |
-
Na versão <b>4.2.0</b> o módulo de cálculo de frete foi atualizado para utilizar a nova
|
| 38 |
-
lógica de cálculo de peso volumétrico para todos os serviços, teve sua licença
|
| 39 |
-
alterada para <a href="http://www.pteixeira.com.br/new-bsd-license/" target="_blank">New BSD</a>,
|
| 40 |
-
possibilidade de utilizar limites de dimensões dos Correios, retirada da URL de cálculo da
|
| 41 |
-
Locaweb além de outras correções e melhorias.<br /><br />
|
| 42 |
-
Lembre-se de configurar as "Definições de Envio" no menu ao lado esquerdo.<br /><br />
|
| 43 |
-
Para serviços que tenham em seu nome "Com Contrato", é necessário configurar o "Código
|
| 44 |
-
Administrativo dos Correios" e "Senha Administrativa dos Correios".<br /><br />
|
| 45 |
-
Para utilizar as regras de desconto de frete, você deve configurar o "Serviço para entrega gratuita",
|
| 46 |
-
lembre-se de habilitar o serviço.<br /><br />
|
| 47 |
-
<hr /><br /><br />
|
| 48 |
</div>
|
| 49 |
]]>
|
| 50 |
</comment>
|
|
@@ -75,7 +64,9 @@
|
|
| 75 |
<show_in_website>1</show_in_website>
|
| 76 |
<show_in_store>1</show_in_store>
|
| 77 |
<comment>Formato do peso dos produtos.</comment>
|
| 78 |
-
<tooltip>O formato do peso irá implicar na maneira como o mesmo é cadastrado no produto, por
|
|
|
|
|
|
|
| 79 |
</weight_type>
|
| 80 |
<postmethods translate="label">
|
| 81 |
<label>Serviços</label>
|
|
@@ -85,7 +76,9 @@
|
|
| 85 |
<show_in_default>1</show_in_default>
|
| 86 |
<show_in_website>1</show_in_website>
|
| 87 |
<show_in_store>1</show_in_store>
|
| 88 |
-
<comment>Serviços que estarão disponíveis, lembre-se de usar os serviços correspondentes a
|
|
|
|
|
|
|
| 89 |
</postmethods>
|
| 90 |
<free_method translate="label">
|
| 91 |
<label>Serviço Para Entrega Gratuita</label>
|
|
@@ -96,8 +89,10 @@
|
|
| 96 |
<show_in_default>1</show_in_default>
|
| 97 |
<show_in_website>1</show_in_website>
|
| 98 |
<show_in_store>1</show_in_store>
|
| 99 |
-
<comment>Quando usar um cupom oferecendo frete gratuito, qual serviço será gratuito.
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
<cod_admin translate="label">
|
| 102 |
<label>Código Administrativo dos Correios (Serviços Com Contrato)</label>
|
| 103 |
<frontend_type>text</frontend_type>
|
|
@@ -131,8 +126,11 @@
|
|
| 131 |
<show_in_default>1</show_in_default>
|
| 132 |
<show_in_website>1</show_in_website>
|
| 133 |
<show_in_store>1</show_in_store>
|
| 134 |
-
<tooltip>"%s" para o nome do serviço, por exemplo "Sedex", "%d" para o número de dias
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 136 |
</msgprazo>
|
| 137 |
<mao_propria translate="label">
|
| 138 |
<label>Utilizar Serviço de Mão Própria</label>
|
|
@@ -169,7 +167,8 @@
|
|
| 169 |
<show_in_default>1</show_in_default>
|
| 170 |
<show_in_website>1</show_in_website>
|
| 171 |
<show_in_store>1</show_in_store>
|
| 172 |
-
<comment
|
|
|
|
| 173 |
</check_dimensions>
|
| 174 |
<altura_padrao translate="label">
|
| 175 |
<label>Altura Padrão (cm)</label>
|
|
@@ -178,7 +177,8 @@
|
|
| 178 |
<show_in_default>1</show_in_default>
|
| 179 |
<show_in_website>1</show_in_website>
|
| 180 |
<show_in_store>1</show_in_store>
|
| 181 |
-
<comment
|
|
|
|
| 182 |
</altura_padrao>
|
| 183 |
<comprimento_padrao translate="label">
|
| 184 |
<label>Comprimento Padrão (cm)</label>
|
|
@@ -187,7 +187,8 @@
|
|
| 187 |
<show_in_default>1</show_in_default>
|
| 188 |
<show_in_website>1</show_in_website>
|
| 189 |
<show_in_store>1</show_in_store>
|
| 190 |
-
<comment
|
|
|
|
| 191 |
</comprimento_padrao>
|
| 192 |
<largura_padrao translate="label">
|
| 193 |
<label>Largura Padrão (cm)</label>
|
|
@@ -196,7 +197,8 @@
|
|
| 196 |
<show_in_default>1</show_in_default>
|
| 197 |
<show_in_website>1</show_in_website>
|
| 198 |
<show_in_store>1</show_in_store>
|
| 199 |
-
<comment
|
|
|
|
| 200 |
</largura_padrao>
|
| 201 |
<min_order_value translate="label">
|
| 202 |
<label>Valor Mínimo de Compra</label>
|
|
@@ -313,7 +315,9 @@
|
|
| 313 |
<show_in_default>1</show_in_default>
|
| 314 |
<show_in_website>1</show_in_website>
|
| 315 |
<show_in_store>1</show_in_store>
|
| 316 |
-
<comment>Se houver um erro ou o método não for aplicável naquela situação, mesmo assim
|
|
|
|
|
|
|
| 317 |
</showmethod>
|
| 318 |
<sort_order translate="label">
|
| 319 |
<label>Ordenar Por</label>
|
|
@@ -322,7 +326,7 @@
|
|
| 322 |
<show_in_default>1</show_in_default>
|
| 323 |
<show_in_website>1</show_in_website>
|
| 324 |
<show_in_store>1</show_in_store>
|
| 325 |
-
</sort_order>
|
| 326 |
</fields>
|
| 327 |
</pedroteixeira_correios>
|
| 328 |
</groups>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
*/
|
| 13 |
-->
|
| 14 |
<config>
|
| 25 |
<comment>
|
| 26 |
<![CDATA[
|
| 27 |
<div>
|
| 28 |
+
<h3>Informações Importantes</h3>
|
| 29 |
+
<p>Para reportar bugs ou sugerir melhorias, por favor use o <a href="https://github.com/pedro-teixeira/correios" target="_blank">GitHub</a>.</p>
|
| 30 |
+
<p>Lembre-se de configurar as "Definições de Envio" no menu ao lado esquerdo.</p>
|
| 31 |
+
<p>Para serviços que tenham em seu nome "Com Contrato", é necessário configurar o "Código Administrativo dos Correios" e "Senha Administrativa dos Correios".</p>
|
| 32 |
+
<p>Para utilizar as regras de desconto de frete, você deve configurar o "Serviço para entrega gratuita", lembre-se de habilitar o serviço.</p>
|
| 33 |
+
<p>Pedro Teixeira [<a href="http://pedroteixeira.io/" target="_blank">pedroteixeira.io</a> ]</p>
|
| 34 |
+
<br />
|
| 35 |
+
<hr />
|
| 36 |
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
</div>
|
| 38 |
]]>
|
| 39 |
</comment>
|
| 64 |
<show_in_website>1</show_in_website>
|
| 65 |
<show_in_store>1</show_in_store>
|
| 66 |
<comment>Formato do peso dos produtos.</comment>
|
| 67 |
+
<tooltip>O formato do peso irá implicar na maneira como o mesmo é cadastrado no produto, por
|
| 68 |
+
exemplo, 1 Kg no formato "Kilo" será "1.000", já em "Gramas" será "1000.000".
|
| 69 |
+
</tooltip>
|
| 70 |
</weight_type>
|
| 71 |
<postmethods translate="label">
|
| 72 |
<label>Serviços</label>
|
| 76 |
<show_in_default>1</show_in_default>
|
| 77 |
<show_in_website>1</show_in_website>
|
| 78 |
<show_in_store>1</show_in_store>
|
| 79 |
+
<comment>Serviços que estarão disponíveis, lembre-se de usar os serviços correspondentes a
|
| 80 |
+
fonte configurada.
|
| 81 |
+
</comment>
|
| 82 |
</postmethods>
|
| 83 |
<free_method translate="label">
|
| 84 |
<label>Serviço Para Entrega Gratuita</label>
|
| 89 |
<show_in_default>1</show_in_default>
|
| 90 |
<show_in_website>1</show_in_website>
|
| 91 |
<show_in_store>1</show_in_store>
|
| 92 |
+
<comment>Quando usar um cupom oferecendo frete gratuito, qual serviço será gratuito.
|
| 93 |
+
Lembre-se de habilitar o serviço.
|
| 94 |
+
</comment>
|
| 95 |
+
</free_method>
|
| 96 |
<cod_admin translate="label">
|
| 97 |
<label>Código Administrativo dos Correios (Serviços Com Contrato)</label>
|
| 98 |
<frontend_type>text</frontend_type>
|
| 126 |
<show_in_default>1</show_in_default>
|
| 127 |
<show_in_website>1</show_in_website>
|
| 128 |
<show_in_store>1</show_in_store>
|
| 129 |
+
<tooltip>"%s" para o nome do serviço, por exemplo "Sedex", "%d" para o número de dias.
|
| 130 |
+
</tooltip>
|
| 131 |
+
<depends>
|
| 132 |
+
<prazo_entrega>1</prazo_entrega>
|
| 133 |
+
</depends>
|
| 134 |
</msgprazo>
|
| 135 |
<mao_propria translate="label">
|
| 136 |
<label>Utilizar Serviço de Mão Própria</label>
|
| 167 |
<show_in_default>1</show_in_default>
|
| 168 |
<show_in_website>1</show_in_website>
|
| 169 |
<show_in_store>1</show_in_store>
|
| 170 |
+
<comment>
|
| 171 |
+
<![CDATA[Ao habilitar essa funcionalidade cada produto será validado seguindo a regra de dimensões dos Correios.<br />A regra pode ser encontrada <a href="http://www2.correios.com.br/sistemas/precosprazos/Formato.cfm" target="_blank">nesse link</a>.]]></comment>
|
| 172 |
</check_dimensions>
|
| 173 |
<altura_padrao translate="label">
|
| 174 |
<label>Altura Padrão (cm)</label>
|
| 177 |
<show_in_default>1</show_in_default>
|
| 178 |
<show_in_website>1</show_in_website>
|
| 179 |
<show_in_store>1</show_in_store>
|
| 180 |
+
<comment>
|
| 181 |
+
<![CDATA[Quando não configurada no produto será usada.<br />Mínimo de 2 cm.]]></comment>
|
| 182 |
</altura_padrao>
|
| 183 |
<comprimento_padrao translate="label">
|
| 184 |
<label>Comprimento Padrão (cm)</label>
|
| 187 |
<show_in_default>1</show_in_default>
|
| 188 |
<show_in_website>1</show_in_website>
|
| 189 |
<show_in_store>1</show_in_store>
|
| 190 |
+
<comment>
|
| 191 |
+
<![CDATA[Quando não configurado no produto será usado.<br />Mínimo de 16 cm.]]></comment>
|
| 192 |
</comprimento_padrao>
|
| 193 |
<largura_padrao translate="label">
|
| 194 |
<label>Largura Padrão (cm)</label>
|
| 197 |
<show_in_default>1</show_in_default>
|
| 198 |
<show_in_website>1</show_in_website>
|
| 199 |
<show_in_store>1</show_in_store>
|
| 200 |
+
<comment>
|
| 201 |
+
<![CDATA[Quando não configurada no produto será usada.<br />Mínimo de 11 cm.]]></comment>
|
| 202 |
</largura_padrao>
|
| 203 |
<min_order_value translate="label">
|
| 204 |
<label>Valor Mínimo de Compra</label>
|
| 315 |
<show_in_default>1</show_in_default>
|
| 316 |
<show_in_website>1</show_in_website>
|
| 317 |
<show_in_store>1</show_in_store>
|
| 318 |
+
<comment>Se houver um erro ou o método não for aplicável naquela situação, mesmo assim
|
| 319 |
+
mostrar as mensagens de erro?
|
| 320 |
+
</comment>
|
| 321 |
</showmethod>
|
| 322 |
<sort_order translate="label">
|
| 323 |
<label>Ordenar Por</label>
|
| 326 |
<show_in_default>1</show_in_default>
|
| 327 |
<show_in_website>1</show_in_website>
|
| 328 |
<show_in_store>1</show_in_store>
|
| 329 |
+
</sort_order>
|
| 330 |
</fields>
|
| 331 |
</pedroteixeira_correios>
|
| 332 |
</groups>
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.0.0.php
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
+
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
/** @var $installer Mage_Core_Model_Resource_Setup */
|
| 15 |
+
$installer = $this;
|
| 16 |
+
$installer->startSetup();
|
| 17 |
+
|
| 18 |
+
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
|
| 19 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 20 |
+
|
| 21 |
+
// Add volume to prduct attribute set
|
| 22 |
+
$codigo = 'volume_comprimento';
|
| 23 |
+
$config = array(
|
| 24 |
+
'position' => 1,
|
| 25 |
+
'required' => 0,
|
| 26 |
+
'label' => 'Comprimento (cm)',
|
| 27 |
+
'type' => 'int',
|
| 28 |
+
'input' => 'text',
|
| 29 |
+
'apply_to' => 'simple,bundle,grouped,configurable',
|
| 30 |
+
'note' => 'Comprimento da embalagem do produto (Para cálculo de PAC, mínimo de 16)'
|
| 31 |
+
);
|
| 32 |
+
|
| 33 |
+
$setup->addAttribute('catalog_product', $codigo, $config);
|
| 34 |
+
|
| 35 |
+
// Add volume to prduct attribute set
|
| 36 |
+
$codigo = 'volume_altura';
|
| 37 |
+
$config = array(
|
| 38 |
+
'position' => 1,
|
| 39 |
+
'required' => 0,
|
| 40 |
+
'label' => 'Altura (cm)',
|
| 41 |
+
'type' => 'int',
|
| 42 |
+
'input' => 'text',
|
| 43 |
+
'apply_to' => 'simple,bundle,grouped,configurable',
|
| 44 |
+
'note' => 'Altura da embalagem do produto (Para cálculo de PAC, mínimo de 2)'
|
| 45 |
+
);
|
| 46 |
+
|
| 47 |
+
$setup->addAttribute('catalog_product', $codigo, $config);
|
| 48 |
+
|
| 49 |
+
// Add volume to prduct attribute set
|
| 50 |
+
$codigo = 'volume_largura';
|
| 51 |
+
$config = array(
|
| 52 |
+
'position' => 1,
|
| 53 |
+
'required' => 0,
|
| 54 |
+
'label' => 'Largura (cm)',
|
| 55 |
+
'type' => 'int',
|
| 56 |
+
'input' => 'text',
|
| 57 |
+
'apply_to' => 'simple,bundle,grouped,configurable',
|
| 58 |
+
'note' => 'Largura da embalagem do produto (Para cálculo de PAC, mínimo de 11)'
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
$setup->addAttribute('catalog_product', $codigo, $config);
|
| 62 |
+
|
| 63 |
+
$installer->endSetup();
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-install-4.0.0.php
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Pedro Teixeira
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the New BSD License.
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://www.pteixeira.com.br/new-bsd-license/
|
| 10 |
-
*
|
| 11 |
-
* @category PedroTeixeira
|
| 12 |
-
* @package PedroTeixeira_Correios
|
| 13 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 14 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 15 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 16 |
-
*/
|
| 17 |
-
|
| 18 |
-
$installer = $this;
|
| 19 |
-
|
| 20 |
-
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
|
| 21 |
-
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 22 |
-
|
| 23 |
-
$installer->startSetup();
|
| 24 |
-
|
| 25 |
-
// Add volume to prduct attribute set
|
| 26 |
-
$codigo = 'volume_comprimento';
|
| 27 |
-
$config = array(
|
| 28 |
-
'position' => 1,
|
| 29 |
-
'required'=> 0,
|
| 30 |
-
'label' => 'Comprimento (cm)',
|
| 31 |
-
'type' => 'int',
|
| 32 |
-
'input'=>'text',
|
| 33 |
-
'apply_to'=>'simple,bundle,grouped,configurable',
|
| 34 |
-
'note'=>'Comprimento da embalagem do produto (Para cálculo de PAC, mínimo de 16)'
|
| 35 |
-
);
|
| 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,
|
| 43 |
-
'required'=> 0,
|
| 44 |
-
'label' => 'Altura (cm)',
|
| 45 |
-
'type' => 'int',
|
| 46 |
-
'input'=>'text',
|
| 47 |
-
'apply_to'=>'simple,bundle,grouped,configurable',
|
| 48 |
-
'note'=>'Altura da embalagem do produto (Para cálculo de PAC, mínimo de 2)'
|
| 49 |
-
);
|
| 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,
|
| 57 |
-
'required'=> 0,
|
| 58 |
-
'label' => 'Largura (cm)',
|
| 59 |
-
'type' => 'int',
|
| 60 |
-
'input'=>'text',
|
| 61 |
-
'apply_to'=>'simple,bundle,grouped,configurable',
|
| 62 |
-
'note'=>'Largura da embalagem do produto (Para cálculo de PAC, mínimo de 11)'
|
| 63 |
-
);
|
| 64 |
-
|
| 65 |
-
$setup->addAttribute('catalog_product', $codigo , $config);
|
| 66 |
-
|
| 67 |
-
$installer->endSetup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/mysql4-upgrade-4.1.0-4.2.0.php
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Pedro Teixeira
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the New BSD License.
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://www.pteixeira.com.br/new-bsd-license/
|
| 10 |
-
*
|
| 11 |
-
* @category PedroTeixeira
|
| 12 |
-
* @package PedroTeixeira_Correios
|
| 13 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 14 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 15 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 16 |
-
*/
|
| 17 |
-
|
| 18 |
-
$installer = $this;
|
| 19 |
-
$installer->startSetup();
|
| 20 |
-
$connection = $installer->getConnection();
|
| 21 |
-
|
| 22 |
-
$installer->deleteConfigData('carriers/pedroteixeira_correios/urlmethod');
|
| 23 |
-
|
| 24 |
-
$sql = "select value from ".$installer->getTable('core/config_data')." where path='carriers/pedroteixeira_correios/postmethods'";
|
| 25 |
-
$methods = explode(',', $connection->fetchOne($sql));
|
| 26 |
-
foreach($methods as $key => $method){
|
| 27 |
-
if($method == '41025'){
|
| 28 |
-
unset($methods[$key]);
|
| 29 |
-
}
|
| 30 |
-
}
|
| 31 |
-
if(count($methods) <= 0){
|
| 32 |
-
$methods[] = '41106';
|
| 33 |
-
}
|
| 34 |
-
$installer->setConfigData('carriers/pedroteixeira_correios/postmethods', implode(',', $methods));
|
| 35 |
-
|
| 36 |
-
$sql = "select value from ".$installer->getTable('core/config_data')." where path='carriers/pedroteixeira_correios/free_method'";
|
| 37 |
-
if($connection->fetchOne($sql) == '41025'){
|
| 38 |
-
$installer->setConfigData('carriers/pedroteixeira_correios/free_method', '41106');
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 42 |
-
$setup->updateAttribute('catalog_product', 'volume_comprimento', 'note', 'Comprimento da embalagem do produto (Para cálculo dos Correios)');
|
| 43 |
-
$setup->updateAttribute('catalog_product', 'volume_altura', 'note', 'Altura da embalagem do produto (Para cálculo dos Correios)');
|
| 44 |
-
$setup->updateAttribute('catalog_product', 'volume_largura', 'note', 'Largura da embalagem do produto (Para cálculo dos Correios)');
|
| 45 |
-
|
| 46 |
-
$installer->endSetup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/{mysql4-upgrade-4.0.0-4.1.0.php → upgrade-4.0.0-4.1.0.php}
RENAMED
|
@@ -1,20 +1,17 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
-
*
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the New BSD License.
|
| 8 |
-
* It is also available through the world-wide-web at this URL:
|
| 9 |
-
* http://www.pteixeira.com.br/new-bsd-license/
|
| 10 |
*
|
| 11 |
-
* @category
|
| 12 |
-
* @package
|
| 13 |
-
* @copyright
|
| 14 |
-
* @author
|
| 15 |
-
* @license
|
| 16 |
*/
|
| 17 |
|
|
|
|
| 18 |
$installer = $this;
|
| 19 |
$installer->startSetup();
|
| 20 |
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
| 12 |
*/
|
| 13 |
|
| 14 |
+
/** @var $installer Mage_Core_Model_Resource_Setup */
|
| 15 |
$installer = $this;
|
| 16 |
$installer->startSetup();
|
| 17 |
|
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.1.0-4.2.0.php
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
+
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
/** @var $installer Mage_Core_Model_Resource_Setup */
|
| 15 |
+
$installer = $this;
|
| 16 |
+
$installer->startSetup();
|
| 17 |
+
$connection = $installer->getConnection();
|
| 18 |
+
|
| 19 |
+
$installer->deleteConfigData('carriers/pedroteixeira_correios/urlmethod');
|
| 20 |
+
|
| 21 |
+
$sql = 'select value from ' . $installer->getTable('core/config_data') . ' where path="carriers/pedroteixeira_correios/postmethods"';
|
| 22 |
+
|
| 23 |
+
$methods = explode(',', $connection->fetchOne($sql));
|
| 24 |
+
|
| 25 |
+
foreach ($methods as $key => $method) {
|
| 26 |
+
if ($method == '41025') {
|
| 27 |
+
unset($methods[$key]);
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
if (count($methods) <= 0) {
|
| 32 |
+
$methods[] = '41106';
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
$installer->setConfigData('carriers/pedroteixeira_correios/postmethods', implode(',', $methods));
|
| 36 |
+
|
| 37 |
+
$sql = 'select value from ' . $installer->getTable('core/config_data') . ' where path="carriers/pedroteixeira_correios/free_method"';
|
| 38 |
+
|
| 39 |
+
if ($connection->fetchOne($sql) == '41025') {
|
| 40 |
+
$installer->setConfigData('carriers/pedroteixeira_correios/free_method', '41106');
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 44 |
+
|
| 45 |
+
$setup->updateAttribute(
|
| 46 |
+
'catalog_product',
|
| 47 |
+
'volume_comprimento',
|
| 48 |
+
'note',
|
| 49 |
+
'Comprimento da embalagem do produto (Para cálculo dos Correios)'
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
$setup->updateAttribute(
|
| 53 |
+
'catalog_product',
|
| 54 |
+
'volume_altura',
|
| 55 |
+
'note',
|
| 56 |
+
'Altura da embalagem do produto (Para cálculo dos Correios)'
|
| 57 |
+
);
|
| 58 |
+
|
| 59 |
+
$setup->updateAttribute(
|
| 60 |
+
'catalog_product',
|
| 61 |
+
'volume_largura',
|
| 62 |
+
'note',
|
| 63 |
+
'Largura da embalagem do produto (Para cálculo dos Correios)'
|
| 64 |
+
);
|
| 65 |
+
|
| 66 |
+
$installer->endSetup();
|
app/etc/modules/PedroTeixeira_Correios.xml
CHANGED
|
@@ -1,19 +1,14 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
-
*
|
|
|
|
| 5 |
*
|
| 6 |
-
*
|
| 7 |
-
*
|
| 8 |
-
*
|
| 9 |
-
*
|
| 10 |
-
* http://
|
| 11 |
-
*
|
| 12 |
-
* @category PedroTeixeira
|
| 13 |
-
* @package PedroTeixeira_Correios
|
| 14 |
-
* @copyright Copyright (c) 2011 Pedro Teixeira (http://www.pteixeira.com.br)
|
| 15 |
-
* @author Pedro Teixeira <pedro@pteixeira.com.br>
|
| 16 |
-
* @license http://www.pteixeira.com.br/new-bsd-license/ New BSD License
|
| 17 |
*/
|
| 18 |
-->
|
| 19 |
<config>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
+
* This source file is subject to the MIT License.
|
| 5 |
+
* It is also available through http://opensource.org/licenses/MIT
|
| 6 |
*
|
| 7 |
+
* @category PedroTeixeira
|
| 8 |
+
* @package PedroTeixeira_Correios
|
| 9 |
+
* @copyright Copyright (c) 2014 Pedro Teixeira (http://pedroteixeira.io)
|
| 10 |
+
* @author Pedro Teixeira <hello@pedroteixeira.io>
|
| 11 |
+
* @license http://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
*/
|
| 13 |
-->
|
| 14 |
<config>
|
package.xml
CHANGED
|
@@ -1,35 +1,44 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>PedroTeixeira_Correios</name>
|
| 4 |
-
<version>4.
|
| 5 |
<stability>stable</stability>
|
| 6 |
-
<license uri="http://www.
|
| 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.
|
| 11 |
-
|
| 12 |
-
Utilizando peso volumétrico para cálculo de todos os serviços e compatível com a validação de dimensões dos Correios
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
- Sedex Sem Contrato
|
| 17 |
-
- Sedex Com Contrato
|
| 18 |
-
- E-Sedex Com Contrato
|
| 19 |
-
- PAC Sem Contrato
|
| 20 |
-
- PAC Com Contrato
|
| 21 |
-
- Sedex 10
|
| 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 |
-
Mais informações em http://
|
| 28 |
-
<notes>
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
<compatible/>
|
| 34 |
-
<dependencies
|
| 35 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>PedroTeixeira_Correios</name>
|
| 4 |
+
<version>4.3.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT License</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.3.0 do módulo de cálculo de frete para Magento.
|
| 11 |
+

|
| 12 |
+
Utilizando peso volumétrico para cálculo de todos os serviços e compatível com a validação de dimensões dos Correios. 
|
| 13 |
+

|
| 14 |
+
Serviços suportados:
|
| 15 |
+

|
| 16 |
+
- Sedex Sem Contrato
|
| 17 |
+
- Sedex Com Contrato
|
| 18 |
+
- E-Sedex Com Contrato
|
| 19 |
+
- PAC Sem Contrato
|
| 20 |
+
- PAC Com Contrato
|
| 21 |
+
- Sedex 10
|
| 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 |
+
Mais informações em http://pedroteixeira.io</description>
|
| 28 |
+
<notes>Bugfix:
|
| 29 |
+

|
| 30 |
+
- Assinatura do método isZipCodeRequired() foi alterada
|
| 31 |
+

|
| 32 |
+
Feature:
|
| 33 |
+

|
| 34 |
+
- Revisão do code style
|
| 35 |
+
- Documentação em markdown
|
| 36 |
+
- Novos códigos de erros dos Correios
|
| 37 |
+
- Novos limites de dimensão dos Correios</notes>
|
| 38 |
+
<authors><author><name>Pedro Teixeira</name><user>teixeirapedro</user><email>hello@pedroteixeira.io</email></author></authors>
|
| 39 |
+
<date>2014-08-03</date>
|
| 40 |
+
<time>22:56:30</time>
|
| 41 |
+
<contents><target name="magecommunity"><dir name="PedroTeixeira"><dir name="Correios"><dir name="Helper"><file name="Data.php" hash="3cad79e9b6499ad762d5b52cffc309b8"/></dir><dir name="Model"><dir name="Carrier"><file name="CorreiosMethod.php" hash="9b72318b51409857321ed524b75e6641"/></dir><dir name="Source"><file name="PostMethods.php" hash="ae6eff9ea069080f6a77e19a37290887"/><file name="WeightType.php" hash="e49300e3836905862ae19e9add86bf96"/></dir></dir><dir name="etc"><file name="config.xml" hash="796ef0d67c95af6a2c7c557ead7e659d"/><file name="system.xml" hash="87bf5a7eb8f7231df063453968f82c8b"/></dir><dir name="sql"><dir name="pedroteixeira_correios_setup"><file name="install-4.0.0.php" hash="63f35dbcdcae0d1430afc2afdd51ab97"/><file name="upgrade-4.0.0-4.1.0.php" hash="0734387a4591ef680cea2c2148e04582"/><file name="upgrade-4.1.0-4.2.0.php" hash="a075e89ea6ced350b18eeae9e9ec7eaf"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PedroTeixeira_Correios.xml" hash="f49af429aed120dbb234cf0c0a99377d"/></dir></target></contents>
|
| 42 |
<compatible/>
|
| 43 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 44 |
</package>
|
