PedroTeixeira_Correios - Version 4.7.0

Version Notes

Bugfix:

- Fix para frete com desconto/grátis em áreas com restrição de entrega
- Configuração de ajuste
- Added Validation to null postcode in cart update
- Removida a função trim em contexto de variável
- Correção para Warning: Invalid argument supplied for foreach
- Fix noservices error
- Correção para referência de items para cálculo do request

Feature:

- Adicionada compatibilidade com pacote de produtos
- Monitoramento Automático da Encomenda, e Atualização do Status da Entrega
- Adicionado serviço 40436 com contrato
- Instalando com Modgit
- Evitando load de produto
- Aba dos Correios na edição de produtos

Download this release

Release Info

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


Code changes from version 4.5.0 to 4.7.0

app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php CHANGED
@@ -89,7 +89,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
89
  }
90
 
91
  if ($this->_packageWeight == 0) {
92
- $this->_packageWeight = $this->_getNominalWeight();
93
  }
94
 
95
  if ($this->getConfigData('weight_type') == PedroTeixeira_Correios_Model_Source_WeightType::WEIGHT_GR) {
@@ -107,40 +107,66 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
107
  $this->_postMethodsExplode = explode(',', $this->getConfigData('postmethods'));
108
 
109
  // Generate Volume Weight
110
- if ($this->_generateVolumeWeight() === false || $this->_removeInvalidServices() === false) {
111
  $this->_throwError('dimensionerror', 'Dimension error', __LINE__);
112
  return $this->_result;
113
  }
114
 
115
- $this->_filterMethodByItemRestriction();
116
- if ($this->_getQuotes()->getError()) {
117
- return $this->_result;
 
118
  }
 
 
119
 
120
  // Use descont codes
121
  $this->_updateFreeMethodQuote($request);
122
 
123
  return $this->_result;
124
  }
125
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  /**
127
  * Gets Nominal Weight
128
  *
 
 
129
  * @return number
130
  */
131
- protected function _getNominalWeight()
132
  {
133
  $weight = 0;
134
- $quote = Mage::getSingleton('checkout/cart')->getQuote();
135
- if (count($quote->getAllVisibleItems()) == 0) {
136
- $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
137
- }
138
- if ($quote->isNominal()) {
139
- foreach ($quote->getAllVisibleItems() as $item) {
140
- $product = Mage::getModel('catalog/product')->load($item->getProductId());
141
- $weight += $product->getWeight();
142
- }
143
  }
 
144
  return $weight;
145
  }
146
 
@@ -155,40 +181,22 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
155
  $correiosReturn = $this->_getCorreiosReturn();
156
 
157
  if ($correiosReturn !== false) {
158
-
159
  $correiosReturn = $this->_addPostMethods($correiosReturn);
160
- $existReturn = false;
161
 
162
  foreach ($correiosReturn as $servicos) {
163
 
164
  $errorId = (string) $servicos->Erro;
 
165
 
166
  if ($errorId != '0' && !in_array($errorId, $softErrors)) {
167
  continue;
168
  }
169
 
170
- $stringPrice = (string) $servicos->Valor;
171
- $stringPrice = str_replace('.', '', $stringPrice);
172
- $stringPrice = str_replace(',', '.', $stringPrice);
173
- $shippingPrice = floatval($stringPrice);
174
- $shippingPrice *= pow(2, $this->_splitUp);
175
- $shippingDelivery = (int) $servicos->PrazoEntrega;
176
-
177
- if ($shippingPrice <= 0) {
178
- continue;
179
- }
180
-
181
- $this->_appendShippingReturn((string) $servicos->Codigo, $shippingPrice, $shippingDelivery);
182
- if ($this->getConfigFlag('show_soft_errors') && !isset($isWarnAppended)) {
183
- $isWarnAppended = $this->_appendShippingWarning($servicos);
184
- }
185
- $existReturn = true;
186
- }
187
-
188
- if ($existReturn === false) {
189
- $this->_throwError('urlerror', 'URL Error, all services return with error', __LINE__);
190
- return $this->_result;
191
  }
 
192
  } else {
193
  return $this->_result;
194
  }
@@ -236,6 +244,10 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
236
  return false;
237
  }
238
 
 
 
 
 
239
  $this->_result = Mage::getModel('shipping/rate_result');
