Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions app/code/community/Storm/Correios/Model/Carrier/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
if (!$rates = $this->_doRequest($request)) {
return false;
}


$alert = null;
$smarterrors = array();
foreach ($rates as $rate) {
if ($rate->hasError()) {
if ($this->_getHelper()->getConfigData('showmethod')) {
$this->_appendError($result, sprintf('%s: %s', $this->_getMethodTitle($rate), $rate->getErrorMessage()));
}
continue;
if ($rate->hasPrice()) {
$alert = $rate->getErrorMessage();
} else {
if (!$this->_getHelper()->getConfigData('show_smarterrors')) {
$this->_appendError($result, sprintf('%s: %s', $this->_getMethodTitle($rate), $rate->getErrorMessage()));
} else {
if (($rate->getError() != '-6') && ($rate->getError() != '008')) {
$smarterrors[] = $rate->getError();
}
}
continue;
}
}

$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code)
->setCarrierTitle($this->getConfigData('title'))
Expand All @@ -57,6 +67,25 @@ public function collectRates(Mage_Shipping_Model_Rate_Request $request)

$result->append($method);
}

if ($this->_getHelper()->getConfigData('showmethod')) {
if (($this->_getHelper()->getConfigData('show_smarterrors')) && (!empty($smarterrors))) {
if (count(array_count_values($smarterrors)) == 1) {
$this->_appendError($result, $rates[0]->getErrorMessage());
} else {
foreach ($rates as $rate) {
if ($rate->hasError()) {
$this->_appendError($result, sprintf('%s: %s', $this->_getMethodTitle($rate), $rate->getErrorMessage()));
}
}
}
}

if ($alert != null) {
$this->_appendError($result, $alert);
}
}

} catch (Exception $e) {
$this->_appendError($result, $e->getMessage());
return $result;
Expand Down Expand Up @@ -358,4 +387,4 @@ protected function _getHelper()
{
return Mage::helper('correios');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ private function _convertWebserviceValues(stdClass $data)
$result->setError($data->Erro)
->setErrorMessage($data->MsgErro);

return $result;
if ((!$data->Valor) || ($data->Valor == '0,00')) {
return $result;
}
}

$result->setPrice($this->_getHelper()->convertToFloat($data->Valor))
Expand All @@ -204,4 +206,4 @@ private function _convertWebserviceValues(stdClass $data)

return $result;
}
}
}
18 changes: 14 additions & 4 deletions app/code/community/Storm/Correios/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,21 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</showmethod>
<show_smarterrors>
<label>Show smart errors</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<comment><![CDATA[Only if this option is yes the error messages will be displayed grouped]]></comment>
<sort_order>14</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</show_smarterrors>
<show_deliverytime>
<label>Show delivery time</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>14</sort_order>
<sort_order>15</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -146,7 +156,7 @@
<label>Calculate Handling Fee</label>
<frontend_type>select</frontend_type>
<source_model>shipping/source_handlingType</source_model>
<sort_order>15</sort_order>
<sort_order>16</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
Expand All @@ -156,7 +166,7 @@
<frontend_type>text</frontend_type>
<comment><![CDATA[This value will be added on final price of shipping]]></comment>
<validate>validate-number</validate>
<sort_order>16</sort_order>
<sort_order>17</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
Expand All @@ -174,4 +184,4 @@
</groups>
</carriers>
</sections>
</config>
</config>