PedroTeixeira_Correios - Version 4.4.0

Version Notes

Bugfix:

- Usar atributo para setar o carrier name e passar o encoding para htmlentities
- Erro 99 Input string was not in a correct format
- Peso cúbico não calculado no backend
- Corrige a leitura do valor de frete
- Frete de mil reais exibido por 1 real
- Problema com peso do E-SEDEX

Feature:

- Adiciona CONTRIBUTING.md
- Adiciona badges
- Integração com Travis
- Testado em Magento 1.9.1.0
- Serviços por produto, validação por serviço, grandes formatos, carta registrada, cache
- Considerar produtos encaixados
- Adicionar PAC grandes formatos aos serviços de postagem
- Validação de peso e dimensões
- Selecionar serviços por produto
- Suporte para instalações modman
- Integrar carta registrada
- Implementar cache de respostas dos Correios
- Opção de dividir a entrega em mais de um pacote

Download this release

Release Info

Developer Pedro Teixeira
Extension PedroTeixeira_Correios
Version 4.4.0
Comparing to
See all releases


Code changes from version 4.3.0 to 4.4.0

app/code/community/PedroTeixeira/Correios/Helper/Data.php CHANGED
@@ -6,9 +6,10 @@
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
  {
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
  class PedroTeixeira_Correios_Helper_Data extends Mage_Core_Helper_Abstract
15
  {
app/code/community/PedroTeixeira/Correios/Model/Cache.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
+ */
14
+ class PedroTeixeira_Correios_Model_Cache
15
+ extends Varien_Object
16
+ {
17
+ /**
18
+ * Code property
19
+ *
20
+ * @var string
21
+ */
22
+ protected $_code = 'pedroteixeira_correios';
23
+
24
+ /**
25
+ * Core cache instance
26
+ *
27
+ * @var Zend_Cache_Core
28
+ */
29
+ private $_cache = null;
30
+
31
+ /**
32
+ * Retrieve cache instance.
33
+ *
34
+ * @return Zend_Cache_Core
35
+ */
36
+ private function getCache()
37
+ {
38
+ if ($this->_cache == null) {
39
+ $this->_cache = Mage::app()->getCache();
40
+ }
41
+ return $this->_cache;
42
+ }
43
+
44
+ /**
45
+ * Retrieve Zip Tags
46
+ *
47
+ * @return array
48
+ */
49
+ protected function getZipTags()
50
+ {
51
+ $padLength = $this->getConfigData('cache_accuracy/zip');
52
+ $zipLength = $padLength - 1;
53
+ $tags = array();
54
+ $tags[] = "ZIP_" . str_pad(substr($this->getData('sCepDestino'), 0, $zipLength--), $padLength, '0');
55
+ $tags[] = "ZIP_" . str_pad(substr($this->getData('sCepDestino'), 0, $zipLength--), $padLength, '0');
56
+ $tags[] = "ZIP_" . str_pad(substr($this->getData('sCepDestino'), 0, $zipLength--), $padLength, '0');
57
+ $tags[] = "ZIP_" . str_pad(substr($this->getData('sCepDestino'), 0, $zipLength--), $padLength, '0');
58
+ return $tags;
59
+ }
60
+
61
+ /**
62
+ * Retrieve Weight Tags
63
+ *
64
+ * @return array
65
+ */
66
+ protected function getWeightTags()
67
+ {
68
+ $tags = array();
69
+ $tags[] = "WEIGHT_" . floor($this->getData('nVlPeso'));
70
+ $tags[] = "WEIGHT_" . ceil($this->getData('nVlPeso'));
71
+ return $tags;
72
+ }
73
+
74
+ /**
75
+ * Retrieve Size Tags
76
+ *
77
+ * @return array
78
+ */
79
+ protected function getSizeTags()
80
+ {
81
+ $tags = array();
82
+ $type = ($this->getData('nVlAltura') < 40) ? 'REAL' : 'UNDEFINED';
83
+ $tags[] = "SIZE_{$type}";
84
+ return $tags;
85
+ }
86
+
87
+ /**
88
+ * Retrieve Post Methods Tags
89
+ *
90
+ * @return array
91
+ */
92
+ protected function getPostMethodsTags()
93
+ {
94
+ $tags = explode(',', $this->getData('nCdServico'));
95
+ return $tags;
96
+ }
97
+
98
+ /**
99
+ * When
100
+ * ZIP: 51038245
101
+ * WEIGHT: 1.3kg
102
+ * SIZE: 22cm
103
+ *
104
+ * Return example:
105
+ * array(
106
+ * 41068,
107
+ * 81019,
108
+ * ZIP_51038240,
109
+ * ZIP_51038200,
110
+ * ZIP_51038000,
111
+ * WEIGHT_1,
112
+ * WEIGHT_2,
113
+ * SIZE_REAL,
114
+ * PEDROTEIXEIRA_CORREIOS
115
+ * )
116
+ *
117
+ * @return array
118
+ */
119
+ protected function getCacheTags()
120
+ {
121
+ $tags = array();
122
+ $tags = array_merge($tags, $this->getPostMethodsTags());
123
+ $tags = array_merge($tags, $this->getZipTags());
124
+ $tags = array_merge($tags, $this->getWeightTags());
125
+ $tags = array_merge($tags, $this->getSizeTags());
126
+ $tags[] = 'PEDROTEIXEIRA_CORREIOS';
127
+ return $tags;
128
+ }
129
+
130
+ /**
131
+ * Return example:
132
+ * 41068x40096x81019_10_16_51030240
133
+ *
134
+ * @return string
135
+ */
136
+ protected function _getId()
137
+ {
138
+ $weight = round($this->getData('nVlPeso'), $this->getConfigData('cache_accuracy/weight'));
139
+ $zip = substr($this->getData('sCepDestino'), 0, $this->getConfigData('cache_accuracy/zip'));
140
+ $size = round($this->getData('nVlAltura'), $this->getConfigData('cache_accuracy/size'));
141
+ $methods = str_replace(',', 'x', $this->getData('nCdServico'));
142
+ $cacheId = "{$methods}_{$weight}_{$size}_{$zip}";
143
+ $cacheId = preg_replace("/[^[:alnum:]^_]/", "", $cacheId);
144
+ return $cacheId;
145
+ }
146
+
147
+ /**
148
+ * Retrieve the cache content.
149
+ *
150
+ * @return string
151
+ */
152
+ public function load()
153
+ {
154
+ $data = $this->loadById();
155
+ if (!$data) {
156
+ $data = $this->loadByTags();
157
+ }
158
+ return $data;
159
+ }
160
+
161
+ /**
162
+ * Retrieve the cache content by key.
163
+ *
164
+ * @return string
165
+ */
166
+ public function loadById()
167
+ {
168
+ $id = $this->_getId();
169
+ $data = $this->getCache()->load($id);
170
+ if ($data) {
171
+ Mage::log("{$this->_code} [cache]: mode={$this->getConfigData('cache_mode')} status=hit");
172
+ }
173
+ return $data;
174
+ }
175
+
176
+ /**
177
+ * Iterates over the ZIP codes, and returns the closest match.
178
+ *
179
+ * @return string
180
+ */
181
+ public function loadByTags()
182
+ {
183
+ $data = false;
184
+ $padLength = $this->getConfigData('cache_accuracy/zip');
185
+ for ($i = 1; $i < 5; $i++) {
186
+ $zipTag = str_pad(substr($this->getData('sCepDestino'), 0, $padLength - $i), $padLength, '0');
187
+ $tags = array();
188
+ $tags = array_merge($tags, $this->getPostMethodsTags());
189
+ $tags = array_merge($tags, $this->getWeightTags());
190
+ $tags = array_merge($tags, $this->getSizeTags());
191
+ $tags[] = 'PEDROTEIXEIRA_CORREIOS';
192
+ $tags[] = "ZIP_{$zipTag}";
193
+ $keys = $this->getCache()->getIdsMatchingTags($tags);
194
+ if (count($keys)) {
195
+ Mage::log("{$this->_code} [cache]: mode={$this->getConfigData('cache_mode')} status=hit tag=zip");
196
+ $data = $this->getCache()->load($keys[0]);
197
+ break;
198
+ }
199
+ }
200
+ return $data;
201
+ }
202
+
203
+ /**
204
+ * Validate the response data from Correios.
205
+ *
206
+ * @param string $data XML Content
207
+ *
208
+ * @return boolean
209
+ */
210
+ protected function _isValidCache($data)
211
+ {
212
+ $response = Zend_Http_Response::fromString($data);
213
+ $content = $response->getBody();
214
+ $pattern = $this->getConfigData('pattern_nocache');
215
+ if ($pattern != '' && preg_match($pattern, $content, $matches)) {
216
+ return false;
217
+ }
218
+ if (empty($content)) {
219
+ return false;
220
+ }
221
+ libxml_use_internal_errors(true);
222
+ $xml = simplexml_load_string($content);
223
+ if (!$xml || !isset($xml->cServico)) {
224
+ return false;
225
+ }
226
+ return true;
227
+ }
228
+
229
+ /**
230
+ * Save Correios content, tags and expiration period.
231
+ *
232
+ * @param string $data XML Content
233
+ *
234
+ * @throws Exception
235
+ *
236
+ * @return PedroTeixeira_Correios_Model_Cache
237
+ */
238
+ public function save($data)
239
+ {
240
+ if (!$this->_isValidCache($data)) {
241
+ return false; // Invalid for the Cache only
242
+ }
243
+ $id = $this->_getId();
244
+ $tags = $this->getCacheTags();
245
+ if ($this->getCache()->save($data, $id, $tags)) {
246
+ Mage::log("{$this->_code} [cache]: mode={$this->getConfigData('cache_mode')} status=write key={$id}");
247
+ }
248
+ return $this;
249
+ }
250
+
251
+ /**
252
+ * Retrieve information from carrier configuration
253
+ *
254
+ * @param string $field Field
255
+ *
256
+ * @return mixed
257
+ */
258
+ public function getConfigData($field)
259
+ {
260
+ if (empty($this->_code)) {
261
+ return false;
262
+ }
263
+ $path = 'carriers/' . $this->_code . '/' . $field;
264
+ return Mage::getStoreConfig($path);
265
+ }
266
+ }
app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php CHANGED
@@ -6,9 +6,10 @@
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
@@ -41,6 +42,8 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
41
  protected $_packageWeight = null;
42
  protected $_volumeWeight = null;
43
  protected $_freeMethodWeight = null;
 
 
44
 
45
  /**
46
  * Post methods
@@ -58,7 +61,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
  */
@@ -84,16 +87,8 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
@@ -102,16 +97,17 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
  }
@@ -134,7 +130,8 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
134
 
135
  if ($correiosReturn !== false) {
136
 
137
- $existReturn = false;
 
138
 
139
  foreach ($correiosReturn as $servicos) {
140
 
@@ -144,14 +141,18 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
 
@@ -173,7 +174,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
173
  /**
174
  * Make initial checks and iniciate module variables
175
  *
176
- * @param Mage_Shipping_Model_Rate_Request $request
177
  *
178
  * @return bool
179
  */
@@ -206,7 +207,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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()
@@ -220,6 +221,8 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
220
  * Get Correios return
221
  *
222
  * @return bool|SimpleXMLElement[]
 
 
223
  */
224
  protected function _getCorreiosReturn()
225
  {
@@ -230,27 +233,20 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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');
@@ -267,7 +263,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
  }
@@ -317,28 +313,28 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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')) {
@@ -346,7 +342,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
346
  $method->setMethodTitle(
347
  sprintf(
348
  $this->getConfigData('msgprazo'),
349
- $shipping_data[0],
350
  (int) ($correiosDelivery + $this->getConfigData('add_prazo'))
351
  )
352
  );
@@ -354,13 +350,13 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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);
@@ -376,10 +372,12 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
  {
@@ -404,8 +402,6 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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()
@@ -414,6 +410,10 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
414
 
415
  $items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
416
 
 
 
 
 
417
  foreach ($items as $item) {
418
  $_product = $item->getProduct();
419
 
@@ -436,20 +436,28 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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, '.', '');
@@ -460,7 +468,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
460
  /**
461
  * Generate free shipping for a product
462
  *
463
- * @param string $freeMethod
464
  *
465
  * @return void
466
  */
@@ -493,7 +501,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
493
  /**
494
  * Get Tracking Info
495
  *
496
- * @param mixed $tracking
497
  *
498
  * @return mixed
499
  */
@@ -514,7 +522,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
514
  /**
515
  * Get Tracking
516
  *
517
- * @param array $trackings
518
  *
519
  * @return Mage_Shipping_Model_Tracking_Result
520
  */
@@ -531,7 +539,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
531
  /**
532
  * Protected Get Tracking, opens the request to Correios
533
  *
534
- * @param string $code
535
  *
536
  * @return bool
537
  */
@@ -572,7 +580,8 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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
@@ -601,13 +610,13 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
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);
611
  }
612
 
613
  $progress[] = $track;
@@ -620,7 +629,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
620
 
621
  $tracking = Mage::getModel('shipping/tracking_result_status');
622
  $tracking->setTracking($code);
623
- $tracking->setCarrier('correios');
624
  $tracking->setCarrierTitle($this->getConfigData('title'));
625
  $tracking->addData($track);
626
 
@@ -645,7 +654,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
645
  /**
646
  * Define ZIP Code as required
647
  *
648
- * @param string $countryId
649
  *
650
  * @return bool
651
  */
@@ -653,4 +662,200 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
653
  {
654
  return true;
655
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  }
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
  class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
15
  extends Mage_Shipping_Model_Carrier_Abstract
42
  protected $_packageWeight = null;
43
  protected $_volumeWeight = null;
44
  protected $_freeMethodWeight = null;
45
+ protected $_midSize = null;
46
+ protected $_splitUp = 0;
47
 
48
  /**
49
  * Post methods
61
  /**
62
  * Collect Rates
63
  *
64
+ * @param Mage_Shipping_Model_Rate_Request $request Mage request
65
  *
66
  * @return bool|Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result
67
  */
87
  }