240
  $this->_packageValue = $request->getBaseCurrency()->convert(
241
  $request->getPackageValue(),
@@ -342,18 +354,23 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
342
  /**
343
  * Apend shipping value to return
344
  *
345
- * @param string $shippingMethod Method of shipping
346
- * @param int $shippingPrice Price
347
- * @param int $correiosDelivery Delivery date
348
  *
349
  * @return void
350
  */
351
- protected function _appendShippingReturn($shippingMethod, $shippingPrice = 0, $correiosDelivery = 0)
352
  {
 
 
 
 
 
 
353
 
 
354
  $method = Mage::getModel('shipping/rate_result_method');
355
  $method->setCarrier($this->_code);
356
- $method->setCarrierTitle($this->getConfigData('title'));
357
  $method->setMethod($shippingMethod);
358
 
359
  $shippingCost = $shippingPrice;
@@ -431,17 +448,15 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
431
  /**
432
  * Generate Volume weight
433
  *
 
 
434
  * @return bool
435
  */
436
- protected function _generateVolumeWeight()
437
  {
438
  $pesoCubicoTotal = 0;
439
 
440
- $items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
441
-
442
- if (count($items) == 0) {
443
- $items = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
444
- }
445
 
446
  foreach ($items as $item) {
447
  $_product = $item->getProduct();
@@ -486,7 +501,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
486
 
487
  $itemAltura = $this->_getFitHeight($item);
488
  $pesoCubicoTotal += (($itemAltura * $itemLargura * $itemComprimento) *
489
- $item->getQty()) / $this->getConfigData('coeficiente_volume');
490
 
491
  $this->_postingDays = max($this->_postingDays, (int) $_product->getData('posting_days'));
492
  }
@@ -721,7 +736,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
721
  $tmpMethods = $this->_postMethodsExplode;
722
  $tmpMethods = $this->_filterMethodByConfigRestriction($tmpMethods);
723
  $isDivisible = (count($tmpMethods) == 0);
724
-
725
  if ($isDivisible) {
726
  return $this->_splitPack();
727
  }
@@ -761,6 +776,9 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
761
  protected function _addPostMethods($cServico)
762
  {
763
  $addMethods = $this->getConfigData("add_postmethods");
 
 
 
764
  foreach ($addMethods as $configData) {
765
  $isValid = true;
766
  $isValid &= $this->_packageWeight >= $configData['from']['weight'];
@@ -808,17 +826,15 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
808
  * ...
809
  * value 99: 81019
810
  *
 
 
811
  * @return PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
812
  */
813
- protected function _filterMethodByItemRestriction()
814
  {
815
  if ($this->getConfigFlag('filter_by_item')) {
816
- $items = Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems();
817
-
818
- if (count($items) == 0) {
819
- $items = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getAllVisibleItems();
820
- }
821
 
 
822
  $intersection = $this->_postMethodsExplode;
823
  foreach ($items as $item) {
824
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
@@ -887,9 +903,9 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
887
  /**
888
  * Receive a list of methods, and validate one-by-one using the config settings.
889
  * Returns a list of valid methods or empty.
890
- *
891
  * @param array $postmethods Services List
892
- *
893
  * @return array
894
  */
895
  protected function _filterMethodByConfigRestriction($postmethods)
@@ -913,9 +929,9 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
913
  /**
914
  * Loads the zip range list.
915
  * Returns TRUE only if zip target is included in the range.
916
- *
917
  * @param array $method Current Post Method
918
- *
919
  * @return boolean
920
  */
921
  protected function _validateZipRestriction($method)
@@ -934,23 +950,116 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
934
  }
935
 
936
  /**
937
- * Add a warning message at the top of the shipping method list.
 
938
  *
939
- * @param SimpleXMLElement $servico Post Method
940
  *
941
  * @return boolean
942
  */
943
- protected function _appendShippingWarning(SimpleXMLElement $servico)
944
  {
945
- $id = (string) $servico->Erro;
946
- $ids = explode(',', $this->getConfigData('soft_errors'));
947
- if (in_array($id, $ids)) {
948
- $error = Mage::getModel('shipping/rate_result_error');
949
- $error->setCarrier($this->_code);
950
- $error->setErrorMessage($servico->MsgErro);
951
- $this->_result->append($error);
952
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
  }
954
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
  }
956
  }
89
  }
90
 
91
  if ($this->_packageWeight == 0) {
92
+ $this->_packageWeight = $this->_getNominalWeight($request);
93
  }
94
 
95
  if ($this->getConfigData('weight_type') == PedroTeixeira_Correios_Model_Source_WeightType::WEIGHT_GR) {
107
  $this->_postMethodsExplode = explode(',', $this->getConfigData('postmethods'));
108
 
109
  // Generate Volume Weight
110
+ if ($this->_generateVolumeWeight($request) === false || $this->_removeInvalidServices() === false) {
111
  $this->_throwError('dimensionerror', 'Dimension error', __LINE__);
112
  return $this->_result;
113
  }
114
 
115
+ $this->_filterMethodByItemRestriction($request);
116
+
117
+ if (empty($this->_postMethods)) {
118
+ return false;
119
  }
120
+ //Show Quotes
121
+ $this->_getQuotes();
122
 
123
  // Use descont codes
124
  $this->_updateFreeMethodQuote($request);
125
 
126
  return $this->_result;
127
  }
128
+
129
+ /**
130
+ * Retrieve all visible items from request
131
+ *
132
+ * @param Mage_Shipping_Model_Rate_Request $request Mage request
133
+ *
134
+ * @return array
135
+ */
136
+ protected function _getRequestItems($request)
137
+ {
138
+
139
+ $allItems = $request->getAllItems();
140
+ $items = array();
141
+
142
+ foreach ( $allItems as $item ) {
143
+ if ( !$item->getParentItemId() ) {
144
+ $items[] = $item;
145
+ }
146
+ }
147
+
148
+ $items = $this->_loadBundleChildren($items);
149
+
150
+ return $items;
151
+ }
152
+
153
  /**
154
  * Gets Nominal Weight
155
  *
156
+ * @param Mage_Shipping_Model_Rate_Request $request Mage request
157
+ *
158
  * @return number
159
  */
160
+ protected function _getNominalWeight($request)
161
  {
162
  $weight = 0;
163
+ $items = $this->_getRequestItems($request);
164
+
165
+ foreach ($items as $item) {
166
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
167
+ $weight += $product->getWeight();
 
 
 
 
168
  }
169
+
170
  return $weight;
171
  }
172
 
181
  $correiosReturn = $this->_getCorreiosReturn();
182
 
183
  if ($correiosReturn !== false) {
184
+ $errorList = array();
185
  $correiosReturn = $this->_addPostMethods($correiosReturn);
 
186
 
187
  foreach ($correiosReturn as $servicos) {
188
 
189
  $errorId = (string) $servicos->Erro;
190
+ $errorList[$errorId] = $servicos->MsgErro;
191
 
192
  if ($errorId != '0' && !in_array($errorId, $softErrors)) {
193
  continue;
194
  }
195
 
196
+ $servicos->Valor = $this->_getFormatPrice((string) $servicos->Valor);
197
+ $this->_appendShippingReturn($servicos);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  }
199
+ $this->_appendShippingErrors($errorList);
200
  } else {
201
  return $this->_result;
202
  }
244
  return false;
245
  }
246
 
247
+ if (!trim($this->_toZip)) {
248
+ return false;
249
+ }
250
+
251
  $this->_result = Mage::getModel('shipping/rate_result');
252
  $this->_packageValue = $request->getBaseCurrency()->convert(
253
  $request->getPackageValue(),
354
  /**
355
  * Apend shipping value to return
356
  *
357
+ * @param SimpleXMLElement $servico Service Data
 
 
358
  *
359
  * @return void
360
  */
361
+ protected function _appendShippingReturn(SimpleXMLElement $servico)
362
  {
363
+ $correiosDelivery = (int) $servico->PrazoEntrega;
364
+ $shippingMethod = (string) $servico->Codigo;
365
+ $shippingPrice = (float) $servico->Valor;
366
+ if ($shippingPrice <= 0) {
367
+ return;
368
+ }
369
 
370
+ $errorMsg = $this->_getSoftErrorMsg((string) $servico->Erro);
371
  $method = Mage::getModel('shipping/rate_result_method');
372
  $method->setCarrier($this->_code);
373
+ $method->setCarrierTitle($this->getConfigData('title') . $this->_getSplitUpMsg() . $errorMsg);
374
  $method->setMethod($shippingMethod);
375
 
376
  $shippingCost = $shippingPrice;
448
  /**
449
  * Generate Volume weight
450
  *
451
+ * @param Mage_Shipping_Model_Rate_Request $request Mage request
452
+ *
453
  * @return bool
454
  */
455
+ protected function _generateVolumeWeight($request)
456
  {
457
  $pesoCubicoTotal = 0;
458
 
459
+ $items = $this->_getRequestItems($request);
 
 
 
 
460
 
461
  foreach ($items as $item) {
462
  $_product = $item->getProduct();
501
 
502
  $itemAltura = $this->_getFitHeight($item);
503
  $pesoCubicoTotal += (($itemAltura * $itemLargura * $itemComprimento) *
504
+ $item->getTotalQty()) / $this->getConfigData('coeficiente_volume');
505
 
506
  $this->_postingDays = max($this->_postingDays, (int) $_product->getData('posting_days'));
507
  }
736
  $tmpMethods = $this->_postMethodsExplode;
737
  $tmpMethods = $this->_filterMethodByConfigRestriction($tmpMethods);
738
  $isDivisible = (count($tmpMethods) == 0);
739
+
740
  if ($isDivisible) {
741
  return $this->_splitPack();
742
  }
776
  protected function _addPostMethods($cServico)
777
  {
778
  $addMethods = $this->getConfigData("add_postmethods");
779
+ if (empty($addMethods) || !is_array($addMethods)) {
780
+ return $cServico;
781
+ }
782
  foreach ($addMethods as $configData) {
783
  $isValid = true;
784
  $isValid &= $this->_packageWeight >= $configData['from']['weight'];
826
  * ...
827
  * value 99: 81019
828
  *
829
+ * @param Mage_Shipping_Model_Rate_Request $request Mage request
830
+ *
831
  * @return PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
832
  */
833
+ protected function _filterMethodByItemRestriction($request)
834
  {
835
  if ($this->getConfigFlag('filter_by_item')) {
 
 
 
 
 
836
 
837
+ $items = $this->_getRequestItems($request);
838
  $intersection = $this->_postMethodsExplode;
839
  foreach ($items as $item) {
840
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
903
  /**
904
  * Receive a list of methods, and validate one-by-one using the config settings.
905
  * Returns a list of valid methods or empty.
906
+ *
907
  * @param array $postmethods Services List
908
+ *
909
  * @return array
910
  */
911
  protected function _filterMethodByConfigRestriction($postmethods)
929
  /**
930
  * Loads the zip range list.
931
  * Returns TRUE only if zip target is included in the range.
932
+ *
933
  * @param array $method Current Post Method
934
+ *
935
  * @return boolean
936
  */
937
  protected function _validateZipRestriction($method)
950
  }
951
 
952
  /**
953
+ * Some special errors must be sent to users.
954
+ * If not applicable, the default error will be sent.
955
  *
956
+ * @param array $errorList Error List
957
  *
958
  * @return boolean
959
  */
960
+ protected function _appendShippingErrors($errorList)
961
  {
962
+ $output = false;
963
+ $successCode = '0';
964
+ $hasValidQuote = array_key_exists($successCode, $errorList);
965
+ if (!$hasValidQuote) {
966
+ $displayErrorList = explode(',', $this->getConfigData('hard_errors'));
967
+ if ($this->getConfigFlag('show_soft_errors')) {
968
+ $softErrorList = explode(',', $this->getConfigData('soft_errors'));
969
+ $displayErrorList = array_merge($displayErrorList, $softErrorList);
970
+ }
971
+ foreach ($errorList as $errorCode => $errorMsg) {
972
+ $isDisplayError = in_array($errorCode, $displayErrorList);
973
+ if ($isDisplayError) {
974
+ $error = Mage::getModel('shipping/rate_result_error');
975
+ $error->setCarrier($this->_code);
976
+ $error->setErrorMessage($errorMsg);
977
+ $this->_result->append($error);
978
+ $output = true;
979
+ }
980
+ }
981
+ if (!$output) {
982
+ $logMsg = implode(',', $errorList);
983
+ Mage::log("{$this->_code}: Warning! There is no valid quotes, and no one error was throwed: {$logMsg}");
984
+ }
985
  }
986
+ return $output;
987
+ }
988
+
989
+ /**
990
+ * Returns a short message showing the number of the packs that will be needed.
991
+ *
992
+ * @return string
993
+ */
994
+ protected function _getSplitUpMsg()
995
+ {
996
+ $msg = "";
997
+ if ($this->_splitUp > 0) {
998
+ $qty = pow(2, $this->_splitUp);
999
+ $msg.= " / {$qty} volumes";
1000
+ }
1001
+ return $msg;
1002
+ }
1003
+
1004
+ /**
1005
+ * Returns a short warning message.
1006
+ *
1007
+ * @param string $error Error Id
1008
+ *
1009
+ * @return string
1010
+ */
1011
+ protected function _getSoftErrorMsg($error)
1012
+ {
1013
+ $msg = "";
1014
+ if ($this->getConfigFlag('show_soft_errors')) {
1015
+ $softErrorList = explode(',', $this->getConfigData('soft_errors'));
1016
+ $isSoftError = in_array($error, $softErrorList);
1017
+ if ($isSoftError) {
1018
+ $msg.= " / Área de Risco";
1019
+ }
1020
+ }
1021
+ return $msg;
1022
+ }
1023
+
1024
+ /**
1025
+ * Returns the price as float, and fixed by pack division.
1026
+ *
1027
+ * @param string $price Price String
1028
+ *
1029
+ * @return float
1030
+ */
1031
+ protected function _getFormatPrice($price)
1032
+ {
1033
+ $stringPrice = str_replace('.', '', $price);
1034
+ $stringPrice = str_replace(',', '.', $stringPrice);
1035
+ $shippingPrice = floatval($stringPrice);
1036
+ $shippingPrice *= pow(2, $this->_splitUp);
1037
+ return $shippingPrice;
1038
+ }
1039
+
1040
+ /**
1041
+ * Filter visible and bundle children products.
1042
+ *
1043
+ * @param array $items Product Items
1044
+ *
1045
+ * @return array
1046
+ */
1047
+ protected function _loadBundleChildren($items)
1048
+ {
1049
+ $visibleAndBundleChildren = array();
1050
+ /* @var $item Mage_Sales_Model_Quote_Item */
1051
+ foreach ($items as $item) {
1052
+ $product = $item->getProduct();
1053
+ $isBundle = ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE);
1054
+ if ($isBundle) {
1055
+ /* @var $child Mage_Sales_Model_Quote_Item */
1056
+ foreach ($item->getChildren() as $child) {
1057
+ $visibleAndBundleChildren[] = $child;
1058
+ }
1059
+ } else {
1060
+ $visibleAndBundleChildren[] = $item;
1061
+ }
1062
+ }
1063
+ return $visibleAndBundleChildren;
1064
  }
1065
  }
app/code/community/PedroTeixeira/Correios/Model/Observer.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Observer
15
+ {
16
+ /**
17
+ * Look for shipped trackings, and send notifications if available and enabled
18
+ *
19
+ * @return string
20
+ */
21
+ public function sroTrackingJob()
22
+ {
23
+ $count = 0;
24
+ /* @var $sro PedroTeixeira_Correios_Model_Sro */
25
+ $sro = Mage::getModel('pedroteixeira_correios/sro');
26
+ $collection = $sro->getShippedTracks();
27
+ foreach ($collection as $track) {
28
+ /* @var $track Mage_Sales_Model_Order_Shipment_Track */
29
+ if ($sro->request($track->getNumber())) {
30
+ $savedId = $track->getDescription();
31
+ $eventId = $sro->getEventId();
32
+ if ($eventId != $savedId) {
33
+ $track->setDescription($eventId)->save();
34
+ $track->getShipment()->getOrder()
35
+ ->setStatus($sro->getStatus())
36
+ ->save();
37
+ $track->getShipment()
38
+ ->addComment($sro->getComment(), $sro->isNotify(), true)
39
+ ->sendUpdateEmail($sro->isNotify(), $sro->getEmailComment())
40
+ ->save();
41
+ $count++;
42
+ }
43
+ }
44
+ }
45
+ return "Tracked {$count} objects of {$collection->getSize()}.";
46
+ }
47
+ }
app/code/community/PedroTeixeira/Correios/Model/Source/PostMethods.php CHANGED
@@ -23,6 +23,7 @@ class PedroTeixeira_Correios_Model_Source_PostMethods extends Mage_Eav_Model_Ent
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)')),
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' => 40436, 'label' => Mage::helper('adminhtml')->__('Sedex Com Contrato (40436)')),
27
  array('value' => 81019, 'label' => Mage::helper('adminhtml')->__('E-Sedex Com Contrato (81019)')),
28
  array('value' => 41106, 'label' => Mage::helper('adminhtml')->__('PAC Sem Contrato (41106)')),
29
  array('value' => 41068, 'label' => Mage::helper('adminhtml')->__('PAC Com Contrato (41068)')),
app/code/community/PedroTeixeira/Correios/Model/Sro.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Sro extends Varien_Object
15
+ {
16
+ const CARRIER_CODE = 'pedroteixeira_correios';
17
+ const ORDER_SHIPPED_STATUS = 'complete_shipped';
18
+ const ORDER_WARNED_STATUS = 'complete_warned';
19
+
20
+ /**
21
+ * Request response
22
+ *
23
+ * @var SimpleXMLElement
24
+ */
25
+ protected $_xml = null;
26
+
27
+ /**
28
+ * Load all opened tracks from database.
29
+ * Filter tracks only with complete order state, and shipped status.
30
+ *
31
+ * @return Mage_Sales_Model_Resource_Order_Shipment_Track_Collection
32
+ */
33
+ public function getShippedTracks()
34
+ {
35
+ $trackTable = 'main_table';
36
+ $orderTable = Mage::getModel('sales/order')->getCollection()->getResource()->getTable('sales/order');
37
+
38
+ /* @var $collection Mage_Sales_Model_Resource_Order_Shipment_Track_Collection */
39
+ $collection = Mage::getModel('sales/order_shipment_track')->getCollection();
40
+ $collection->getSelect()->join($orderTable, "{$trackTable}.order_id = {$orderTable}.entity_id", array());
41
+ $collection
42
+ ->addFieldToFilter("{$trackTable}.carrier_code", self::CARRIER_CODE)
43
+ ->addFieldToFilter("{$orderTable}.state", Mage_Sales_Model_Order::STATE_COMPLETE)
44
+ ->addFieldToFilter("{$orderTable}.status", array('neq' => Mage_Sales_Model_Order::STATE_COMPLETE));
45
+ return $collection;
46
+ }
47
+
48
+ /**
49
+ * Load XML response from Correios
50
+ *
51
+ * @param string $number Tracking Code
52
+ *
53
+ * @throws Zend_Http_Client_Adapter_Exception
54
+ *
55
+ * @link http://www.correios.com.br/para-voce/correios-de-a-a-z/pdf/rastreamento-de-objetos/
56
+ * Manual_SROXML_28fev14.pdf
57
+ *
58
+ * @return SimpleXMLElement
59
+ */
60
+ public function request($number)
61
+ {
62
+ $client = new Zend_Http_Client($this->getConfigData("url_sro_correios"));
63
+ $client->setParameterPost('Usuario', $this->getConfigData('sro_username'));
64
+ $client->setParameterPost('Senha', $this->getConfigData('sro_password'));
65
+ $client->setParameterPost('Tipo', $this->getConfigData('sro_type'));
66
+ $client->setParameterPost('Resultado', $this->getConfigData('sro_result'));
67
+ $client->setParameterPost('Objetos', $number);
68
+ try {
69
+ $response = $client->request(Zend_Http_Client::POST)->getBody();
70
+ if (empty($response)) {
71
+ throw new Zend_Http_Client_Adapter_Exception("Empty response");
72
+ }
73
+ libxml_use_internal_errors(true);
74
+ $this->_xml = simplexml_load_string($response);
75
+ if (!$this->_xml || !isset($this->_xml->objeto)) {
76
+ throw new Zend_Http_Client_Adapter_Exception("Invalid XML");
77
+ }
78
+ } catch (Zend_Http_Exception $e) {
79
+ Mage::log("{$e->getMessage()}");
80
+ Mage::log("TRACKING: {$number}");
81
+ Mage::log("RESPONSE: {$response}");
82
+ return false;
83
+ }
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * Retrieve config value by path
89
+ *
90
+ * @param string $path Variable Path
91
+ *
92
+ * @return string
93
+ */
94
+ public function getConfigData($path)
95
+ {
96
+ return Mage::getStoreConfig("carriers/" . self::CARRIER_CODE . "/{$path}");
97
+ }
98
+
99
+ /**
100
+ * Returns a Shipping comment message
101
+ *
102
+ * @return string
103
+ */
104
+ public function getComment()
105
+ {
106
+ $code = $this->_xml->objeto->numero;
107
+ $evento = $this->_xml->objeto->evento;
108
+ $msg = array();
109
+ $msg[] = $code;
110
+ $msg[] = "{$evento->cidade}/{$evento->uf}";
111
+ $msg[] = $evento->descricao;
112
+ if (isset($evento->destino) && isset($evento->destino->local)) {
113
+ $last = count($msg) - 1;
114
+ $msg[$last].= " para {$evento->destino->cidade}/{$evento->destino->uf}";
115
+ }
116
+ if (isset($evento->recebedor) && !empty($evento->recebedor)) {
117
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Recebedor: %s', $evento->recebedor);
118
+ }
119
+ if (isset($evento->comentario) && !empty($evento->comentario)) {
120
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Comentário: %s', $evento->comentario);
121
+ }
122
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Evento: %s', "{$evento->tipo}/{$evento->status}");
123
+ return implode(' | ', $msg);
124
+ }
125
+
126
+ /**
127
+ * Returns an Update Shipping e-mail comment
128
+ *
129
+ * @return string
130
+ */
131
+ public function getEmailComment()
132
+ {
133
+ $trackUrl = $this->getConfigData('url_tracking');
134
+ $code = $this->_xml->objeto->numero;
135
+ $evento = $this->_xml->objeto->evento;
136
+ $htmlAnchor = "<a href=\"{$trackUrl}?P_LINGUA=001&P_TIPO=001&P_COD_UNI={$code}\">{$code}</a>";
137
+ $msg = array();
138
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Rastreador: %s', $htmlAnchor);
139
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Local: %s', "{$evento->cidade}/{$evento->uf}");
140
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Situação: %s', $evento->descricao);
141
+ if (isset($evento->recebedor) && !empty($evento->recebedor)) {
142
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Recebedor: %s', $evento->recebedor);
143
+ }
144
+ if (isset($evento->comentario) && !empty($evento->comentario)) {
145
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Comentário: %s', $evento->comentario);
146
+ }
147
+ if (isset($evento->destino)) {
148
+ $destino = $evento->destino;
149
+ $msg[] = Mage::helper('pedroteixeira_correios')->__('Destino: %s', "{$destino->cidade}/{$destino->uf}");
150
+ }
151
+ return implode('<br />', $msg);
152
+ }
153
+
154
+ /**
155
+ * Check the event type
156
+ *
157
+ * @param string $mode Event Type Mode
158
+ *
159
+ * @return boolean
160
+ */
161
+ public function validate($mode)
162
+ {
163
+ $isValid = false;
164
+ $evento = $this->_xml->objeto->evento;
165
+ $hashTypes = explode(',', $this->getConfigData("sro_event_type_{$mode}"));
166
+ if (in_array($evento->tipo, $hashTypes)) {
167
+ $type = strtolower($evento->tipo);
168
+ $hashStatus = explode(',', $this->getConfigData("sro_event_status_{$mode}_{$type}"));
169
+ $isValid = in_array((int) $evento->status, $hashStatus);
170
+ }
171
+ return $isValid;
172
+ }
173
+
174
+ /**
175
+ * Track Description field are now being used to save the event id.
176
+ * Event Id is a simple key to identify the last carrier event.
177
+ *
178
+ * @return string
179
+ */
180
+ public function getEventId()
181
+ {
182
+ $code = $this->_xml->objeto->numero;
183
+ $date = $this->_xml->objeto->evento->data;
184
+ $hour = $this->_xml->objeto->evento->hora;
185
+ $type = $this->_xml->objeto->evento->tipo;
186
+ return "{$code}::{$date}{$hour}::{$type}";
187
+ }
188
+
189
+ /**
190
+ * Check whether event notify is enabled or not
191
+ *
192
+ * @return boolean
193
+ */
194
+ public function isNotify()
195
+ {
196
+ return $this->validate('notify');
197
+ }
198
+
199
+ /**
200
+ * Load order status based on event checking
201
+ *
202
+ * @return string
203
+ */
204
+ public function getStatus()
205
+ {
206
+ $status = self::ORDER_SHIPPED_STATUS;
207
+ if ($this->validate('warn')) {
208
+ $status = self::ORDER_WARNED_STATUS;
209
+ }
210
+ if ($this->validate('last')) {
211
+ $status = Mage_Sales_Model_Order::STATE_COMPLETE;
212
+ }
213
+ return $status;
214
+ }
215
+ }
app/code/community/PedroTeixeira/Correios/etc/config.xml CHANGED
@@ -15,7 +15,7 @@
15
  <config>
16
  <modules>
17
  <PedroTeixeira_Correios>
18
- <version>4.5.0</version>
19
  <depends>
20
  <Mage_Shipping/>
21
  </depends>
@@ -84,6 +84,7 @@
84
  <model>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</model>
85
  <title>Correios</title>
86
  <postmethods>40010</postmethods>
 
87
  <soft_errors>009,010,011</soft_errors>
88
  <show_soft_errors>0</show_soft_errors>
89
  <prazo_entrega>0</prazo_entrega>
@@ -127,6 +128,17 @@
127
  <brasil>00000000,99999999</brasil>
128
  </zips>
129
  </serv_40096>
 
 
 
 
 
 
 
 
 
 
 
130
  <serv_81019>
131
  <max>
132
  <size>105</size>
@@ -389,6 +401,7 @@
389
  <!-- SYSTEM -->
390
  <serv_40010>Sedex,3</serv_40010>
391
  <serv_40096>Sedex,3</serv_40096>
 
392
  <serv_81019>E-Sedex,3</serv_81019>
393
  <serv_41106>PAC,3</serv_41106>
394
  <serv_41068>PAC,3</serv_41068>
@@ -400,9 +413,40 @@
400
  <serv_10138>Carta Comercial Registrada,3</serv_10138>
401
  <coeficiente_volume>6000</coeficiente_volume>
402
  <acobrar_code>40045</acobrar_code>
403
- <contrato_codes>40096,81019,41068,41300</contrato_codes>
404
  <url_ws_correios>http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx</url_ws_correios>
405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  <!-- CACHE -->
407
  <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>
408
  <cache_timeout>31536000</cache_timeout>
@@ -414,337 +458,351 @@
414
  <cache_mode>0</cache_mode>
415
 
416
  <!-- ADDITIONAL POST METHODS -->
417
- <add_method_0>
418
- <code>10065</code>
419
- <price>1.40</price>
420
- <days>5</days>
421
- <from>
422
- <zip>00000000</zip>
423
- <weight>0</weight>
424
- <size>0</size>
425
- </from>
426
- <to>
427
- <zip>99999999</zip>
428
- <weight>0.020</weight>
429
- <size>30</size>
430
- </to>
431
- </add_method_0>
432
- <add_method_1>
433
- <code>10065</code>
434
- <price>1.95</price>
435
- <days>5</days>
436
- <from>
437
- <zip>00000000</zip>
438
- <weight>0.020</weight>
439
- <size>0</size>
440
- </from>
441
- <to>
442
- <zip>99999999</zip>
443
- <weight>0.050</weight>
444
- <size>30</size>
445
- </to>
446
- </add_method_1>
447
- <add_method_2>
448
- <code>10065</code>
449
- <price>2.70</price>
450
- <days>5</days>
451
- <from>
452
- <zip>00000000</zip>
453
- <weight>0.050</weight>
454
- <size>0</size>
455
- </from>
456
- <to>
457
- <zip>99999999</zip>
458
- <weight>0.100</weight>
459
- <size>30</size>
460
- </to>
461
- </add_method_2>
462
- <add_method_3>
463
- <code>10065</code>
464
- <price>3.30</price>
465
- <days>5</days>
466
- <from>
467
- <zip>00000000</zip>
468
- <weight>0.100</weight>
469
- <size>0</size>
470
- </from>
471
- <to>
472
- <zip>99999999</zip>
473
- <weight>0.150</weight>
474
- <size>30</size>
475
- </to>
476
- </add_method_3>
477
- <add_method_4>
478
- <code>10065</code>
479
- <price>3.90</price>
480
- <days>5</days>
481
- <from>
482
- <zip>00000000</zip>
483
- <weight>0.150</weight>
484
- <size>0</size>
485
- </from>
486
- <to>
487
- <zip>99999999</zip>
488
- <weight>0.200</weight>
489
- <size>30</size>
490
- </to>
491
- </add_method_4>
492
- <add_method_5>
493
- <code>10065</code>
494
- <price>4.50</price>
495
- <days>5</days>
496
- <from>
497
- <zip>00000000</zip>
498
- <weight>0.200</weight>
499
- <size>0</size>
500
- </from>
501
- <to>
502
- <zip>99999999</zip>
503
- <weight>0.250</weight>
504
- <size>30</size>
505
- </to>
506
- </add_method_5>
507
- <add_method_6>
508
- <code>10065</code>
509
- <price>5.15</price>
510
- <days>5</days>
511
- <from>
512
- <zip>00000000</zip>
513
- <weight>0.250</weight>
514
- <size>0</size>
515
- </from>
516
- <to>
517
- <zip>99999999</zip>
518
- <weight>0.300</weight>
519
- <size>30</size>
520
- </to>
521
- </add_method_6>
522
- <add_method_7>
523
- <code>10065</code>
524
- <price>5.75</price>
525
- <days>5</days>
526
- <from>
527
- <zip>00000000</zip>
528
- <weight>0.300</weight>
529
- <size>0</size>
530
- </from>
531
- <to>
532
- <zip>99999999</zip>
533
- <weight>0.350</weight>
534
- <size>30</size>
535
- </to>
536
- </add_method_7>
537
- <add_method_8>
538
- <code>10065</code>
539
- <price>6.35</price>
540
- <days>5</days>
541
- <from>
542
- <zip>00000000</zip>
543
- <weight>0.350</weight>
544
- <size>0</size>
545
- </from>
546
- <to>
547
- <zip>99999999</zip>
548
- <weight>0.400</weight>
549
- <size>30</size>
550
- </to>
551
- </add_method_8>
552
- <add_method_9>
553
- <code>10065</code>
554
- <price>6.95</price>
555
- <days>5</days>
556
- <from>
557
- <zip>00000000</zip>
558
- <weight>0.400</weight>
559
- <size>0</size>
560
- </from>
561
- <to>
562
- <zip>99999999</zip>
563
- <weight>0.450</weight>
564
- <size>30</size>
565
- </to>
566
- </add_method_9>
567
- <add_method_10>
568
- <code>10065</code>
569
- <price>7.55</price>
570
- <days>5</days>
571
- <from>
572
- <zip>00000000</zip>
573
- <weight>0.450</weight>
574
- <size>0</size>
575
- </from>
576
- <to>
577
- <zip>99999999</zip>
578
- <weight>0.500</weight>
579
- <size>30</size>
580
- </to>
581
- </add_method_10>
582
- <add_method_11>
583
- <code>10138</code>
584
- <price>5.00</price>
585
- <days>5</days>
586
- <from>
587
- <zip>00000000</zip>
588
- <weight>0</weight>
589
- <size>0</size>
590
- </from>
591
- <to>
592
- <zip>99999999</zip>
593
- <weight>0.020</weight>
594
- <size>30</size>
595
- </to>
596
- </add_method_11>
597
- <add_method_12>
598
- <code>10138</code>
599
- <price>5.55</price>
600
- <days>5</days>
601
- <from>
602
- <zip>00000000</zip>
603
- <weight>0.020</weight>
604
- <size>0</size>
605
- </from>
606
- <to>
607
- <zip>99999999</zip>
608
- <weight>0.050</weight>
609
- <size>30</size>
610
- </to>
611
- </add_method_12>
612
- <add_method_13>
613
- <code>10138</code>
614
- <price>6.30</price>
615
- <days>5</days>
616
- <from>
617
- <zip>00000000</zip>
618
- <weight>0.050</weight>
619
- <size>0</size>
620
- </from>
621
- <to>
622
- <zip>99999999</zip>
623
- <weight>0.100</weight>
624
- <size>30</size>
625
- </to>
626
- </add_method_13>
627
- <add_method_14>
628
- <code>10138</code>
629
- <price>6.90</price>
630
- <days>5</days>
631
- <from>
632
- <zip>00000000</zip>
633
- <weight>0.100</weight>
634
- <size>0</size>
635
- </from>
636
- <to>
637
- <zip>99999999</zip>
638
- <weight>0.150</weight>
639
- <size>30</size>
640
- </to>
641
- </add_method_14>
642
- <add_method_15>
643
- <code>10138</code>
644
- <price>7.50</price>
645
- <days>5</days>
646
- <from>
647
- <zip>00000000</zip>
648
- <weight>0.150</weight>
649
- <size>0</size>
650
- </from>
651
- <to>
652
- <zip>99999999</zip>
653
- <weight>0.200</weight>
654
- <size>30</size>
655
- </to>
656
- </add_method_15>
657
- <add_method_16>
658
- <code>10138</code>
659
- <price>8.10</price>
660
- <days>5</days>
661
- <from>
662
- <zip>00000000</zip>
663
- <weight>0.200</weight>
664
- <size>0</size>
665
- </from>
666
- <to>
667
- <zip>99999999</zip>
668
- <weight>0.250</weight>
669
- <size>30</size>
670
- </to>
671
- </add_method_16>
672
- <add_method_17>
673
- <code>10138</code>
674
- <price>8.75</price>
675
- <days>5</days>
676
- <from>
677
- <zip>00000000</zip>
678
- <weight>0.250</weight>
679
- <size>0</size>
680
- </from>
681
- <to>
682
- <zip>99999999</zip>
683
- <weight>0.300</weight>
684
- <size>30</size>
685
- </to>
686
- </add_method_17>
687
- <add_method_18>
688
- <code>10138</code>
689
- <price>9.35</price>
690
- <days>5</days>
691
- <from>
692
- <zip>00000000</zip>
693
- <weight>0.300</weight>
694
- <size>0</size>
695
- </from>
696
- <to>
697
- <zip>99999999</zip>
698
- <weight>0.350</weight>
699
- <size>30</size>
700
- </to>
701
- </add_method_18>
702
- <add_method_19>
703
- <code>10138</code>
704
- <price>9.95</price>
705
- <days>5</days>
706
- <from>
707
- <zip>00000000</zip>
708
- <weight>0.350</weight>
709
- <size>0</size>
710
- </from>
711
- <to>
712
- <zip>99999999</zip>
713
- <weight>0.400</weight>
714
- <size>30</size>
715
- </to>
716
- </add_method_19>
717
- <add_method_20>
718
- <code>10138</code>
719
- <price>10.55</price>
720
- <days>5</days>
721
- <from>
722
- <zip>00000000</zip>
723
- <weight>0.400</weight>
724
- <size>0</size>
725
- </from>
726
- <to>
727
- <zip>99999999</zip>
728
- <weight>0.450</weight>
729
- <size>30</size>
730
- </to>
731
- </add_method_20>
732
- <add_method_21>
733
- <code>10138</code>
734
- <price>11.15</price>
735
- <days>5</days>
736
- <from>
737
- <zip>00000000</zip>
738
- <weight>0.450</weight>
739
- <size>0</size>
740
- </from>
741
- <to>
742
- <zip>99999999</zip>
743
- <weight>0.500</weight>
744
- <size>30</size>
745
- </to>
746
- </add_method_21>
 
 
747
  </pedroteixeira_correios>
748
  </carriers>
749
  </default>
 
 
 
 
 
 
 
 
 
 
 
 
750
  </config>
15
  <config>
16
  <modules>
17
  <PedroTeixeira_Correios>
18
+ <version>4.7.0</version>
19
  <depends>
20
  <Mage_Shipping/>
21
  </depends>
84
  <model>PedroTeixeira_Correios_Model_Carrier_CorreiosMethod</model>
85
  <title>Correios</title>
86
  <postmethods>40010</postmethods>
87
+ <hard_errors>-3,-6,-10,-33,-888,7,99</hard_errors>
88
  <soft_errors>009,010,011</soft_errors>
89
  <show_soft_errors>0</show_soft_errors>
90
  <prazo_entrega>0</prazo_entrega>
128
  <brasil>00000000,99999999</brasil>
129
  </zips>
130
  </serv_40096>
131
+ <serv_40436>
132
+ <max>
133
+ <size>105</size>
134
+ <sum>200</sum>
135
+ <weight>30</weight>
136
+ <volume_weight>50</volume_weight>
137
+ </max>
138
+ <zips>
139
+ <brasil>00000000,99999999</brasil>
140
+ </zips>
141
+ </serv_40436>
142
  <serv_81019>
143
  <max>
144
  <size>105</size>
401
  <!-- SYSTEM -->
402
  <serv_40010>Sedex,3</serv_40010>
403
  <serv_40096>Sedex,3</serv_40096>
404
+ <serv_40436>Sedex,3</serv_40436>
405
  <serv_81019>E-Sedex,3</serv_81019>
406
  <serv_41106>PAC,3</serv_41106>
407
  <serv_41068>PAC,3</serv_41068>
413
  <serv_10138>Carta Comercial Registrada,3</serv_10138>
414
  <coeficiente_volume>6000</coeficiente_volume>
415
  <acobrar_code>40045</acobrar_code>
416
+ <contrato_codes>40096,81019,41068,41300,40436</contrato_codes>
417
  <url_ws_correios>http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx</url_ws_correios>
418
 
419
+ <!-- SRO XML -->
420
+ <sro_username>ECT</sro_username>
421
+ <sro_password>SRO</sro_password>
422
+ <sro_type>L</sro_type>
423
+ <sro_result>U</sro_result>
424
+
425
+ <sro_event_type_notify>BDE,BDI,BDR,FC,LDI,OEC</sro_event_type_notify>
426
+ <sro_event_status_notify_bde>0,1,2,7,20,24,25,34,45,54,55</sro_event_status_notify_bde>
427
+ <sro_event_status_notify_bdi>0,1,2,7,20,24,25,34,45,54,55</sro_event_status_notify_bdi>
428
+ <sro_event_status_notify_bdr>0,1,2,7,20,24,25,34,45,54,55</sro_event_status_notify_bdr>
429
+ <sro_event_status_notify_fc>4,7</sro_event_status_notify_fc>
430
+ <sro_event_status_notify_ldi>0,1,2,3,14</sro_event_status_notify_ldi>
431
+ <sro_event_status_notify_oec>0,1</sro_event_status_notify_oec>
432
+
433
+ <sro_event_type_warn>BDE,BDI,BDR,FC,LDI,OEC</sro_event_type_warn>
434
+ <sro_event_status_warn_bde>3,4,5,6,7,8,9,10,12,19,21,22,23,26,28,33,34,35,36,37,38,40,41,42,43,48,49,50,51,52,54,55,56,57,58,59,69</sro_event_status_warn_bde>
435
+ <sro_event_status_warn_bdi>3,4,5,6,7,8,9,10,12,19,21,22,23,26,28,33,34,35,36,37,38,40,41,42,43,48,49,50,51,52,54,55,56,57,58,59,69</sro_event_status_warn_bdi>
436
+ <sro_event_status_warn_bdr>3,4,5,6,7,8,9,10,12,19,21,22,23,26,28,33,34,35,36,37,38,40,41,42,43,48,49,50,51,52,54,55,56,57,58,59,69</sro_event_status_warn_bdr>
437
+ <sro_event_status_warn_blq>1</sro_event_status_warn_blq>
438
+ <sro_event_status_warn_ldi>0,1,3,14</sro_event_status_warn_ldi>
439
+ <sro_event_status_warn_fc>1,4,5</sro_event_status_warn_fc>
440
+ <sro_event_status_warn_idc>1,2,3,4,5,6,7</sro_event_status_warn_idc>
441
+
442
+ <sro_event_type_last>BDE,BDI,BDR</sro_event_type_last>
443
+ <sro_event_status_last_bde>0,1</sro_event_status_last_bde>
444
+ <sro_event_status_last_bdi>0,1</sro_event_status_last_bdi>
445
+ <sro_event_status_last_bdr>0,1</sro_event_status_last_bdr>
446
+
447
+ <url_sro_correios>http://websro.correios.com.br/sro_bin/sroii_xml.eventos</url_sro_correios>
448
+ <url_tracking>http://websro.correios.com.br/sro_bin/txect01$.QueryList</url_tracking>
449
+
450
  <!-- CACHE -->
451
  <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>
452
  <cache_timeout>31536000</cache_timeout>
458
  <cache_mode>0</cache_mode>
459
 
460
  <!-- ADDITIONAL POST METHODS -->
461
+ <add_postmethods>
462
+ <add_method_0>
463
+ <code>10065</code>
464
+ <price>1.40</price>
465
+ <days>5</days>
466
+ <from>
467
+ <zip>00000000</zip>
468
+ <weight>0</weight>
469
+ <size>0</size>
470
+ </from>
471
+ <to>
472
+ <zip>99999999</zip>
473
+ <weight>0.020</weight>
474
+ <size>30</size>
475
+ </to>
476
+ </add_method_0>
477
+ <add_method_1>
478
+ <code>10065</code>
479
+ <price>1.95</price>
480
+ <days>5</days>
481
+ <from>
482
+ <zip>00000000</zip>
483
+ <weight>0.020</weight>
484
+ <size>0</size>
485
+ </from>
486
+ <to>
487
+ <zip>99999999</zip>
488
+ <weight>0.050</weight>
489
+ <size>30</size>
490
+ </to>
491
+ </add_method_1>
492
+ <add_method_2>
493
+ <code>10065</code>
494
+ <price>2.70</price>
495
+ <days>5</days>
496
+ <from>
497
+ <zip>00000000</zip>
498
+ <weight>0.050</weight>
499
+ <size>0</size>
500
+ </from>
501
+ <to>
502
+ <zip>99999999</zip>
503
+ <weight>0.100</weight>
504
+ <size>30</size>
505
+ </to>
506
+ </add_method_2>
507
+ <add_method_3>
508
+ <code>10065</code>
509
+ <price>3.30</price>
510
+ <days>5</days>
511
+ <from>
512
+ <zip>00000000</zip>
513
+ <weight>0.100</weight>
514
+ <size>0</size>
515
+ </from>
516
+ <to>
517
+ <zip>99999999</zip>
518
+ <weight>0.150</weight>
519
+ <size>30</size>
520
+ </to>
521
+ </add_method_3>
522
+ <add_method_4>
523
+ <code>10065</code>
524
+ <price>3.90</price>
525
+ <days>5</days>
526
+ <from>
527
+ <zip>00000000</zip>
528
+ <weight>0.150</weight>
529
+ <size>0</size>
530
+ </from>
531
+ <to>
532
+ <zip>99999999</zip>
533
+ <weight>0.200</weight>
534
+ <size>30</size>
535
+ </to>
536
+ </add_method_4>
537
+ <add_method_5>
538
+ <code>10065</code>
539
+ <price>4.50</price>
540
+ <days>5</days>
541
+ <from>
542
+ <zip>00000000</zip>
543
+ <weight>0.200</weight>
544
+ <size>0</size>
545
+ </from>
546
+ <to>
547
+ <zip>99999999</zip>
548
+ <weight>0.250</weight>
549
+ <size>30</size>
550
+ </to>
551
+ </add_method_5>
552
+ <add_method_6>
553
+ <code>10065</code>
554
+ <price>5.15</price>
555
+ <days>5</days>
556
+ <from>
557
+ <zip>00000000</zip>
558
+ <weight>0.250</weight>
559
+ <size>0</size>
560
+ </from>
561
+ <to>
562
+ <zip>99999999</zip>
563
+ <weight>0.300</weight>
564
+ <size>30</size>
565
+ </to>
566
+ </add_method_6>
567
+ <add_method_7>
568
+ <code>10065</code>
569
+ <price>5.75</price>
570
+ <days>5</days>
571
+ <from>
572
+ <zip>00000000</zip>
573
+ <weight>0.300</weight>
574
+ <size>0</size>
575
+ </from>
576
+ <to>
577
+ <zip>99999999</zip>
578
+ <weight>0.350</weight>
579
+ <size>30</size>
580
+ </to>
581
+ </add_method_7>
582
+ <add_method_8>
583
+ <code>10065</code>
584
+ <price>6.35</price>
585
+ <days>5</days>
586
+ <from>
587
+ <zip>00000000</zip>
588
+ <weight>0.350</weight>
589
+ <size>0</size>
590
+ </from>
591
+ <to>
592
+ <zip>99999999</zip>
593
+ <weight>0.400</weight>
594
+ <size>30</size>
595
+ </to>
596
+ </add_method_8>
597
+ <add_method_9>
598
+ <code>10065</code>
599
+ <price>6.95</price>
600
+ <days>5</days>
601
+ <from>
602
+ <zip>00000000</zip>
603
+ <weight>0.400</weight>
604
+ <size>0</size>
605
+ </from>
606
+ <to>
607
+ <zip>99999999</zip>
608
+ <weight>0.450</weight>
609
+ <size>30</size>
610
+ </to>
611
+ </add_method_9>
612
+ <add_method_10>
613
+ <code>10065</code>
614
+ <price>7.55</price>
615
+ <days>5</days>
616
+ <from>
617
+ <zip>00000000</zip>
618
+ <weight>0.450</weight>
619
+ <size>0</size>
620
+ </from>
621
+ <to>
622
+ <zip>99999999</zip>
623
+ <weight>0.500</weight>
624
+ <size>30</size>
625
+ </to>
626
+ </add_method_10>
627
+ <add_method_11>
628
+ <code>10138</code>
629
+ <price>5.00</price>
630
+ <days>5</days>
631
+ <from>
632
+ <zip>00000000</zip>
633
+ <weight>0</weight>
634
+ <size>0</size>
635
+ </from>
636
+ <to>
637
+ <zip>99999999</zip>
638
+ <weight>0.020</weight>
639
+ <size>30</size>
640
+ </to>
641
+ </add_method_11>
642
+ <add_method_12>
643
+ <code>10138</code>
644
+ <price>5.55</price>
645
+ <days>5</days>
646
+ <from>
647
+ <zip>00000000</zip>
648
+ <weight>0.020</weight>
649
+ <size>0</size>
650
+ </from>
651
+ <to>
652
+ <zip>99999999</zip>
653
+ <weight>0.050</weight>
654
+ <size>30</size>
655
+ </to>
656
+ </add_method_12>
657
+ <add_method_13>
658
+ <code>10138</code>
659
+ <price>6.30</price>
660
+ <days>5</days>
661
+ <from>
662
+ <zip>00000000</zip>
663
+ <weight>0.050</weight>
664
+ <size>0</size>
665
+ </from>
666
+ <to>
667
+ <zip>99999999</zip>
668
+ <weight>0.100</weight>
669
+ <size>30</size>
670
+ </to>
671
+ </add_method_13>
672
+ <add_method_14>
673
+ <code>10138</code>
674
+ <price>6.90</price>
675
+ <days>5</days>
676
+ <from>
677
+ <zip>00000000</zip>
678
+ <weight>0.100</weight>
679
+ <size>0</size>
680
+ </from>
681
+ <to>
682
+ <zip>99999999</zip>
683
+ <weight>0.150</weight>
684
+ <size>30</size>
685
+ </to>
686
+ </add_method_14>
687
+ <add_method_15>
688
+ <code>10138</code>
689
+ <price>7.50</price>
690
+ <days>5</days>
691
+ <from>
692
+ <zip>00000000</zip>
693
+ <weight>0.150</weight>
694
+ <size>0</size>
695
+ </from>
696
+ <to>
697
+ <zip>99999999</zip>
698
+ <weight>0.200</weight>
699
+ <size>30</size>
700
+ </to>
701
+ </add_method_15>
702
+ <add_method_16>
703
+ <code>10138</code>
704
+ <price>8.10</price>
705
+ <days>5</days>
706
+ <from>
707
+ <zip>00000000</zip>
708
+ <weight>0.200</weight>
709
+ <size>0</size>
710
+ </from>
711
+ <to>
712
+ <zip>99999999</zip>
713
+ <weight>0.250</weight>
714
+ <size>30</size>
715
+ </to>
716
+ </add_method_16>
717
+ <add_method_17>
718
+ <code>10138</code>
719
+ <price>8.75</price>
720
+ <days>5</days>
721
+ <from>
722
+ <zip>00000000</zip>
723
+ <weight>0.250</weight>
724
+ <size>0</size>
725
+ </from>
726
+ <to>
727
+ <zip>99999999</zip>
728
+ <weight>0.300</weight>
729
+ <size>30</size>
730
+ </to>
731
+ </add_method_17>
732
+ <add_method_18>
733
+ <code>10138</code>
734
+ <price>9.35</price>
735
+ <days>5</days>
736
+ <from>
737
+ <zip>00000000</zip>
738
+ <weight>0.300</weight>
739
+ <size>0</size>
740
+ </from>
741
+ <to>
742
+ <zip>99999999</zip>
743
+ <weight>0.350</weight>
744
+ <size>30</size>
745
+ </to>
746
+ </add_method_18>
747
+ <add_method_19>
748
+ <code>10138</code>
749
+ <price>9.95</price>
750
+ <days>5</days>
751
+ <from>
752
+ <zip>00000000</zip>
753
+ <weight>0.350</weight>
754
+ <size>0</size>
755
+ </from>
756
+ <to>
757
+ <zip>99999999</zip>
758
+ <weight>0.400</weight>
759
+ <size>30</size>
760
+ </to>
761
+ </add_method_19>
762
+ <add_method_20>
763
+ <code>10138</code>
764
+ <price>10.55</price>
765
+ <days>5</days>
766
+ <from>
767
+ <zip>00000000</zip>
768
+ <weight>0.400</weight>
769
+ <size>0</size>
770
+ </from>
771
+ <to>
772
+ <zip>99999999</zip>
773
+ <weight>0.450</weight>
774
+ <size>30</size>
775
+ </to>
776
+ </add_method_20>
777
+ <add_method_21>
778
+ <code>10138</code>
779
+ <price>11.15</price>
780
+ <days>5</days>
781
+ <from>
782
+ <zip>00000000</zip>
783
+ <weight>0.450</weight>
784
+ <size>0</size>
785
+ </from>
786
+ <to>
787
+ <zip>99999999</zip>
788
+ <weight>0.500</weight>
789
+ <size>30</size>
790
+ </to>
791
+ </add_method_21>
792
+ </add_postmethods>
793
  </pedroteixeira_correios>
794
  </carriers>
795
  </default>
796
+ <crontab>
797
+ <jobs>
798
+ <correios_status_check>
799
+ <schedule>
800
+ <cron_expr>*/15 * * * *</cron_expr>
801
+ </schedule>
802
+ <run>
803
+ <model>pedroteixeira_correios/observer::sroTrackingJob</model>
804
+ </run>
805
+ </correios_status_check>
806
+ </jobs>
807
+ </crontab>
808
  </config>
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.6.0.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $status = Mage::getModel('sales/order_status');
20
+ $status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_SHIPPED_STATUS)
21
+ ->setLabel('Pedido em Transporte')
22
+ ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE)
23
+ ->save();
24
+
25
+ $status = Mage::getModel('sales/order_status');
26
+ $status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_WARNED_STATUS)
27
+ ->setLabel('Dificuldade de Entrega')
28
+ ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE)
29
+ ->save();
30
+
31
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
32
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
33
+
34
+ // Add volume to prduct attribute set
35
+ $codigo = 'volume_comprimento';
36
+ $config = array(
37
+ 'position' => 1,
38
+ 'required' => 0,
39
+ 'label' => 'Comprimento (cm)',
40
+ 'type' => 'int',
41
+ 'input' => 'text',
42
+ 'apply_to' => 'simple,bundle,grouped,configurable',
43
+ 'note' => 'Comprimento da embalagem do produto (Para cálculo dos Correios)'
44
+ );
45
+
46
+ $setup->addAttribute('catalog_product', $codigo, $config);
47
+
48
+ // Add volume to prduct attribute set
49
+ $codigo = 'volume_altura';
50
+ $config = array(
51
+ 'position' => 1,
52
+ 'required' => 0,
53
+ 'label' => 'Altura (cm)',
54
+ 'type' => 'int',
55
+ 'input' => 'text',
56
+ 'apply_to' => 'simple,bundle,grouped,configurable',
57
+ 'note' => 'Altura da embalagem do produto (Para cálculo dos Correios)'
58
+ );
59
+
60
+ $setup->addAttribute('catalog_product', $codigo, $config);
61
+
62
+ // Add volume to prduct attribute set
63
+ $codigo = 'volume_largura';
64
+ $config = array(
65
+ 'position' => 1,
66
+ 'required' => 0,
67
+ 'label' => 'Largura (cm)',
68
+ 'type' => 'int',
69
+ 'input' => 'text',
70
+ 'apply_to' => 'simple,bundle,grouped,configurable',
71
+ 'note' => 'Largura da embalagem do produto (Para cálculo dos Correios)'
72
+ );
73
+
74
+ $setup->addAttribute('catalog_product', $codigo, $config);
75
+
76
+ $codigo = 'postmethods';
77
+ $config = array(
78
+ 'position' => 1,
79
+ 'required' => 0,
80
+ 'label' => 'Serviços de Entrega',
81
+ 'type' => 'text',
82
+ 'input' => 'multiselect',
83
+ 'source' => 'pedroteixeira_correios/source_postMethods',
84
+ 'backend' => 'eav/entity_attribute_backend_array',
85
+ 'apply_to' => 'simple,bundle,grouped,configurable',
86
+ 'note' => 'Selecione os serviços apropriados para o produto.'
87
+ );
88
+
89
+ $setup->addAttribute('catalog_product', $codigo, $config);
90
+
91
+ $codigo = 'fit_size';
92
+ $config = array(
93
+ 'position' => 1,
94
+ 'required' => 0,
95
+ 'label' => 'Diferença do Encaixe (cm)',
96
+ 'type' => 'varchar',
97
+ 'input' => 'text',
98
+ 'apply_to' => 'simple,bundle,grouped,configurable',
99
+ 'note' => 'Exemplo: Se 1 item mede 10cm de altura, e 2 itens encaixados medem 11cm. A diferença é de 1cm.'
100
+ );
101
+
102
+ $setup->addAttribute('catalog_product', $codigo, $config);
103
+
104
+ $codigo = 'posting_days';
105
+ $config = array(
106
+ 'position' => 1,
107
+ 'required' => 0,
108
+ 'label' => 'Prazo de Postagem',
109
+ 'type' => 'int',
110
+ 'input' => 'text',
111
+ 'apply_to' => 'simple,bundle,grouped,configurable',
112
+ 'note' => 'O prazo total é o Prazo dos Correios acrescido do maior Prazo de Postagem dos produtos no carrinho.'
113
+ );
114
+
115
+ $setup->addAttribute('catalog_product', $codigo, $config);
116
+
117
+ $installer->endSetup();
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.7.0.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $status = Mage::getModel('sales/order_status');
20
+ $status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_SHIPPED_STATUS)
21
+ ->setLabel('Pedido em Transporte')
22
+ ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE)
23
+ ->save();
24
+
25
+ $status = Mage::getModel('sales/order_status');
26
+ $status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_WARNED_STATUS)
27
+ ->setLabel('Dificuldade de Entrega')
28
+ ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE)
29
+ ->save();
30
+
31
+ /* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
32
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
33
+
34
+ // Add volume to prduct attribute set
35
+ $codigo = 'volume_comprimento';
36
+ $config = array(
37
+ 'position' => 1,
38
+ 'required' => 0,
39
+ 'label' => 'Comprimento (cm)',
40
+ 'type' => 'int',
41
+ 'input' => 'text',
42
+ 'apply_to' => 'simple,bundle,grouped,configurable',
43
+ 'note' => 'Comprimento da embalagem do produto (Para cálculo dos Correios)'
44
+ );
45
+
46
+ $setup->addAttribute('catalog_product', $codigo, $config);
47
+
48
+ // Add volume to prduct attribute set
49
+ $codigo = 'volume_altura';
50
+ $config = array(
51
+ 'position' => 1,
52
+ 'required' => 0,
53
+ 'label' => 'Altura (cm)',
54
+ 'type' => 'int',
55
+ 'input' => 'text',
56
+ 'apply_to' => 'simple,bundle,grouped,configurable',
57
+ 'note' => 'Altura da embalagem do produto (Para cálculo dos Correios)'
58
+ );
59
+
60
+ $setup->addAttribute('catalog_product', $codigo, $config);
61
+
62
+ // Add volume to prduct attribute set
63
+ $codigo = 'volume_largura';
64
+ $config = array(
65
+ 'position' => 1,
66
+ 'required' => 0,
67
+ 'label' => 'Largura (cm)',
68
+ 'type' => 'int',
69
+ 'input' => 'text',
70
+ 'apply_to' => 'simple,bundle,grouped,configurable',
71
+ 'note' => 'Largura da embalagem do produto (Para cálculo dos Correios)'
72
+ );
73
+
74
+ $setup->addAttribute('catalog_product', $codigo, $config);
75
+
76
+ $codigo = 'postmethods';
77
+ $config = array(
78
+ 'position' => 1,
79
+ 'required' => 0,
80
+ 'label' => 'Serviços de Entrega',
81
+ 'type' => 'text',
82
+ 'input' => 'multiselect',
83
+ 'source' => 'pedroteixeira_correios/source_postMethods',
84
+ 'backend' => 'eav/entity_attribute_backend_array',
85
+ 'apply_to' => 'simple,bundle,grouped,configurable',
86
+ 'note' => 'Selecione os serviços apropriados para o produto.'
87
+ );
88
+
89
+ $setup->addAttribute('catalog_product', $codigo, $config);
90
+
91
+ $codigo = 'fit_size';
92
+ $config = array(
93
+ 'position' => 1,
94
+ 'required' => 0,
95
+ 'label' => 'Diferença do Encaixe (cm)',
96
+ 'type' => 'varchar',
97
+ 'input' => 'text',
98
+ 'apply_to' => 'simple,bundle,grouped,configurable',
99
+ 'note' => 'Exemplo: Se 1 item mede 10cm de altura, e 2 itens encaixados medem 11cm. A diferença é de 1cm.'
100
+ );
101
+
102
+ $setup->addAttribute('catalog_product', $codigo, $config);
103
+
104
+ $codigo = 'posting_days';
105
+ $config = array(
106
+ 'position' => 1,
107
+ 'required' => 0,
108
+ 'label' => 'Prazo de Postagem',
109
+ 'type' => 'int',
110
+ 'input' => 'text',
111
+ 'apply_to' => 'simple,bundle,grouped,configurable',
112
+ 'note' => 'O prazo total é o Prazo dos Correios acrescido do maior Prazo de Postagem dos produtos no carrinho.'
113
+ );
114
+
115
+ $setup->addAttribute('catalog_product', $codigo, $config);
116
+
117
+ // Add Correios Tab
118
+ $setIds = $setup->getAllAttributeSetIds('catalog_product');
119
+
120
+ $attributes = array(
121
+ 'volume_comprimento',
122
+ 'volume_altura',
123
+ 'volume_largura',
124
+ 'postmethods',
125
+ 'fit_size',
126
+ 'posting_days'
127
+ );
128
+
129
+ foreach ( $setIds as $setId ) {
130
+
131
+ $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2);
132
+ $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios');
133
+
134
+ foreach ( $attributes as $attribute ) {
135
+ $attributeId = $setup->getAttributeId('catalog_product', $attribute);
136
+ $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId);
137
+ }
138
+
139
+ }
140
+
141
+ $installer->endSetup();
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.5.0-4.6.0.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $status = Mage::getModel('sales/order_status');
20
+ $status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_SHIPPED_STATUS)
21
+ ->setLabel('Pedido em Transporte')
22
+ ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE)
23
+ ->save();
24
+
25
+ $status = Mage::getModel('sales/order_status');
26
+ $status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_WARNED_STATUS)
27
+ ->setLabel('Dificuldade de Entrega')
28
+ ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE)
29
+ ->save();
30
+
31
+ $installer->endSetup();
app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.6.0-4.7.0.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
20
+ $setIds = $setup->getAllAttributeSetIds('catalog_product');
21
+
22
+ $attributes = array(
23
+ 'volume_comprimento',
24
+ 'volume_altura',
25
+ 'volume_largura',
26
+ 'postmethods',
27
+ 'fit_size',
28
+ 'posting_days'
29
+ );
30
+
31
+ foreach ( $setIds as $setId ) {
32
+
33
+ $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2);
34
+ $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios');
35
+
36
+ foreach ( $attributes as $attribute ) {
37
+ $attributeId = $setup->getAttributeId('catalog_product', $attribute);
38
+ $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId);
39
+ }
40
+
41
+ }
42
+
43
+ $installer->endSetup();
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>PedroTeixeira_Correios</name>
4
- <version>4.5.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/mit-license.php">MIT License</license>
7
  <channel>community</channel>
@@ -28,22 +28,26 @@ Conta com identifica&#xE7;&#xE3;o de erros dos Correios, m&#xE3;o pr&#xF3;pria,
28
  Mais informa&#xE7;&#xF5;es em https://pedroteixeira.io.</description>
29
  <notes>Bugfix:&#xD;
30
  &#xD;
31
- - Corre&#xE7;&#xE3;o de prazo para mapeamentos recentes dos Correios&#xD;
32
- - Corrige exce&#xE7;&#xE3;o no caso de falha na comunica&#xE7;&#xE3;o com os Correios&#xD;
 
 
 
 
 
33
  &#xD;
34
  Feature:&#xD;
35
  &#xD;
36
- - Adiciona suporte a Perfil Recorrente (Recurring Profile)&#xD;
37
- - Licen&#xE7;a utilizada vis&#xED;vel na documenta&#xE7;&#xE3;o&#xD;
38
- - Atualiza&#xE7;&#xE3;o dos pre&#xE7;os da carta comercial e carta comercial registrada&#xD;
39
- - Adiciona mensagem especial para CEPs com &#xE1;rea de risco&#xD;
40
- - Adiciona explica&#xE7;&#xE3;o de novos campos no README&#xD;
41
- - Adiciona informa&#xE7;&#xE3;o sobre compila&#xE7;&#xE3;o no README&#xD;
42
- - Possibilidade de acrescentar dias nos prazos dos Correios por produto</notes>
43
  <authors><author><name>Pedro Teixeira</name><user>teixeirapedro</user><email>hello@pedroteixeira.io</email></author></authors>
44
- <date>2015-07-13</date>
45
- <time>09:08:57</time>
46
- <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="63903ef57e86e2be3cd79787063f3946"/><dir name="Carrier"><file name="CorreiosMethod.php" hash="aedcce35a9b2a2b633ae2828681072a3"/></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="03105f699463cf7df28eafb89a9bddf4"/><file name="system.xml" hash="a176657e9f5565ef20d101059cca833c"/></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="install-4.5.0.php" hash="e0daaac3649b166a33928da3844ad965"/><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"/><file name="upgrade-4.4.0-4.5.0.php" hash="95dfd40fa6469a711b4b65a331f0b1b7"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PedroTeixeira_Correios.xml" hash="e714579bed97c85f2bcc3988dec271da"/></dir></target></contents>
47
  <compatible/>
48
  <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>
49
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>PedroTeixeira_Correios</name>
4
+ <version>4.7.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/mit-license.php">MIT License</license>
7
  <channel>community</channel>
28
  Mais informa&#xE7;&#xF5;es em https://pedroteixeira.io.</description>
29
  <notes>Bugfix:&#xD;
30
  &#xD;
31
+ - Fix para frete com desconto/gr&#xE1;tis em &#xE1;reas com restri&#xE7;&#xE3;o de entrega&#xD;
32
+ - Configura&#xE7;&#xE3;o de ajuste&#xD;
33
+ - Added Validation to null postcode in cart update&#xD;
34
+ - Removida a fun&#xE7;&#xE3;o trim em contexto de vari&#xE1;vel&#xD;
35
+ - Corre&#xE7;&#xE3;o para Warning: Invalid argument supplied for foreach&#xD;
36
+ - Fix noservices error&#xD;
37
+ - Corre&#xE7;&#xE3;o para refer&#xEA;ncia de items para c&#xE1;lculo do request&#xD;
38
  &#xD;
39
  Feature:&#xD;
40
  &#xD;
41
+ - Adicionada compatibilidade com pacote de produtos&#xD;
42
+ - Monitoramento Autom&#xE1;tico da Encomenda, e Atualiza&#xE7;&#xE3;o do Status da Entrega&#xD;
43
+ - Adicionado servi&#xE7;o 40436 com contrato&#xD;
44
+ - Instalando com Modgit&#xD;
45
+ - Evitando load de produto&#xD;
46
+ - Aba dos Correios na edi&#xE7;&#xE3;o de produtos</notes>
 
47
  <authors><author><name>Pedro Teixeira</name><user>teixeirapedro</user><email>hello@pedroteixeira.io</email></author></authors>
48
+ <date>2016-05-24</date>
49
+ <time>10:14:12</time>
50
+ <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="63903ef57e86e2be3cd79787063f3946"/><dir name="Carrier"><file name="CorreiosMethod.php" hash="7886063ac2184904947304d25af66454"/></dir><dir name="Http"><dir name="Client"><dir name="Adapter"><file name="Socket.php" hash="76da85f117c3f9950164a5d90500d82f"/></dir></dir></dir><file name="Observer.php" hash="10d46e3849f531cef13a6ee6dfc6dfa9"/><dir name="Source"><file name="CacheMode.php" hash="b34ae611b8bf913e4b646f4a156cc2a4"/><file name="PostMethods.php" hash="22f500a45f51515409fa9367d0a5e957"/><file name="WeightType.php" hash="4bf1608fb6b665dcc7d834ca35eee174"/></dir><file name="Sro.php" hash="25e2f1675755b57f2a11d47f874fcbc9"/></dir><dir name="etc"><file name="config.xml" hash="94380d19dcf930b359b48a9f128df413"/><file name="system.xml" hash="a176657e9f5565ef20d101059cca833c"/></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="install-4.5.0.php" hash="e0daaac3649b166a33928da3844ad965"/><file name="install-4.6.0.php" hash="5168cdf9b1e60480d5bc90951c69cb20"/><file name="install-4.7.0.php" hash="ad7b3434d1c5fbb0b49212e8bc5923b9"/><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"/><file name="upgrade-4.4.0-4.5.0.php" hash="95dfd40fa6469a711b4b65a331f0b1b7"/><file name="upgrade-4.5.0-4.6.0.php" hash="24686aec7822436598e94680e3e6a948"/><file name="upgrade-4.6.0-4.7.0.php" hash="d12205fcbe16e21bdf233eae06500998"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PedroTeixeira_Correios.xml" hash="e714579bed97c85f2bcc3988dec271da"/></dir></target></contents>
51
  <compatible/>
52
  <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>
53
  </package>