From dfcd82093a23740c9ef6ea518163eadfd084fdfb Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Tue, 31 Mar 2015 17:19:31 -0300 Subject: [PATCH 1/8] =?UTF-8?q?#72=20Corrige=20exce=C3=A7=C3=A3o=20no=20ca?= =?UTF-8?q?so=20de=20falha=20na=20comunica=C3=A7=C3=A3o=20com=20os=20Corre?= =?UTF-8?q?ios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/PedroTeixeira/Correios/Model/Cache.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/code/community/PedroTeixeira/Correios/Model/Cache.php b/app/code/community/PedroTeixeira/Correios/Model/Cache.php index 0d0a7f1..6fd2cdc 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Cache.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Cache.php @@ -211,16 +211,18 @@ protected function _isValidCache($data) { $response = Zend_Http_Response::fromString($data); $content = $response->getBody(); - $pattern = $this->getConfigData('pattern_nocache'); - if ($pattern != '' && preg_match($pattern, $content, $matches)) { - return false; - } + if (empty($content)) { - return false; + throw new Zend_Http_Client_Adapter_Exception(); } libxml_use_internal_errors(true); $xml = simplexml_load_string($content); if (!$xml || !isset($xml->cServico)) { + throw new Zend_Http_Client_Adapter_Exception(); + } + + $pattern = $this->getConfigData('pattern_nocache'); + if ($pattern != '' && preg_match($pattern, $content, $matches)) { return false; } return true; From 52869459f87130aebcd1359e95eea7165458124f Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Tue, 31 Mar 2015 17:19:31 -0300 Subject: [PATCH 2/8] =?UTF-8?q?#72=20Corre=C3=A7=C3=A3o=20do=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PedroTeixeira/Correios/Model/Cache.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/code/community/PedroTeixeira/Correios/Model/Cache.php b/app/code/community/PedroTeixeira/Correios/Model/Cache.php index 0d0a7f1..df17ceb 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Cache.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Cache.php @@ -204,6 +204,8 @@ public function loadByTags() * Validate the response data from Correios. * * @param string $data XML Content + * + * @throws Zend_Http_Client_Adapter_Exception * * @return boolean */ @@ -211,16 +213,18 @@ protected function _isValidCache($data) { $response = Zend_Http_Response::fromString($data); $content = $response->getBody(); - $pattern = $this->getConfigData('pattern_nocache'); - if ($pattern != '' && preg_match($pattern, $content, $matches)) { - return false; - } + if (empty($content)) { - return false; + throw new Zend_Http_Client_Adapter_Exception(); } libxml_use_internal_errors(true); $xml = simplexml_load_string($content); if (!$xml || !isset($xml->cServico)) { + throw new Zend_Http_Client_Adapter_Exception(); + } + + $pattern = $this->getConfigData('pattern_nocache'); + if ($pattern != '' && preg_match($pattern, $content, $matches)) { return false; } return true; From 3ce06641969b21e41b2d2600b5d4ceadeb6539ab Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Wed, 1 Apr 2015 09:59:01 -0300 Subject: [PATCH 3/8] =?UTF-8?q?#73=20Corrigidos=20e=20refatorados=20os=20m?= =?UTF-8?q?=C3=A9todos=20de=20Valida=C3=A7=C3=A3o=20e=20Escrita=20em=20cac?= =?UTF-8?q?he?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PedroTeixeira/Correios/Model/Cache.php | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/app/code/community/PedroTeixeira/Correios/Model/Cache.php b/app/code/community/PedroTeixeira/Correios/Model/Cache.php index 8fd605b..92354b3 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Cache.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Cache.php @@ -202,6 +202,15 @@ public function loadByTags() /** * Validate the response data from Correios. + * This method will choose between Request Cache or Save in Cache + * + * Step 1: + * Invalid responses must call the Cache load. + * Cache loading is requested by throwing adapter exception. + * + * Step 2: + * To save valid responses, it must contain no errors. + * Errors are detected by pattern_nocache and returns false. * * @param string $data XML Content * @@ -211,8 +220,13 @@ public function loadByTags() */ protected function _isValidCache($data) { - $response = Zend_Http_Response::fromString($data); - $content = $response->getBody(); + // Step 1 + try { + $response = Zend_Http_Response::fromString($data); + $content = $response->getBody(); + } catch (Zend_Http_Exception $e) { + throw new Zend_Http_Client_Adapter_Exception($e->getMessage()); + } if (empty($content)) { throw new Zend_Http_Client_Adapter_Exception(); @@ -223,7 +237,8 @@ protected function _isValidCache($data) throw new Zend_Http_Client_Adapter_Exception(); } - $pattern = $this->getConfigData('pattern_nocache'); + // Step 2 + $pattern = $this->getConfigData('pattern_nocache'); if ($pattern != '' && preg_match($pattern, $content, $matches)) { return false; } @@ -235,19 +250,16 @@ protected function _isValidCache($data) * * @param string $data XML Content * - * @throws Exception - * - * @return PedroTeixeira_Correios_Model_Cache + * @return boolean|PedroTeixeira_Correios_Model_Cache */ public function save($data) { - if (!$this->_isValidCache($data)) { - return false; // Invalid for the Cache only - } - $id = $this->_getId(); - $tags = $this->getCacheTags(); - if ($this->getCache()->save($data, $id, $tags)) { - Mage::log("{$this->_code} [cache]: mode={$this->getConfigData('cache_mode')} status=write key={$id}"); + if ($this->_isValidCache($data)) { + $id = $this->_getId(); + $tags = $this->getCacheTags(); + if ($this->getCache()->save($data, $id, $tags)) { + Mage::log("{$this->_code} [cache]: mode={$this->getConfigData('cache_mode')} status=write key={$id}"); + } } return $this; } From 635d211bda22f4a31ee087118632e2a9f6d5ef7e Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Mon, 6 Apr 2015 18:05:34 -0300 Subject: [PATCH 4/8] =?UTF-8?q?#74=20Altera=C3=A7=C3=A3o=20cosm=C3=A9tica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Correios/Model/Carrier/CorreiosMethod.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php index 91d9e65..d85d8f0 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php @@ -762,14 +762,14 @@ protected function _addPostMethods($cServico) $servico->PrazoEntrega = $days; } $servico->EntregaDomiciliar = 'S'; - $servico->EntregaSabado = 'S'; - $servico->Erro = '0'; - $servico->MsgErro = ''; + $servico->EntregaSabado = 'S'; + $servico->Erro = '0'; + $servico->MsgErro = ''; } } } } - + return $cServico; } From e07048977679b48c89138ea254250ffbc476ebee Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Thu, 9 Apr 2015 10:33:20 -0300 Subject: [PATCH 5/8] =?UTF-8?q?#75=20Adicionada=20op=C3=A7=C3=A3o=20de=20e?= =?UTF-8?q?xibir=20aviso=20de=20=C3=A1rea=20de=20risco.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Correios/Model/Carrier/CorreiosMethod.php | 24 +++++++++++++++++++ .../PedroTeixeira/Correios/etc/config.xml | 1 + .../PedroTeixeira/Correios/etc/system.xml | 9 +++++++ 3 files changed, 34 insertions(+) diff --git a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php index d85d8f0..a8cbd78 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php @@ -153,6 +153,9 @@ protected function _getQuotes() } $this->_appendShippingReturn((string) $servicos->Codigo, $shippingPrice, $shippingDelivery); + if ($this->getConfigFlag('show_soft_errors') && !isset($isWarnAppended)) { + $isWarnAppended = $this->_appendShippingWarning($servicos); + } $existReturn = true; } @@ -860,4 +863,25 @@ protected function _splitPack() } return false; } + + /** + * Add a warning message at the top of the shipping method list. + * + * @param SimpleXMLElement $servico + * + * @return boolean + */ + protected function _appendShippingWarning(SimpleXMLElement $servico) + { + $id = (string) $servico->Erro; + $ids = explode(',', $this->getConfigData('soft_errors')); + if (in_array($id, $ids)) { + $error = Mage::getModel('shipping/rate_result_error'); + $error->setCarrier($this->_code); + $error->setErrorMessage((string)$servico->MsgErro); + $this->_result->append($error); + return true; + } + return false; + } } diff --git a/app/code/community/PedroTeixeira/Correios/etc/config.xml b/app/code/community/PedroTeixeira/Correios/etc/config.xml index 87ea8d6..2b771dd 100644 --- a/app/code/community/PedroTeixeira/Correios/etc/config.xml +++ b/app/code/community/PedroTeixeira/Correios/etc/config.xml @@ -84,6 +84,7 @@ Correios 40010 009,010,011 + 0 0 1 0 diff --git a/app/code/community/PedroTeixeira/Correios/etc/system.xml b/app/code/community/PedroTeixeira/Correios/etc/system.xml index 1436bbc..fe6d81f 100644 --- a/app/code/community/PedroTeixeira/Correios/etc/system.xml +++ b/app/code/community/PedroTeixeira/Correios/etc/system.xml @@ -334,6 +334,15 @@ 1 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. + + + select + adminhtml/system_config_source_yesno + 269 + 1 + 1 + 1 + text From 3b0e3ad478f8b2c3fc64a53dc6fd2e30707e9107 Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Thu, 9 Apr 2015 11:00:00 -0300 Subject: [PATCH 6/8] =?UTF-8?q?#75=20Corre=C3=A7=C3=A3o=20do=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php index a8cbd78..476d668 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php @@ -867,7 +867,7 @@ protected function _splitPack() /** * Add a warning message at the top of the shipping method list. * - * @param SimpleXMLElement $servico + * @param SimpleXMLElement $servico Post Method * * @return boolean */ @@ -878,7 +878,7 @@ protected function _appendShippingWarning(SimpleXMLElement $servico) if (in_array($id, $ids)) { $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier($this->_code); - $error->setErrorMessage((string)$servico->MsgErro); + $error->setErrorMessage($servico->MsgErro); $this->_result->append($error); return true; } From af679d53a8edce5a46056699820abbabbaa1b66f Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Fri, 24 Apr 2015 13:56:41 -0300 Subject: [PATCH 7/8] =?UTF-8?q?#62=20Corre=C3=A7=C3=A3o=20do=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Correios/Model/Carrier/CorreiosMethod.php | 7 +- .../PedroTeixeira/Correios/etc/config.xml | 3 +- .../install-4.4.1.php | 105 ++++++++++++++++++ .../upgrade-4.4.0-4.4.1.php | 35 ++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.1.php create mode 100644 app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.4.1.php diff --git a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php index d29d99e..2f9a66d 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php @@ -44,6 +44,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod protected $_freeMethodWeight = null; protected $_midSize = null; protected $_splitUp = 0; + protected $_postingDays = 0; /** * Post methods @@ -346,7 +347,7 @@ protected function _appendShippingReturn($shippingMethod, $shippingPrice = 0, $c sprintf( $this->getConfigData('msgprazo'), $shippingData[0], - (int) ($correiosDelivery + $this->getConfigData('add_prazo')) + (int) ($correiosDelivery + $this->getConfigData('add_prazo') + $this->_postingDays) ) ); } else { @@ -354,7 +355,7 @@ protected function _appendShippingReturn($shippingMethod, $shippingPrice = 0, $c sprintf( $this->getConfigData('msgprazo'), $shippingData[0], - (int) ($shippingData[1] + $this->getConfigData('add_prazo')) + (int) ($shippingData[1] + $this->getConfigData('add_prazo') + $this->_postingDays) ) ); } @@ -461,6 +462,8 @@ protected function _generateVolumeWeight() $itemAltura = $this->_getFitHeight($item); $pesoCubicoTotal += (($itemAltura * $itemLargura * $itemComprimento) * $item->getQty()) / $this->getConfigData('coeficiente_volume'); + + $this->_postingDays = max($this->_postingDays, (int) $_product->getData('posting_days')); } $this->_volumeWeight = number_format($pesoCubicoTotal, 2, '.', ''); diff --git a/app/code/community/PedroTeixeira/Correios/etc/config.xml b/app/code/community/PedroTeixeira/Correios/etc/config.xml index 0d77532..c21a958 100644 --- a/app/code/community/PedroTeixeira/Correios/etc/config.xml +++ b/app/code/community/PedroTeixeira/Correios/etc/config.xml @@ -15,7 +15,7 @@ - 4.4.0 + 4.4.1 @@ -31,6 +31,7 @@ + diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.1.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.1.php new file mode 100644 index 0000000..5b2fca8 --- /dev/null +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.1.php @@ -0,0 +1,105 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ + +/** @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; +$installer->startSetup(); + +/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */ +$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); + +// Add volume to prduct attribute set +$codigo = 'volume_comprimento'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Comprimento (cm)', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'Comprimento da embalagem do produto (Para cálculo dos Correios)' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +// Add volume to prduct attribute set +$codigo = 'volume_altura'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Altura (cm)', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'Altura da embalagem do produto (Para cálculo dos Correios)' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +// Add volume to prduct attribute set +$codigo = 'volume_largura'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Largura (cm)', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'Largura da embalagem do produto (Para cálculo dos Correios)' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$codigo = 'postmethods'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Serviços de Entrega', + 'type' => 'text', + 'input' => 'multiselect', + 'source' => 'pedroteixeira_correios/source_postMethods', + 'backend' => 'eav/entity_attribute_backend_array', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'Selecione os serviços apropriados para o produto.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$codigo = 'fit_size'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Diferença do Encaixe (cm)', + 'type' => 'varchar', + 'input' => 'text', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'Exemplo: Se 1 item mede 10cm de altura, e 2 itens encaixados medem 11cm. A diferença é de 1cm.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$codigo = 'posting_days'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Prazo de Postagem', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'O prazo total é o Prazo dos Correios acrescido do maior Prazo de Postagem dos produtos no carrinho.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.4.1.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.4.1.php new file mode 100644 index 0000000..dd7b680 --- /dev/null +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.4.1.php @@ -0,0 +1,35 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ + +/** @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; +$installer->startSetup(); + +/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */ +$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); + +$codigo = 'posting_days'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Prazo de Postagem', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,bundle,grouped,configurable', + 'note' => 'O prazo total é o Prazo dos Correios acrescido do maior Prazo de Postagem dos produtos no carrinho.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$installer->endSetup(); From 60d607da26a5b0d69ef5827dbc115b258888409e Mon Sep 17 00:00:00 2001 From: jarjar123 Date: Sun, 12 Jul 2015 19:22:40 -0300 Subject: [PATCH 8/8] =?UTF-8?q?#73=20Atualizado=20o=20fork,=20e=20alterada?= =?UTF-8?q?=20a=20vers=C3=A3o=20para=204.5.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- .../Correios/Model/Carrier/CorreiosMethod.php | 27 +- .../PedroTeixeira/Correios/etc/config.xml | 664 +++++++++--------- .../{install-4.4.1.php => install-4.5.0.php} | 0 ....4.0-4.4.1.php => upgrade-4.4.0-4.5.0.php} | 0 5 files changed, 362 insertions(+), 335 deletions(-) rename app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/{install-4.4.1.php => install-4.5.0.php} (100%) rename app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/{upgrade-4.4.0-4.4.1.php => upgrade-4.4.0-4.5.0.php} (100%) diff --git a/README.md b/README.md index 7f9ac3e..67e42c9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PedroTeixeira_Correios -[![Build Status](http://img.shields.io/travis/pedro-teixeira/correios.svg?style=flat)](https://travis-ci.org/pedro-teixeira/correios) [![Magento Connect Popularity](http://img.shields.io/badge/popularity-17k-brightgreen.svg?style=flat)](http://www.magentocommerce.com/magento-connect/pedroteixeira-correios.html) [![MIT](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/pedro-teixeira/correios/blob/master/LICENSE) +[![Build Status](http://img.shields.io/travis/pedro-teixeira/correios.svg?style=flat)](https://travis-ci.org/pedro-teixeira/correios) [![Magento Connect Popularity](http://img.shields.io/badge/popularity-18k-brightgreen.svg?style=flat)](http://www.magentocommerce.com/magento-connect/pedroteixeira-correios.html) [![MIT](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/pedro-teixeira/correios/blob/master/LICENSE) > Módulo de frete para Magento com tracking @@ -241,3 +241,7 @@ find ./app -name "*.php" -exec php -l {} \; ``` *O Magento não segue nenhum code style, por isso compilei uma lista de checks no `ruleset.xml`.* + +## Licença + +[MIT](https://github.com/pedro-teixeira/correios/blob/master/LICENSE) © [Pedro Teixeira](https://pedroteixeira.io). diff --git a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php index 2f9a66d..933cf6b 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php @@ -21,6 +21,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod * @var string */ protected $_code = 'pedroteixeira_correios'; + protected $_isFixed = true; /** * _result property @@ -87,7 +88,10 @@ public function collectRates(Mage_Shipping_Model_Rate_Request $request) return $this->_result; } - // Fix weight + if ($this->_packageWeight == 0) { + $this->_packageWeight = $this->_getNominalWeight(); + } + if ($this->getConfigData('weight_type') == PedroTeixeira_Correios_Model_Source_WeightType::WEIGHT_GR) { $this->_packageWeight = number_format($this->_packageWeight / 1000, 2, '.', ''); } @@ -118,6 +122,27 @@ public function collectRates(Mage_Shipping_Model_Rate_Request $request) return $this->_result; } + + /** + * Gets Nominal Weight + * + * @return number + */ + protected function _getNominalWeight() + { + $weight = 0; + $quote = Mage::getSingleton('checkout/cart')->getQuote(); + if (count($quote->getAllVisibleItems()) == 0) { + $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); + } + if ($quote->isNominal()) { + foreach ($quote->getAllVisibleItems() as $item) { + $product = Mage::getModel('catalog/product')->load($item->getProductId()); + $weight += $product->getWeight(); + } + } + return $weight; + } /** * Get shipping quote diff --git a/app/code/community/PedroTeixeira/Correios/etc/config.xml b/app/code/community/PedroTeixeira/Correios/etc/config.xml index c21a958..3ecb92a 100644 --- a/app/code/community/PedroTeixeira/Correios/etc/config.xml +++ b/app/code/community/PedroTeixeira/Correios/etc/config.xml @@ -15,7 +15,7 @@ - 4.4.1 + 4.5.0 @@ -414,338 +414,336 @@ 0 - - - 10065 - 1.30 - 5 - - 00000000 - 0 - 0 - - - 99999999 - 0.020 - 30 - - - - 10065 - 1.80 - 5 - - 00000000 - 0.020 - 0 - - - 99999999 - 0.050 - 30 - - - - 10065 - 2.45 - 5 - - 00000000 - 0.050 - 0 - - - 99999999 - 0.100 - 30 - - - - 10065 - 3.00 - 5 - - 00000000 - 0.100 - 0 - - - 99999999 - 0.150 - 30 - - - - 10065 - 3.60 - 5 - - 00000000 - 0.150 - 0 - - - 99999999 - 0.200 - 30 - - - - 10065 - 4.15 - 5 - - 00000000 - 0.200 - 0 - - - 99999999 - 0.250 - 30 - - - - 10065 - 4.70 - 5 - - 00000000 - 0.250 - 0 - - - 99999999 - 0.300 - 30 - - - - 10065 - 5.25 - 5 - - 00000000 - 0.300 - 0 - - - 99999999 - 0.350 - 30 - - - - 10065 - 5.80 - 5 - - 00000000 - 0.350 - 0 - - - 99999999 - 0.400 - 30 - - - - 10065 - 6.35 - 5 - - 00000000 - 0.400 - 0 - - - 99999999 - 0.450 - 30 - - - - 10065 - 6.90 - 5 - - 00000000 - 0.450 - 0 - - - 99999999 - 0.500 - 30 - - - - 10138 - 4.50 - 5 - - 00000000 - 0 - 0 - - - 99999999 - 0.020 - 30 - - - - 10138 - 5.00 - 5 - - 00000000 - 0.020 - 0 - - - 99999999 - 0.050 - 30 - - - - 10138 - 5.65 - 5 - - 00000000 - 0.050 - 0 - - - 99999999 - 0.100 - 30 - - - - 10138 - 6.20 - 5 - - 00000000 - 0.100 - 0 - - - 99999999 - 0.150 - 30 - - - - 10138 - 6.80 - 5 - - 00000000 - 0.150 - 0 - - - 99999999 - 0.200 - 30 - - - - 10138 - 7.35 - 5 - - 00000000 - 0.200 - 0 - - - 99999999 - 0.250 - 30 - - - - 10138 - 7.90 - 5 - - 00000000 - 0.250 - 0 - - - 99999999 - 0.300 - 30 - - - - 10138 - 8.45 - 5 - - 00000000 - 0.300 - 0 - - - 99999999 - 0.350 - 30 - - - - 10138 - 9.00 - 5 - - 00000000 - 0.350 - 0 - - - 99999999 - 0.400 - 30 - - - - 10138 - 9.55 - 5 - - 00000000 - 0.400 - 0 - - - 99999999 - 0.450 - 30 - - - - 10138 - 10.10 - 5 - - 00000000 - 0.450 - 0 - - - 99999999 - 0.500 - 30 - - - + + 10065 + 1.40 + 5 + + 00000000 + 0 + 0 + + + 99999999 + 0.020 + 30 + + + + 10065 + 1.95 + 5 + + 00000000 + 0.020 + 0 + + + 99999999 + 0.050 + 30 + + + + 10065 + 2.70 + 5 + + 00000000 + 0.050 + 0 + + + 99999999 + 0.100 + 30 + + + + 10065 + 3.30 + 5 + + 00000000 + 0.100 + 0 + + + 99999999 + 0.150 + 30 + + + + 10065 + 3.90 + 5 + + 00000000 + 0.150 + 0 + + + 99999999 + 0.200 + 30 + + + + 10065 + 4.50 + 5 + + 00000000 + 0.200 + 0 + + + 99999999 + 0.250 + 30 + + + + 10065 + 5.15 + 5 + + 00000000 + 0.250 + 0 + + + 99999999 + 0.300 + 30 + + + + 10065 + 5.75 + 5 + + 00000000 + 0.300 + 0 + + + 99999999 + 0.350 + 30 + + + + 10065 + 6.35 + 5 + + 00000000 + 0.350 + 0 + + + 99999999 + 0.400 + 30 + + + + 10065 + 6.95 + 5 + + 00000000 + 0.400 + 0 + + + 99999999 + 0.450 + 30 + + + + 10065 + 7.55 + 5 + + 00000000 + 0.450 + 0 + + + 99999999 + 0.500 + 30 + + + + 10138 + 5.00 + 5 + + 00000000 + 0 + 0 + + + 99999999 + 0.020 + 30 + + + + 10138 + 5.55 + 5 + + 00000000 + 0.020 + 0 + + + 99999999 + 0.050 + 30 + + + + 10138 + 6.30 + 5 + + 00000000 + 0.050 + 0 + + + 99999999 + 0.100 + 30 + + + + 10138 + 6.90 + 5 + + 00000000 + 0.100 + 0 + + + 99999999 + 0.150 + 30 + + + + 10138 + 7.50 + 5 + + 00000000 + 0.150 + 0 + + + 99999999 + 0.200 + 30 + + + + 10138 + 8.10 + 5 + + 00000000 + 0.200 + 0 + + + 99999999 + 0.250 + 30 + + + + 10138 + 8.75 + 5 + + 00000000 + 0.250 + 0 + + + 99999999 + 0.300 + 30 + + + + 10138 + 9.35 + 5 + + 00000000 + 0.300 + 0 + + + 99999999 + 0.350 + 30 + + + + 10138 + 9.95 + 5 + + 00000000 + 0.350 + 0 + + + 99999999 + 0.400 + 30 + + + + 10138 + 10.55 + 5 + + 00000000 + 0.400 + 0 + + + 99999999 + 0.450 + 30 + + + + 10138 + 11.15 + 5 + + 00000000 + 0.450 + 0 + + + 99999999 + 0.500 + 30 + + diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.1.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.5.0.php similarity index 100% rename from app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.4.1.php rename to app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.5.0.php diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.4.1.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.5.0.php similarity index 100% rename from app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.4.1.php rename to app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.4.0-4.5.0.php