88
 
89
  // Fix weight
 
90
  if ($this->getConfigData('weight_type') == PedroTeixeira_Correios_Model_Source_WeightType::WEIGHT_GR) {
91
  $this->_packageWeight = number_format($this->_packageWeight / 1000, 2, '.', '');
 
 
 
 
 
 
 
92
  }
93
 
94
  // Check weight zero
97
  return $this->_result;
98
  }
99
 
100
+ $this->_postMethods = $this->getConfigData('postmethods');
101
+ $this->_postMethodsFixed = $this->_postMethods;
102
+ $this->_postMethodsExplode = explode(',', $this->getConfigData('postmethods'));
103
+
104
  // Generate Volume Weight
105
+ if ($this->_generateVolumeWeight() === false || $this->_removeInvalidServices() === false) {
106
  $this->_throwError('dimensionerror', 'Dimension error', __LINE__);
107
  return $this->_result;
108
  }
109
 
110
+ $this->_filterMethodByItemRestriction();
 
 
 
111
  if ($this->_getQuotes()->getError()) {
112
  return $this->_result;
113
  }
130
 
131
  if ($correiosReturn !== false) {
132
 
133
+ $correiosReturn = $this->_addPostMethods($correiosReturn);
134
+ $existReturn = false;
135
 
136
  foreach ($correiosReturn as $servicos) {
137
 
141
  continue;
142
  }
143
 
144
+ $stringPrice = (string) $servicos->Valor;
145
+ $stringPrice = str_replace('.', '', $stringPrice);
146
+ $stringPrice = str_replace(',', '.', $stringPrice);
147
+ $shippingPrice = floatval($stringPrice);
148
+ $shippingPrice *= pow(2, $this->_splitUp);
149
  $shippingDelivery = (int) $servicos->PrazoEntrega;
150
 
151
  if ($shippingPrice <= 0) {
152
  continue;
153
  }
154
 
155
+ $this->_appendShippingReturn((string) $servicos->Codigo, $shippingPrice, $shippingDelivery);
156
  $existReturn = true;
157
  }
158
 
174
  /**
175
  * Make initial checks and iniciate module variables
176
  *
177
+ * @param Mage_Shipping_Model_Rate_Request $request Mage request
178
  *
179
  * @return bool
180
  */
207
  return false;
208
  }
209
 
210
+ $this->_result = Mage::getModel('shipping/rate_result');
211
  $this->_packageValue = $request->getBaseCurrency()->convert(
212
  $request->getPackageValue(),
213
  $request->getPackageCurrency()
221
  * Get Correios return
222
  *
223
  * @return bool|SimpleXMLElement[]
224
+ *
225
+ * @throws Exception
226
  */
227
  protected function _getCorreiosReturn()
228
  {
233
  $client = new Zend_Http_Client($filename);
234
  $client->setConfig(
235
  array(
236
+ 'timeout' => $this->getConfigData('ws_timeout'),
237
+ 'adapter' => Mage::getModel('pedroteixeira_correios/http_client_adapter_socket')
238
  )
239
  );
240
 
241
  $client->setParameterGet('StrRetorno', 'xml');
242
  $client->setParameterGet('nCdServico', $this->_postMethods);
243
+ $client->setParameterGet('nVlPeso', $this->_packageWeight);
 
 
 
 
 
 
 
 
244
  $client->setParameterGet('sCepOrigem', $this->_fromZip);
245
  $client->setParameterGet('sCepDestino', $this->_toZip);
246
  $client->setParameterGet('nCdFormato', 1);
247
+ $client->setParameterGet('nVlComprimento', $this->_midSize);
248
+ $client->setParameterGet('nVlAltura', $this->_midSize);
249
+ $client->setParameterGet('nVlLargura', $this->_midSize);
250
 
251
  if ($this->getConfigData('mao_propria')) {
252
  $client->setParameterGet('sCdMaoPropria', 'S');
263
  if ($this->getConfigData('valor_declarado')
264
  || in_array($this->getConfigData('acobrar_code'), $this->_postMethodsExplode)
265
  ) {
266
+ $client->setParameterGet('nVlValorDeclarado', number_format($this->_packageValue, 2, ',', ''));
267
  } else {
268
  $client->setParameterGet('nVlValorDeclarado', 0);
269
  }
313
  /**
314
  * Apend shipping value to return
315
  *
316
+ * @param string $shippingMethod Method of shipping
317
+ * @param int $shippingPrice Price
318
+ * @param int $correiosDelivery Delivery date
319
  *
320
  * @return void
321
  */
322
+ protected function _appendShippingReturn($shippingMethod, $shippingPrice = 0, $correiosDelivery = 0)
323
  {
324
 
325
  $method = Mage::getModel('shipping/rate_result_method');
326
  $method->setCarrier($this->_code);
327
  $method->setCarrierTitle($this->getConfigData('title'));
328
+ $method->setMethod($shippingMethod);
329
 
330
  $shippingCost = $shippingPrice;
331
  $shippingPrice = $shippingPrice + $this->getConfigData('handling_fee');
332
 
333
+ $shippingData = explode(',', $this->getConfigData('serv_' . $shippingMethod));
334
 
335
+ if ($shippingMethod == $this->getConfigData('acobrar_code')) {
336
+ $shippingData[0] = $shippingData[0] . ' ( R$' . number_format($shippingPrice, 2, ',', '.') . ' )';
337
+ $shippingPrice = 0;
338
  }
339
 
340
  if ($this->getConfigFlag('prazo_entrega')) {
342
  $method->setMethodTitle(
343
  sprintf(
344
  $this->getConfigData('msgprazo'),
345
+ $shippingData[0],
346
  (int) ($correiosDelivery + $this->getConfigData('add_prazo'))
347
  )
348
  );
350
  $method->setMethodTitle(
351
  sprintf(
352
  $this->getConfigData('msgprazo'),
353
+ $shippingData[0],
354
+ (int) ($shippingData[1] + $this->getConfigData('add_prazo'))
355
  )
356
  );
357
  }
358
  } else {
359
+ $method->setMethodTitle($shippingData[0]);
360
  }
361
 
362
  $method->setPrice($shippingPrice);
372
  /**
373
  * Throw error
374
  *
375
+ * @param string $message Message placeholder
376
+ * @param string $log Message
377
+ * @param string|int $line Line of log
378
+ * @param string $custom Custom variables for placeholder
379
+ *
380
+ * @return void
381
  */
382
  protected function _throwError($message, $log = null, $line = 'NO LINE', $custom = null)
383
  {
402
  /**
403
  * Generate Volume weight
404
  *
 
 
405
  * @return bool
406
  */
407
  protected function _generateVolumeWeight()
410
 
411
  $items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
412
 
413
+ if (count($items) == 0) {
414
+ $items = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
415
+ }
416
+
417
  foreach ($items as $item) {
418
  $_product = $item->getProduct();
419
 
436
  }
437
 
438
  if ($this->getConfigFlag('check_dimensions')) {
439
+ foreach ($this->_postMethodsExplode as $key => $method) {
440
+ $sizeMax = max($itemAltura, $itemLargura, $itemComprimento);
441
+ $sumMax = ($itemAltura + $itemLargura + $itemComprimento);
442
+ $isValid = ($sizeMax <= $this->getConfigData("validate/serv_{$method}/max/size"));
443
+ $isValid &= ($sumMax <= $this->getConfigData("validate/serv_{$method}/max/sum"));
444
+
445
+ if (!$isValid) {
446
+ unset($this->_postMethodsExplode[$key]);
447
+ }
448
+ }
449
+
450
+ if (count($this->_postMethodsExplode) == 0) {
451
  return false;
452
  }
453
+
454
+ $this->_postMethods = implode(',', $this->_postMethodsExplode);
455
+ $this->_postMethodsFixed = $this->_postMethods;
456
  }
457
 
458
+ $itemAltura = $this->_getFitHeight($item);
459
+ $pesoCubicoTotal += (($itemAltura * $itemLargura * $itemComprimento) *
460
+ $item->getQty()) / $this->getConfigData('coeficiente_volume');
461
  }
462
 
463
  $this->_volumeWeight = number_format($pesoCubicoTotal, 2, '.', '');
468
  /**
469
  * Generate free shipping for a product
470
  *
471
+ * @param string $freeMethod Free method
472
  *
473
  * @return void
474
  */
501
  /**
502
  * Get Tracking Info
503
  *
504
+ * @param mixed $tracking Tracking
505
  *
506
  * @return mixed
507
  */
522
  /**
523
  * Get Tracking
524
  *
525
+ * @param array $trackings Trackings
526
  *
527
  * @return Mage_Shipping_Model_Tracking_Result
528
  */
539
  /**
540
  * Protected Get Tracking, opens the request to Correios
541
  *
542
+ * @param string $code Code
543
  *
544
  * @return bool
545
  */
580
 
581
  $description = '';
582
  $found = false;
583
+ if (preg_match('/<td rowspan="?2"?/i', $column)
584
+ && preg_match(
585
  '/<td rowspan="?2"?>(.*)<\/td><td>(.*)<\/td><td><font color="[A-Z0-9]{6}">(.*)<\/font><\/td>/i',
586
  $column,
587
  $matches
610
  $track = array(
611
  'deliverydate' => $date->toString('YYYY-MM-dd'),
612
  'deliverytime' => $datetime[1] . ':00',
613
+ 'deliverylocation' => htmlentities($matches[2], ENT_IGNORE, 'ISO-8859-1'),
614
+ 'status' => htmlentities($matches[3], ENT_IGNORE, 'ISO-8859-1'),
615
+ 'activity' => htmlentities($matches[3], ENT_IGNORE, 'ISO-8859-1')
616
  );
617
 
618
  if ($description !== '') {
619
+ $track['activity'] = $matches[3] . ' - ' . htmlentities($description, ENT_IGNORE, 'ISO-8859-1');
620
  }
621
 
622
  $progress[] = $track;
629
 
630
  $tracking = Mage::getModel('shipping/tracking_result_status');
631
  $tracking->setTracking($code);
632
+ $tracking->setCarrier($this->_code);
633
  $tracking->setCarrierTitle($this->getConfigData('title'));
634
  $tracking->addData($track);
635
 
654
  /**
655
  * Define ZIP Code as required
656
  *
657
+ * @param string $countryId Country ID
658
  *
659
  * @return bool
660
  */
662
  {
663
  return true;
664
  }
665
+
666
+ /**
667
+ * Retrieve an average size.
668
+ * For optimization purposes all tree box sizes are converted in one medium dimension.
669
+ * Result cant exceed the minimum transportation limits.
670
+ *
671
+ * @return PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
672
+ */
673
+ protected function _loadMidSize()
674
+ {
675
+ $volumeFactor = $this->getConfigData('coeficiente_volume');
676
+ $volumeTotal = $this->_volumeWeight * $volumeFactor;
677
+ $pow = round(pow((int) $volumeTotal, (1 / 3)));
678
+ $min = $this->getConfigData('midsize_min');
679
+ $this->_midSize = max($pow, $min);
680
+ return $this;
681
+ }
682
+
683
+ /**
684
+ * Validate post methods removing invalid services from quotation.
685
+ *
686
+ * @return boolean|PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
687
+ */
688
+ protected function _removeInvalidServices()
689
+ {
690
+ $this->_loadMidSize();
691
+ $tmpMethods = $this->_postMethodsExplode;
692
+ foreach ($tmpMethods as $key => $method) {
693
+ $isOverSize = ($this->_midSize > $this->getConfigData("validate/serv_{$method}/max/size"));
694
+ $isOverSize |= ($this->_midSize * 3 > $this->getConfigData("validate/serv_{$method}/max/sum"));
695
+ $isOverWeight = ($this->_packageWeight > $this->getConfigData("validate/serv_{$method}/max/weight"));
696
+
697
+ if ($isOverSize || $isOverWeight) {
698
+ unset($tmpMethods[$key]);
699
+ }
700
+ }
701
+
702
+ $isDivisible = (count($tmpMethods) == 0);
703
+ $isLoopBreakable = (count($this->_postMethodsExplode) > 0);
704
+ if ($isDivisible && $isLoopBreakable) {
705
+ return $this->_splitPack();
706
+ }
707
+
708
+ $this->_postMethodsExplode = $tmpMethods;
709
+ $this->_postMethods = implode(',', $this->_postMethodsExplode);
710
+ $this->_postMethodsFixed = $this->_postMethods;
711
+ return $this;
712
+ }
713
+
714
+ /**
715
+ * Include an additional method to quote content before showing.
716
+ * When requested the new method is added in xml content as specified in config.xml like below:
717
+ *
718
+ * <add_method_0>
719
+ * <code>10065</code>
720
+ * <price>2.45</price>
721
+ * <days>5</days>
722
+ * <from>
723
+ * <zip>00000000</zip>
724
+ * <weight>0.0</weight>
725
+ * <size>0</size>
726
+ * </from>
727
+ * <to>
728
+ * <zip>99999999</zip>
729
+ * <weight>0.1</weight>
730
+ * <size>150</size>
731
+ * </to>
732
+ * </add_method_0>
733
+ *
734
+ * @param SimpleXMLElement $cServico XML Node
735
+ *
736
+ * @see http://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/carta
737
+ *
738
+ * @return SimpleXMLElement
739
+ */
740
+ protected function _addPostMethods($cServico)
741
+ {
742
+ $i = 0;
743
+ while (!is_null($this->getConfigData("add_method_{$i}"))) {
744
+ $isValid = true;
745
+ $isValid &= $this->_packageWeight >= $this->getConfigData("add_method_{$i}/from/weight");
746
+ $isValid &= $this->_packageWeight <= $this->getConfigData("add_method_{$i}/to/weight");
747
+ $isValid &= $this->_midSize >= $this->getConfigData("add_method_{$i}/from/size");
748
+ $isValid &= $this->_midSize <= $this->getConfigData("add_method_{$i}/to/size");
749
+ $isValid &= $this->_toZip >= $this->getConfigData("add_method_{$i}/from/zip");
750
+ $isValid &= $this->_toZip <= $this->getConfigData("add_method_{$i}/to/zip");
751
+
752
+ if ($isValid) {
753
+ $price = $this->getConfigData("add_method_{$i}/price");
754
+ $days = $this->getConfigData("add_method_{$i}/days");
755
+ $method = $this->getConfigData("add_method_{$i}/code");
756
+ foreach ($cServico as $servico) {
757
+ if ($servico->Codigo == $method) {
758
+ $servico->Valor = number_format($price, 2, ',', '');
759
+ $servico->PrazoEntrega = $days;
760
+ $servico->EntregaDomiciliar = 'S';
761
+ $servico->EntregaSabado = 'S';
762
+ $servico->Erro = '0';
763
+ $servico->MsgErro = '<![CDATA[]]>';
764
+ }
765
+ }
766
+ }
767
+
768
+ $i++;
769
+ }
770
+
771
+ return $cServico;
772
+ }
773
+
774
+ /**
775
+ * This keeps only postmethods available for all items in cart.
776
+ * In other words you can set post methods by products.
777
+ * Methods not available for all items in cart are removed.
778
+ * Require attribute creation called postmethods.
779
+ * Example:
780
+ * code: postmethods
781
+ * type: multiselect
782
+ * label: [free]
783
+ * value 1: 41068
784
+ * value 2: 40096
785
+ * ...
786
+ * value 99: 81019
787
+ *
788
+ * @return PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
789
+ */
790
+ protected function _filterMethodByItemRestriction()
791
+ {
792
+ if ($this->getConfigFlag('filter_by_item')) {
793
+ $items = Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems();
794
+
795
+ if (count($items) == 0) {
796
+ $items = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
797
+ }
798
+
799
+ $intersection = $this->_postMethodsExplode;
800
+ foreach ($items as $item) {
801
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
802
+ $prodPostMethods = explode(',', $product->getData('postmethods'));
803
+ $intersection = array_intersect($prodPostMethods, $intersection);
804
+ }
805
+
806
+ $this->_postMethodsExplode = $intersection;
807
+ $this->_postMethods = implode(',', $intersection);
808
+ $this->_postMethodsFixed = $this->_postMethods;
809
+ }
810
+
811
+ return $this;
812
+ }
813
+
814
+ /**
815
+ * Added a fit size for items in large quantities.
816
+ * Means you can join items like two or more glasses, pots and vases.
817
+ * The calc is applied only for height side.
818
+ * Required attribute fit_size. Example:
819
+ *
820
+ * code: fit_size
821
+ * type: varchar
822
+ *
823
+ * After you can set a fit size for all products and improve your sells
824
+ *
825
+ * @param Mage_Eav_Model_Entity_Abstract $item Order Item
826
+ *
827
+ * @return number
828
+ */
829
+ protected function _getFitHeight($item)
830
+ {
831
+ $product = $item->getProduct();
832
+ $height = $product->getData('volume_altura');
833
+ $height = ($height > 0) ? $height : (int) $this->getConfigData('altura_padrao');
834
+ $fitSize = (float) $product->getData('fit_size');
835
+
836
+ if ($item->getQty() > 1 && is_numeric($fitSize) && $fitSize > 0) {
837
+ $totalSize = $height + ($fitSize * ($item->getQty() - 1));
838
+ $height = $totalSize / $item->getQty();
839
+ }
840
+
841
+ return $height;
842
+ }
843
+
844
+ /**
845
+ * Splits the package in two parts.
846
+ * If the package is already splited, each piece will be splited in two equal parts.
847
+ *
848
+ * @return boolean|PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
849
+ */
850
+ protected function _splitPack()
851
+ {
852
+ if ($this->getConfigFlag('split_pack')) {
853
+ $this->_splitUp++;
854
+ $this->_volumeWeight /= 2;
855
+ $this->_packageWeight /= 2;
856
+ $this->_packageValue /= 2;
857
+ return $this->_removeInvalidServices();
858
+ }
859
+ return false;
860
+ }
861
  }
app/code/community/PedroTeixeira/Correios/Model/Http/Client/Adapter/Socket.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
+ */
14
+ class PedroTeixeira_Correios_Model_Http_Client_Adapter_Socket
15
+ extends Zend_Http_Client_Adapter_Socket
16
+ {
17
+ protected $_cache = null;
18
+ protected $_params = null;
19
+ protected $_code = 'pedroteixeira_correios';
20
+
21
+ const CACHE_TYPE = 'pedroteixeira_correios';
22
+
23
+ /**
24
+ * Connect to the remote server
25
+ *
26
+ * @param string $host Host name
27
+ * @param int $port Port number
28
+ * @param bool $secure Secure flag
29
+ *
30
+ * @return void
31
+ */
32
+ public function connect($host, $port = 80, $secure = false)
33
+ {
34
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
35
+ $mode = $this->getConfigData('cache_mode');
36
+ if (!($mode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_CACHE_ONLY)) {
37
+ try {
38
+ parent::connect($host, $port, $secure);
39
+ } catch (Zend_Http_Client_Adapter_Exception $e) {
40
+ Mage::log("{$this->_code} [socket]: {$e->getMessage()}");
41
+ }
42
+ }
43
+ } else {
44
+ parent::connect($host, $port, $secure);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Send request to the remote server
50
+ *
51
+ * @param string $method Method
52
+ * @param Zend_Uri_Http $uri Uri
53
+ * @param string $http_ver HTTP version
54
+ * @param array $headers Headers
55
+ * @param string $body Body
56
+ *
57
+ * @return string Request as string
58
+ */
59
+ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
60
+ {
61
+ $request = false;
62
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
63
+ $this->_params = $uri->getQueryAsArray();
64
+ try {
65
+ $request = parent::write($method, $uri, $http_ver, $headers, $body);
66
+ } catch (Zend_Http_Client_Adapter_Exception $e) {
67
+ Mage::log("{$this->_code} [socket]: {$e->getMessage()}");
68
+ }
69
+ } else {
70
+ $request = parent::write($method, $uri, $http_ver, $headers, $body);
71
+ }
72
+ return $request;
73
+ }
74
+
75
+ /**
76
+ * Read response from server
77
+ *
78
+ * @see Zend_Http_Client_Adapter_Socket::read()
79
+ *
80
+ * @return string
81
+ */
82
+ public function read()
83
+ {
84
+ $response = false;
85
+ if (Mage::app()->useCache(self::CACHE_TYPE)) {
86
+ $cache = $this->getCache();
87
+ $cache->addData($this->_params);
88
+ $cacheMode = $this->getConfigData('cache_mode');
89
+ if ($cacheMode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_HTTP_PRIOR) {
90
+ try {
91
+ $response = parent::read();
92
+ $cache->save($response);
93
+ } catch (Zend_Http_Client_Adapter_Exception $e) {
94
+ $response = $cache->load();
95
+ }
96
+ } elseif ($cacheMode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_CACHE_PRIOR) {
97
+ $response = $cache->loadById();
98
+ if (!$response) {
99
+ try {
100
+ $response = parent::read();
101
+ $cache->save($response);
102
+ } catch (Zend_Http_Client_Adapter_Exception $e) {
103
+ $response = $cache->loadByTags();
104
+ }
105
+ }
106
+ } elseif ($cacheMode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_CACHE_ONLY) {
107
+ $response = $cache->load();
108
+ }
109
+ } else {
110
+ $response = parent::read();
111
+ }
112
+ return $response;
113
+ }
114
+
115
+ /**
116
+ * Retrieves the cache instance
117
+ *
118
+ * @return PedroTeixeira_Correios_Model_Cache
119
+ */
120
+ public function getCache()
121
+ {
122
+ if ($this->_cache == null) {
123
+ $this->_cache = Mage::getModel('pedroteixeira_correios/cache');
124
+ }
125
+ return $this->_cache;
126
+ }
127
+
128
+ /**
129
+ * Retrieve information from carrier configuration
130
+ *
131
+ * @param string $field Field
132
+ *
133
+ * @return mixed
134
+ */
135
+ public function getConfigData($field)
136
+ {
137
+ if (empty($this->_code)) {
138
+ return false;
139
+ }
140
+ $path = 'carriers/' . $this->_code . '/' . $field;
141
+ return Mage::getStoreConfig($path);
142
+ }
143
+ }
app/code/community/PedroTeixeira/Correios/Model/Source/CacheMode.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
+ */
14
+ class PedroTeixeira_Correios_Model_Source_CacheMode extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
15
+ {
16
+ const MODE_HTTP_PRIOR = 0;
17
+ const MODE_CACHE_PRIOR = 1;
18
+ const MODE_CACHE_ONLY = 2;
19
+
20
+ /**
21
+ * Get options for methods
22
+ *
23
+ * @return array
24
+ */
25
+ public function toOptionArray()
26
+ {
27
+ return array(
28
+ array('value' => self::MODE_HTTP_PRIOR, 'label' => 'Consultar os Correios; e, se falhar, o Cache'),
29
+ array('value' => self::MODE_CACHE_PRIOR, 'label' => 'Consultar o Cache; e, se falhar, os Correios'),
30
+ array('value' => self::MODE_CACHE_ONLY, 'label' => 'Consultar somente o Cache'),
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Get options for input fields
36
+ *
37
+ * @see Mage_Eav_Model_Entity_Attribute_Source_Interface::getAllOptions()
38
+ *
39
+ * @return array
40
+ */
41
+ public function getAllOptions()
42
+ {
43
+ return self::toOptionArray();
44
+ }
45
+ }
app/code/community/PedroTeixeira/Correios/Model/Source/PostMethods.php CHANGED
@@ -6,13 +6,16 @@
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()
@@ -26,6 +29,21 @@ class PedroTeixeira_Correios_Model_Source_PostMethods
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
  }
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
+ class PedroTeixeira_Correios_Model_Source_PostMethods extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
15
  {
16
  /**
17
+ * Get options for methods
18
+ *
19
  * @return array
20
  */
21
  public function toOptionArray()
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
+ array('value' => 41300, 'label' => Mage::helper('adminhtml')->__('PAC GF (41300)')),
33
+ array('value' => 10065, 'label' => Mage::helper('adminhtml')->__('Carta Comercial (10065)')),
34
+ array('value' => 10138, 'label' => Mage::helper('adminhtml')->__('Carta Comercial Registrada (10138)')),
35
  );
36
  }
37
+
38
+ /**
39
+ * Get options for input fields
40
+ *
41
+ * @see Mage_Eav_Model_Entity_Attribute_Source_Interface::getAllOptions()
42
+ *
43
+ * @return array
44
+ */
45
+ public function getAllOptions()
46
+ {
47
+ return self::toOptionArray();
48
+ }
49
  }
app/code/community/PedroTeixeira/Correios/Model/Source/WeightType.php CHANGED
@@ -6,9 +6,10 @@
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
  {
@@ -19,6 +20,8 @@ class PedroTeixeira_Correios_Model_Source_WeightType
19
  const WEIGHT_KG = 'kg';
20
 
21
  /**
 
 
22
  * @return array
23
  */
24
  public function toOptionArray()
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
  class PedroTeixeira_Correios_Model_Source_WeightType
15
  {
20
  const WEIGHT_KG = 'kg';
21
 
22
  /**
23
+ * Get options for weight
24
+ *
25
  * @return array
26
  */
27
  public function toOptionArray()
app/code/community/PedroTeixeira/Correios/etc/config.xml CHANGED
@@ -6,15 +6,16 @@
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>
15
  <modules>
16
  <PedroTeixeira_Correios>
17
- <version>4.2.0</version>
18
  <depends>
19
  <Mage_Shipping/>
20
  </depends>
@@ -28,6 +29,8 @@
28
  <volume_altura/>
29
  <volume_comprimento/>
30
  <volume_largura/>
 
 
31
  </product_attributes>
32
  </item>
33
  </quote>
@@ -61,6 +64,15 @@
61
  </carriers>
62
  </shipping>
63
  </sales>
 
 
 
 
 
 
 
 
 
64
  </global>
65
 
66
  <default>
@@ -76,7 +88,6 @@
76
  <check_dimensions>1</check_dimensions>
77
  <min_order_value>0</min_order_value>
78
  <max_order_value>10000</max_order_value>
79
- <maxweight>30</maxweight>
80
  <handling_fee>0</handling_fee>
81
  <ws_timeout>20</ws_timeout>
82
 
@@ -89,34 +100,101 @@
89
  <altura_padrao>2</altura_padrao>
90
  <comprimento_padrao>16</comprimento_padrao>
91
  <largura_padrao>11</largura_padrao>
92
- <altura_sent>2</altura_sent>
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 -->
109
  <free_method>40010</free_method>
110
  <weight_type>kg</weight_type>
111
  <add_prazo>0</add_prazo>
112
  <showmethod>1</showmethod>
 
 
113
 
114
  <!-- MESSAGES -->
115
  <msgprazo>%s - Em média %d dia(s)</msgprazo>
116
  <correioserror>Houve um erro inesperado, por favor entre em contato. %s</correioserror>
117
  <valueerror>Valor de compra fora do permitido pelos Correios. Por favor entre em contato conosco.</valueerror>
118
  <zipcodeerror>Por favor, corrija o CEP digitado, ele não está correto.</zipcodeerror>
119
- <maxweighterror>Peso dos produtos acima do permitido pelos Correios. Por favor entre em contato conosco.</maxweighterror>
120
  <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>
121
  <coderror>Lojista: Para calcular esse serviço você precisa ter contrato com os Correios.</coderror>
122
  <urlerror>Esse método de envio está fora do ar. Por favor entre em contato conosco.</urlerror>
@@ -131,11 +209,355 @@
131
  <serv_40215>Sedex 10,1</serv_40215>
132
  <serv_40290>Sedex HOJE,1</serv_40290>
133
  <serv_40045>Sedex a Cobrar,5</serv_40045>
134
- <volume_weight_min>5</volume_weight_min>
 
 
135
  <coeficiente_volume>6000</coeficiente_volume>
136
  <acobrar_code>40045</acobrar_code>
137
- <contrato_codes>40096,81019,41068</contrato_codes>
138
  <url_ws_correios>http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx</url_ws_correios>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  </pedroteixeira_correios>
140
  </carriers>
141
  </default>
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
  -->
15
  <config>
16
  <modules>
17
  <PedroTeixeira_Correios>
18
+ <version>4.4.0</version>
19
  <depends>
20
  <Mage_Shipping/>
21
  </depends>
29
  <volume_altura/>
30
  <volume_comprimento/>
31
  <volume_largura/>
32
+ <postmethods/>
33
+ <fit_size/>
34
  </product_attributes>
35
  </item>
36
  </quote>
64
  </carriers>
65
  </shipping>
66
  </sales>
67
+ <cache>
68
+ <types>
69
+ <pedroteixeira_correios translate="label,description" module="pedroteixeira_correios">
70
+ <label>Correios Cache</label>
71
+ <description>Banco de Cotações dos Correios.</description>
72
+ <tags>PEDROTEIXEIRA_CORREIOS</tags>
73
+ </pedroteixeira_correios>
74
+ </types>
75
+ </cache>
76
  </global>
77
 
78
  <default>
88
  <check_dimensions>1</check_dimensions>
89
  <min_order_value>0</min_order_value>
90
  <max_order_value>10000</max_order_value>
 
91
  <handling_fee>0</handling_fee>
92
  <ws_timeout>20</ws_timeout>
93
 
100
  <altura_padrao>2</altura_padrao>
101
  <comprimento_padrao>16</comprimento_padrao>
102
  <largura_padrao>11</largura_padrao>
103
+ <midsize_min>16</midsize_min>
 
 
104
 
105
+ <validate>
106
+ <serv_40010>
107
+ <max>
108
+ <size>105</size>
109
+ <sum>200</sum>
110
+ <weight>30</weight>
111
+ </max>
112
+ </serv_40010>
113
+ <serv_40096>
114
+ <max>
115
+ <size>105</size>
116
+ <sum>200</sum>
117
+ <weight>30</weight>
118
+ </max>
119
+ </serv_40096>
120
+ <serv_81019>
121
+ <max>
122
+ <size>105</size>
123
+ <sum>200</sum>
124
+ <weight>15</weight>
125
+ </max>
126
+ </serv_81019>
127
+ <serv_41106>
128
+ <max>
129
+ <size>105</size>
130
+ <sum>200</sum>
131
+ <weight>30</weight>
132
+ </max>
133
+ </serv_41106>
134
+ <serv_41068>
135
+ <max>
136
+ <size>105</size>
137
+ <sum>200</sum>
138
+ <weight>30</weight>
139
+ </max>
140
+ </serv_41068>
141
+ <serv_40215>
142
+ <max>
143
+ <size>105</size>
144
+ <sum>200</sum>
145
+ <weight>10</weight>
146
+ </max>
147
+ </serv_40215>
148
+ <serv_40290>
149
+ <max>
150
+ <size>105</size>
151
+ <sum>200</sum>
152
+ <weight>10</weight>
153
+ </max>
154
+ </serv_40290>
155
+ <serv_40045>
156
+ <max>
157
+ <size>105</size>
158
+ <sum>200</sum>
159
+ <weight>30</weight>
160
+ </max>
161
+ </serv_40045>
162
+ <serv_41300>
163
+ <max>
164
+ <size>150</size>
165
+ <sum>300</sum>
166
+ <weight>30</weight>
167
+ </max>
168
+ </serv_41300>
169
+ <serv_10065>
170
+ <max>
171
+ <size>30</size>
172
+ <sum>50</sum>
173
+ <weight>0.5</weight>
174
+ </max>
175
+ </serv_10065>
176
+ <serv_10138>
177
+ <max>
178
+ <size>30</size>
179
+ <sum>50</sum>
180
+ <weight>0.5</weight>
181
+ </max>
182
+ </serv_10138>
183
+ </validate>
184
 
185
  <!-- CONFIG -->
186
  <free_method>40010</free_method>
187
  <weight_type>kg</weight_type>
188
  <add_prazo>0</add_prazo>
189
  <showmethod>1</showmethod>
190
+ <filter_by_item>0</filter_by_item>
191
+ <split_pack>1</split_pack>
192
 
193
  <!-- MESSAGES -->
194
  <msgprazo>%s - Em média %d dia(s)</msgprazo>
195
  <correioserror>Houve um erro inesperado, por favor entre em contato. %s</correioserror>
196
  <valueerror>Valor de compra fora do permitido pelos Correios. Por favor entre em contato conosco.</valueerror>
197
  <zipcodeerror>Por favor, corrija o CEP digitado, ele não está correto.</zipcodeerror>
 
198
  <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>
199
  <coderror>Lojista: Para calcular esse serviço você precisa ter contrato com os Correios.</coderror>
200
  <urlerror>Esse método de envio está fora do ar. Por favor entre em contato conosco.</urlerror>
209
  <serv_40215>Sedex 10,1</serv_40215>
210
  <serv_40290>Sedex HOJE,1</serv_40290>
211
  <serv_40045>Sedex a Cobrar,5</serv_40045>
212
+ <serv_41300>PAC GF,4</serv_41300>
213
+ <serv_10065>Carta Comercial,3</serv_10065>
214
+ <serv_10138>Carta Comercial Registrada,3</serv_10138>
215
  <coeficiente_volume>6000</coeficiente_volume>
216
  <acobrar_code>40045</acobrar_code>
217
+ <contrato_codes>40096,81019,41068,41300</contrato_codes>
218
  <url_ws_correios>http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx</url_ws_correios>
219
+
220
+ <!-- CACHE -->
221
+ <pattern_nocache><![CDATA[/<Erro>(-2|-3|-5|-6|-7|-8|-9|-10|-11|-12|-13|-14|-15|-16|-17|-18|-20|-22|-23|-24|-25|-26|-27|-28|-29|-30|-31|-32|-33|-34|-35|-36|-37|-38|-39|-40|-41|-42|-43|-44|-45|-888|006|007|009|010|011|7|99)<\/Erro>/]]></pattern_nocache>
222
+ <cache_timeout>31536000</cache_timeout>
223
+ <cache_accuracy>
224
+ <weight>1</weight>
225
+ <zip>8</zip>
226
+ <size>0</size>
227
+ </cache_accuracy>
228
+ <cache_mode>0</cache_mode>
229
+
230
+ <!-- ADDITIONAL POST METHODS -->
231
+ <add_method_0>
232
+ <code>10065</code>
233
+ <price>1.30</price>
234
+ <days>5</days>
235
+ <from>
236
+ <zip>00000000</zip>
237
+ <weight>0</weight>
238
+ <size>0</size>
239
+ </from>
240
+ <to>
241
+ <zip>99999999</zip>
242
+ <weight>0.020</weight>
243
+ <size>30</size>
244
+ </to>
245
+ </add_method_0>
246
+ <add_method_1>
247
+ <code>10065</code>
248
+ <price>1.80</price>
249
+ <days>5</days>
250
+ <from>
251
+ <zip>00000000</zip>
252
+ <weight>0.020</weight>
253
+ <size>0</size>
254
+ </from>
255
+ <to>
256
+ <zip>99999999</zip>
257
+ <weight>0.050</weight>
258
+ <size>30</size>
259
+ </to>
260
+ </add_method_1>
261
+ <add_method_2>
262
+ <code>10065</code>
263
+ <price>2.45</price>
264
+ <days>5</days>
265
+ <from>
266
+ <zip>00000000</zip>
267
+ <weight>0.050</weight>
268
+ <size>0</size>
269
+ </from>
270
+ <to>
271
+ <zip>99999999</zip>
272
+ <weight>0.100</weight>
273
+ <size>30</size>
274
+ </to>
275
+ </add_method_2>
276
+ <add_method_3>
277
+ <code>10065</code>
278
+ <price>3.00</price>
279
+ <days>5</days>
280
+ <from>
281
+ <zip>00000000</zip>
282
+ <weight>0.100</weight>
283
+ <size>0</size>
284
+ </from>
285
+ <to>
286
+ <zip>99999999</zip>
287
+ <weight>0.150</weight>
288
+ <size>30</size>
289
+ </to>
290
+ </add_method_3>
291
+ <add_method_4>
292
+ <code>10065</code>
293
+ <price>3.60</price>
294
+ <days>5</days>
295
+ <from>
296
+ <zip>00000000</zip>
297
+ <weight>0.150</weight>
298
+ <size>0</size>
299
+ </from>
300
+ <to>
301
+ <zip>99999999</zip>
302
+ <weight>0.200</weight>
303
+ <size>30</size>
304
+ </to>
305
+ </add_method_4>
306
+ <add_method_5>
307
+ <code>10065</code>
308
+ <price>4.15</price>
309
+ <days>5</days>
310
+ <from>
311
+ <zip>00000000</zip>
312
+ <weight>0.200</weight>
313
+ <size>0</size>
314
+ </from>
315
+ <to>
316
+ <zip>99999999</zip>
317
+ <weight>0.250</weight>
318
+ <size>30</size>
319
+ </to>
320
+ </add_method_5>
321
+ <add_method_6>
322
+ <code>10065</code>
323
+ <price>4.70</price>
324
+ <days>5</days>
325
+ <from>
326
+ <zip>00000000</zip>
327
+ <weight>0.250</weight>
328
+ <size>0</size>
329
+ </from>
330
+ <to>
331
+ <zip>99999999</zip>
332
+ <weight>0.300</weight>
333
+ <size>30</size>
334
+ </to>
335
+ </add_method_6>
336
+ <add_method_7>
337
+ <code>10065</code>
338
+ <price>5.25</price>
339
+ <days>5</days>
340
+ <from>
341
+ <zip>00000000</zip>
342
+ <weight>0.300</weight>
343
+ <size>0</size>
344
+ </from>
345
+ <to>
346
+ <zip>99999999</zip>
347
+ <weight>0.350</weight>
348
+ <size>30</size>
349
+ </to>
350
+ </add_method_7>
351
+ <add_method_8>
352
+ <code>10065</code>
353
+ <price>5.80</price>
354
+ <days>5</days>
355
+ <from>
356
+ <zip>00000000</zip>
357
+ <weight>0.350</weight>
358
+ <size>0</size>
359
+ </from>
360
+ <to>
361
+ <zip>99999999</zip>
362
+ <weight>0.400</weight>
363
+ <size>30</size>
364
+ </to>
365
+ </add_method_8>
366
+ <add_method_9>
367
+ <code>10065</code>
368
+ <price>6.35</price>
369
+ <days>5</days>
370
+ <from>
371
+ <zip>00000000</zip>
372
+ <weight>0.400</weight>
373
+ <size>0</size>
374
+ </from>
375
+ <to>
376
+ <zip>99999999</zip>
377
+ <weight>0.450</weight>
378
+ <size>30</size>
379
+ </to>
380
+ </add_method_9>
381
+ <add_method_10>
382
+ <code>10065</code>
383
+ <price>6.90</price>
384
+ <days>5</days>
385
+ <from>
386
+ <zip>00000000</zip>
387
+ <weight>0.450</weight>
388
+ <size>0</size>
389
+ </from>
390
+ <to>
391
+ <zip>99999999</zip>
392
+ <weight>0.500</weight>
393
+ <size>30</size>
394
+ </to>
395
+ </add_method_10>
396
+ <add_method_11>
397
+ <code>10138</code>
398
+ <price>4.50</price>
399
+ <days>5</days>
400
+ <from>
401
+ <zip>00000000</zip>
402
+ <weight>0</weight>
403
+ <size>0</size>
404
+ </from>
405
+ <to>
406
+ <zip>99999999</zip>
407
+ <weight>0.020</weight>
408
+ <size>30</size>
409
+ </to>
410
+ </add_method_11>
411
+ <add_method_12>
412
+ <code>10138</code>
413
+ <price>5.00</price>
414
+ <days>5</days>
415
+ <from>
416
+ <zip>00000000</zip>
417
+ <weight>0.020</weight>
418
+ <size>0</size>
419
+ </from>
420
+ <to>
421
+ <zip>99999999</zip>
422
+ <weight>0.050</weight>
423
+ <size>30</size>
424
+ </to>
425
+ </add_method_12>
426
+ <add_method_13>
427
+ <code>10138</code>
428
+ <price>5.65</price>
429
+ <days>5</days>
430
+ <from>
431
+ <zip>00000000</zip>
432
+ <weight>0.050</weight>
433
+ <size>0</size>
434
+ </from>
435
+ <to>
436
+ <zip>99999999</zip>
437
+ <weight>0.100</weight>
438
+ <size>30</size>
439
+ </to>
440
+ </add_method_13>
441
+ <add_method_14>
442
+ <code>10138</code>
443
+ <price>6.20</price>
444
+ <days>5</days>
445
+ <from>
446
+ <zip>00000000</zip>
447
+ <weight>0.100</weight>
448
+ <size>0</size>
449
+ </from>
450
+ <to>
451
+ <zip>99999999</zip>
452
+ <weight>0.150</weight>
453
+ <size>30</size>
454
+ </to>
455
+ </add_method_14>
456
+ <add_method_15>
457
+ <code>10138</code>
458
+ <price>6.80</price>
459
+ <days>5</days>
460
+ <from>
461
+ <zip>00000000</zip>
462
+ <weight>0.150</weight>
463
+ <size>0</size>
464
+ </from>
465
+ <to>
466
+ <zip>99999999</zip>
467
+ <weight>0.200</weight>
468
+ <size>30</size>
469
+ </to>
470
+ </add_method_15>
471
+ <add_method_16>
472
+ <code>10138</code>
473
+ <price>7.35</price>
474
+ <days>5</days>
475
+ <from>
476
+ <zip>00000000</zip>
477
+ <weight>0.200</weight>
478
+ <size>0</size>
479
+ </from>
480
+ <to>
481
+ <zip>99999999</zip>
482
+ <weight>0.250</weight>
483
+ <size>30</size>
484
+ </to>
485
+ </add_method_16>
486
+ <add_method_17>
487
+ <code>10138</code>
488
+ <price>7.90</price>
489
+ <days>5</days>
490
+ <from>
491
+ <zip>00000000</zip>
492
+ <weight>0.250</weight>
493
+ <size>0</size>
494
+ </from>
495
+ <to>
496
+ <zip>99999999</zip>
497
+ <weight>0.300</weight>
498
+ <size>30</size>
499
+ </to>
500
+ </add_method_17>
501
+ <add_method_18>
502
+ <code>10138</code>
503
+ <price>8.45</price>
504
+ <days>5</days>
505
+ <from>
506
+ <zip>00000000</zip>
507
+ <weight>0.300</weight>
508
+ <size>0</size>
509
+ </from>
510
+ <to>
511
+ <zip>99999999</zip>
512
+ <weight>0.350</weight>
513
+ <size>30</size>
514
+ </to>
515
+ </add_method_18>
516
+ <add_method_19>
517
+ <code>10138</code>
518
+ <price>9.00</price>
519
+ <days>5</days>
520
+ <from>
521
+ <zip>00000000</zip>
522
+ <weight>0.350</weight>
523
+ <size>0</size>
524
+ </from>
525
+ <to>
526
+ <zip>99999999</zip>
527
+ <weight>0.400</weight>
528
+ <size>30</size>
529
+ </to>
530
+ </add_method_19>
531
+ <add_method_20>
532
+ <code>10138</code>
533
+ <price>9.55</price>
534
+ <days>5</days>
535
+ <from>
536
+ <zip>00000000</zip>
537
+ <weight>0.400</weight>
538
+ <size>0</size>
539
+ </from>
540
+ <to>
541
+ <zip>99999999</zip>
542
+ <weight>0.450</weight>
543
+ <size>30</size>
544
+ </to>
545
+ </add_method_20>
546
+ <add_method_21>
547
+ <code>10138</code>
548
+ <price>10.10</price>
549
+ <days>5</days>
550
+ <from>
551
+ <zip>00000000</zip>
552
+ <weight>0.450</weight>
553
+ <size>0</size>
554
+ </from>
555
+ <to>
556
+ <zip>99999999</zip>
557
+ <weight>0.500</weight>
558
+ <size>30</size>
559
+ </to>
560
+ </add_method_21>
561
  </pedroteixeira_correios>
562
  </carriers>
563
  </default>
app/code/community/PedroTeixeira/Correios/etc/system.xml CHANGED
@@ -6,9 +6,10 @@
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>
@@ -30,6 +31,7 @@
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 />
@@ -216,15 +218,6 @@
216
  <show_in_website>1</show_in_website>
217
  <show_in_store>1</show_in_store>
218
  </max_order_value>
219
- <maxweight translate="label">
220
- <label>Peso Máximo Permitido Pelos Correios</label>
221
- <frontend_type>text</frontend_type>
222
- <sort_order>150</sort_order>
223
- <show_in_default>1</show_in_default>
224
- <show_in_website>1</show_in_website>
225
- <show_in_store>1</show_in_store>
226
- <comment>Utilize o mesmo formato de peso configurado no módulo, kilos ou gramas.</comment>
227
- </maxweight>
228
  <handling_fee translate="label">
229
  <label>Taxa de Postagem</label>
230
  <frontend_type>text</frontend_type>
@@ -275,14 +268,6 @@
275
  <show_in_website>1</show_in_website>
276
  <show_in_store>1</show_in_store>
277
  </zipcodeerror>
278
- <maxweighterror translate="label">
279
- <label>Mensagem de Peso Fora do Permitido</label>
280
- <frontend_type>textarea</frontend_type>
281
- <sort_order>220</sort_order>
282
- <show_in_default>1</show_in_default>
283
- <show_in_website>1</show_in_website>
284
- <show_in_store>1</show_in_store>
285
- </maxweighterror>
286
  <weightzeroerror translate="label">
287
  <label>Mensagem de Peso Zero</label>
288
  <frontend_type>textarea</frontend_type>
@@ -319,6 +304,36 @@
319
  mostrar as mensagens de erro?
320
  </comment>
321
  </showmethod>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  <sort_order translate="label">
323
  <label>Ordenar Por</label>
324
  <frontend_type>text</frontend_type>
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
  -->
15
  <config>
31
  <p>Lembre-se de configurar as "Definições de Envio" no menu ao lado esquerdo.</p>
32
  <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>
33
  <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>
34
+ <p>Agradecimento especial para todos os <a href="https://github.com/pedro-teixeira/correios/graphs/contributors" target="_blank">contribuidores</a>.</p>
35
  <p>Pedro Teixeira [<a href="http://pedroteixeira.io/" target="_blank">pedroteixeira.io</a> ]</p>
36
  <br />
37
  <hr />
218
  <show_in_website>1</show_in_website>
219
  <show_in_store>1</show_in_store>
220
  </max_order_value>
 
 
 
 
 
 
 
 
 
221
  <handling_fee translate="label">
222
  <label>Taxa de Postagem</label>
223
  <frontend_type>text</frontend_type>
268
  <show_in_website>1</show_in_website>
269
  <show_in_store>1</show_in_store>
270
  </zipcodeerror>
 
 
 
 
 
 
 
 
271
  <weightzeroerror translate="label">
272
  <label>Mensagem de Peso Zero</label>
273
  <frontend_type>textarea</frontend_type>
304
  mostrar as mensagens de erro?
305
  </comment>
306
  </showmethod>
307
+ <filter_by_item translate="label">
308
+ <label>Habilitar Filtro de Serviços por Produto</label>
309
+ <frontend_type>select</frontend_type>
310
+ <source_model>adminhtml/system_config_source_yesno</source_model>
311
+ <sort_order>265</sort_order>
312
+ <show_in_default>1</show_in_default>
313
+ <show_in_website>1</show_in_website>
314
+ <show_in_store>1</show_in_store>
315
+ <comment>A cotação irá exibir somente os serviços de postagem comuns a todos os produtos do carrinho de compras.</comment>
316
+ </filter_by_item>
317
+ <cache_mode translate="label">
318
+ <label>Modo de Prioridade da Cache</label>
319
+ <frontend_type>select</frontend_type>
320
+ <source_model>PedroTeixeira_Correios_Model_Source_CacheMode</source_model>
321
+ <sort_order>267</sort_order>
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
+ <comment>Esta configuração se aplica somente quando Correios Cache estiver ativo, em Sistema > Gerenciar Cache.</comment>
326
+ </cache_mode>
327
+ <split_pack translate="label">
328
+ <label>Habilitar Divisão de Pacotes</label>
329
+ <frontend_type>select</frontend_type>
330
+ <source_model>adminhtml/system_config_source_yesno</source_model>
331
+ <sort_order>268</sort_order>
332
+ <show_in_default>1</show_in_default>
333
+ <show_in_website>1</show_in_website>
334
+ <show_in_store>1</show_in_store>
335
+ <comment>O pacote é dividido, caso o carrinho exceda os limites de peso e tamanho, para todos os serviços. A divisão se repete até que os limites sejam válidos, para um ou mais serviços.</comment>
336
+ </split_pack>
337
  <sort_order translate="label">
338
  <label>Ordenar Por</label>
339
  <frontend_type>text</frontend_type>
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.0.0.php CHANGED
@@ -6,9 +6,10 @@
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 */
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
 
15
  /** @var $installer Mage_Core_Model_Resource_Setup */
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.0.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
+ */
14
+
15
+ /** @var $installer Mage_Core_Model_Resource_Setup */
16
+ $installer = $this;
17
+ $installer->startSetup();
18
+
19
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
20
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
21
+
22
+ // Add volume to prduct attribute set
23
+ $codigo = 'volume_comprimento';
24
+ $config = array(
25
+ 'position' => 1,
26
+ 'required' => 0,
27
+ 'label' => 'Comprimento (cm)',
28
+ 'type' => 'int',
29
+ 'input' => 'text',
30
+ 'apply_to' => 'simple,bundle,grouped,configurable',
31
+ 'note' => 'Comprimento da embalagem do produto (Para cálculo dos Correios)'
32
+ );
33
+
34
+ $setup->addAttribute('catalog_product', $codigo, $config);
35
+
36
+ // Add volume to prduct attribute set
37
+ $codigo = 'volume_altura';
38
+ $config = array(
39
+ 'position' => 1,
40
+ 'required' => 0,
41
+ 'label' => 'Altura (cm)',
42
+ 'type' => 'int',
43
+ 'input' => 'text',
44
+ 'apply_to' => 'simple,bundle,grouped,configurable',
45
+ 'note' => 'Altura da embalagem do produto (Para cálculo dos Correios)'
46
+ );
47
+
48
+ $setup->addAttribute('catalog_product', $codigo, $config);
49
+
50
+ // Add volume to prduct attribute set
51
+ $codigo = 'volume_largura';
52
+ $config = array(
53
+ 'position' => 1,
54
+ 'required' => 0,
55
+ 'label' => 'Largura (cm)',
56
+ 'type' => 'int',
57
+ 'input' => 'text',
58
+ 'apply_to' => 'simple,bundle,grouped,configurable',
59
+ 'note' => 'Largura da embalagem do produto (Para cálculo dos Correios)'
60
+ );
61
+
62
+ $setup->addAttribute('catalog_product', $codigo, $config);
63
+
64
+ $codigo = 'postmethods';
65
+ $config = array(
66
+ 'position' => 1,
67
+ 'required' => 0,
68
+ 'label' => 'Serviços de Entrega',
69
+ 'type' => 'text',
70
+ 'input' => 'multiselect',
71
+ 'source' => 'pedroteixeira_correios/source_postMethods',
72
+ 'backend' => 'eav/entity_attribute_backend_array',
73
+ 'apply_to' => 'simple,bundle,grouped,configurable',
74
+ 'note' => 'Selecione os serviços apropriados para o produto.'
75
+ );
76
+
77
+ $setup->addAttribute('catalog_product', $codigo, $config);
78
+
79
+ $codigo = 'fit_size';
80
+ $config = array(
81
+ 'position' => 1,
82
+ 'required' => 0,
83
+ 'label' => 'Diferença do Encaixe (cm)',
84
+ 'type' => 'varchar',
85
+ 'input' => 'text',
86
+ 'apply_to' => 'simple,bundle,grouped,configurable',
87
+ 'note' => 'Exemplo: Se 1 item mede 10cm de altura, e 2 itens encaixados medem 11cm. A diferença é de 1cm.'
88
+ );
89
+
90
+ $setup->addAttribute('catalog_product', $codigo, $config);
91
+
92
+ $installer->endSetup();
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.0.0-4.1.0.php CHANGED
@@ -6,9 +6,10 @@
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 */
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
 
15
  /** @var $installer Mage_Core_Model_Resource_Setup */
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.1.0-4.2.0.php CHANGED
@@ -6,9 +6,10 @@
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 */
@@ -18,7 +19,9 @@ $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
 
@@ -34,7 +37,9 @@ if (count($methods) <= 0) {
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');
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
 
15
  /** @var $installer Mage_Core_Model_Resource_Setup */
19
 
20
  $installer->deleteConfigData('carriers/pedroteixeira_correios/urlmethod');
21
 
22
+ $sql = 'select value from ' .
23
+ $installer->getTable('core/config_data') .
24
+ ' where path="carriers/pedroteixeira_correios/postmethods"';
25
 
26
  $methods = explode(',', $connection->fetchOne($sql));
27
 
37
 
38
  $installer->setConfigData('carriers/pedroteixeira_correios/postmethods', implode(',', $methods));
39
 
40
+ $sql = 'select value from ' .
41
+ $installer->getTable('core/config_data') .
42
+ ' where path="carriers/pedroteixeira_correios/free_method"';
43
 
44
  if ($connection->fetchOne($sql) == '41025') {
45
  $installer->setConfigData('carriers/pedroteixeira_correios/free_method', '41106');
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.2.0-4.3.0.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
+ */
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.3.0-4.4.0.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
+ */
14
+
15
+ /** @var $installer Mage_Core_Model_Resource_Setup */
16
+ $installer = $this;
17
+ $installer->startSetup();
18
+
19
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
20
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
21
+
22
+ $codigo = 'postmethods';
23
+ $config = array(
24
+ 'position' => 1,
25
+ 'required' => 0,
26
+ 'label' => 'Serviços de Entrega',
27
+ 'type' => 'text',
28
+ 'input' => 'multiselect',
29
+ 'source' => 'pedroteixeira_correios/source_postMethods',
30
+ 'backend' => 'eav/entity_attribute_backend_array',
31
+ 'apply_to' => 'simple,bundle,grouped,configurable',
32
+ 'note' => 'Selecione os serviços apropriados para o produto.'
33
+ );
34
+
35
+ $setup->addAttribute('catalog_product', $codigo, $config);
36
+
37
+ $codigo = 'fit_size';
38
+ $config = array(
39
+ 'position' => 1,
40
+ 'required' => 0,
41
+ 'label' => 'Diferença do Encaixe (cm)',
42
+ 'type' => 'varchar',
43
+ 'input' => 'text',
44
+ 'apply_to' => 'simple,bundle,grouped,configurable',
45
+ 'note' => 'Exemplo: Se 1 item mede 10cm de altura, e 2 itens encaixados medem 11cm. A diferença é de 1cm.'
46
+ );
47
+
48
+ $setup->addAttribute('catalog_product', $codigo, $config);
49
+
50
+ $installer->endSetup();
app/etc/modules/PedroTeixeira_Correios.xml CHANGED
@@ -6,9 +6,10 @@
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>
6
  *
7
  * @category PedroTeixeira
8
  * @package PedroTeixeira_Correios
 
9
  * @author Pedro Teixeira <hello@pedroteixeira.io>
10
+ * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
11
+ * @license http://opensource.org/licenses/MIT MIT
12
+ * @link https://github.com/pedro-teixeira/correios
13
  */
14
  -->
15
  <config>
package.xml CHANGED
@@ -1,15 +1,13 @@
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&#xF3;dulo de c&#xE1;lculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje e Sedex a Cobrar.</summary>
10
- <description>Vers&#xE3;o 4.3.0 do m&#xF3;dulo de c&#xE1;lculo de frete para Magento.&#xD;
11
- &#xD;
12
- Utilizando peso volum&#xE9;trico para c&#xE1;lculo de todos os servi&#xE7;os e compat&#xED;vel com a valida&#xE7;&#xE3;o de dimens&#xF5;es dos Correios. &#xD;
13
  &#xD;
14
  Servi&#xE7;os suportados:&#xD;
15
  &#xD;
@@ -21,24 +19,41 @@ Servi&#xE7;os suportados:&#xD;
21
  - Sedex 10&#xD;
22
  - Sedex HOJE&#xD;
23
  - Sedex a Cobrar&#xD;
 
 
 
24
  &#xD;
25
- Conta com identifica&#xE7;&#xE3;o de erros dos Correios, m&#xE3;o pr&#xF3;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.&#xD;
26
  &#xD;
27
- Mais informa&#xE7;&#xF5;es em http://pedroteixeira.io</description>
28
  <notes>Bugfix:&#xD;
29
  &#xD;
30
- - Assinatura do m&#xE9;todo isZipCodeRequired() foi alterada&#xD;
 
 
 
 
 
31
  &#xD;
32
  Feature:&#xD;
33
  &#xD;
34
- - Revis&#xE3;o do code style&#xD;
35
- - Documenta&#xE7;&#xE3;o em markdown&#xD;
36
- - Novos c&#xF3;digos de erros dos Correios&#xD;
37
- - Novos limites de dimens&#xE3;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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>PedroTeixeira_Correios</name>
4
+ <version>4.4.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&#xF3;dulo de c&#xE1;lculo de PAC, Sedex, E-Sedex, Sedex 10, Sedex Hoje, Sedex a Cobrar, PAC GF e Carta Comercial.</summary>
10
+ <description>Utilizando peso volum&#xE9;trico para c&#xE1;lculo de todos os servi&#xE7;os e compat&#xED;vel com a valida&#xE7;&#xE3;o de dimens&#xF5;es dos Correios.&#xD;
 
 
11
  &#xD;
12
  Servi&#xE7;os suportados:&#xD;
13
  &#xD;
19
  - Sedex 10&#xD;
20
  - Sedex HOJE&#xD;
21
  - Sedex a Cobrar&#xD;
22
+ - PAC GF&#xD;
23
+ - Carta Comercial&#xD;
24
+ - Carta Comercial Registrada&#xD;
25
  &#xD;
26
+ Conta com identifica&#xE7;&#xE3;o de erros dos Correios, m&#xE3;o pr&#xF3;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, tracking em tempo real, cache, pacotes de grandes formato e produtos encaixados.&#xD;
27
  &#xD;
28
+ Mais informa&#xE7;&#xF5;es em https://pedroteixeira.io.</description>
29
  <notes>Bugfix:&#xD;
30
  &#xD;
31
+ - Usar atributo para setar o carrier name e passar o encoding para htmlentities&#xD;
32
+ - Erro 99 Input string was not in a correct format&#xD;
33
+ - Peso c&#xFA;bico n&#xE3;o calculado no backend&#xD;
34
+ - Corrige a leitura do valor de frete&#xD;
35
+ - Frete de mil reais exibido por 1 real&#xD;
36
+ - Problema com peso do E-SEDEX&#xD;
37
  &#xD;
38
  Feature:&#xD;
39
  &#xD;
40
+ - Adiciona CONTRIBUTING.md&#xD;
41
+ - Adiciona badges&#xD;
42
+ - Integra&#xE7;&#xE3;o com Travis&#xD;
43
+ - Testado em Magento 1.9.1.0&#xD;
44
+ - Servi&#xE7;os por produto, valida&#xE7;&#xE3;o por servi&#xE7;o, grandes formatos, carta registrada, cache&#xD;
45
+ - Considerar produtos encaixados&#xD;
46
+ - Adicionar PAC grandes formatos aos servi&#xE7;os de postagem&#xD;
47
+ - Valida&#xE7;&#xE3;o de peso e dimens&#xF5;es&#xD;
48
+ - Selecionar servi&#xE7;os por produto&#xD;
49
+ - Suporte para instala&#xE7;&#xF5;es modman&#xD;
50
+ - Integrar carta registrada&#xD;
51
+ - Implementar cache de respostas dos Correios&#xD;
52
+ - Op&#xE7;&#xE3;o de dividir a entrega em mais de um pacote</notes>
53
  <authors><author><name>Pedro Teixeira</name><user>teixeirapedro</user><email>hello@pedroteixeira.io</email></author></authors>
54
+ <date>2015-03-30</date>
55
+ <time>17:47:09</time>
56
+ <contents><target name="magecommunity"><dir name="PedroTeixeira"><dir name="Correios"><dir name="Helper"><file name="Data.php" hash="a030f07c60af40e9817054800096207f"/></dir><dir name="Model"><file name="Cache.php" hash="60a1fd3536bbeb00e4d2e67b8cc5ea94"/><dir name="Carrier"><file name="CorreiosMethod.php" hash="d3ddd84f037995c132467390fb019445"/></dir><dir name="Http"><dir name="Client"><dir name="Adapter"><file name="Socket.php" hash="76da85f117c3f9950164a5d90500d82f"/></dir></dir></dir><dir name="Source"><file name="CacheMode.php" hash="b34ae611b8bf913e4b646f4a156cc2a4"/><file name="PostMethods.php" hash="b251451bf944b1488c477d58c4c8985d"/><file name="WeightType.php" hash="4bf1608fb6b665dcc7d834ca35eee174"/></dir></dir><dir name="etc"><file name="config.xml" hash="c45f18929175ffc1f7d59dee0e88e34b"/><file name="system.xml" hash="6ffa11314b0bd87a521a69e508463a47"/></dir><dir name="sql"><dir name="pedroteixeira_correios_setup"><file name="install-4.0.0.php" hash="eda109c002d9130fc1ce807784aa60a3"/><file name="install-4.4.0.php" hash="889c7376ee7bdd30bf07616b4f365e3b"/><file name="upgrade-4.0.0-4.1.0.php" hash="ca42fdabb0975f60d8cf5ef5ab122acd"/><file name="upgrade-4.1.0-4.2.0.php" hash="319cd1c4ddaa745da9af4a5111aa1534"/><file name="upgrade-4.2.0-4.3.0.php" hash="783e854d19b0e4915360cc1ec8b4d2d0"/><file name="upgrade-4.3.0-4.4.0.php" hash="982f41d3a113d21c4008de7e63918e45"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PedroTeixeira_Correios.xml" hash="e714579bed97c85f2bcc3988dec271da"/></dir></target></contents>
57
  <compatible/>
58
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name/><channel>connect.magentocommerce.com/core</channel><min/><max/></package></required></dependencies>
59
  </package>