Skip to content

Commit

Permalink
Merge pull request #7 from jarjar123/divisao_de_pacote
Browse files Browse the repository at this point in the history
Adicionada opção de dividir a entrega em mais de um pacote.
  • Loading branch information
rafaelpatro committed Mar 9, 2015
2 parents c8e8856 + 2166a24 commit 4fa612d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
protected $_volumeWeight = null;
protected $_freeMethodWeight = null;
protected $_midSize = null;
protected $_splitUp = 0;

/**
* Post methods
Expand Down Expand Up @@ -109,7 +110,7 @@ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
$this->_postMethodsExplode = explode(',', $this->getConfigData('postmethods'));

// Generate Volume Weight
if ($this->_generateVolumeWeight() === false || $this->_loadMidSize()->_removeInvalidServices() === false) {
if ($this->_generateVolumeWeight() === false || $this->_removeInvalidServices() === false) {
$this->_throwError('dimensionerror', 'Dimension error', __LINE__);
return $this->_result;
}
Expand Down Expand Up @@ -152,6 +153,7 @@ protected function _getQuotes()
$stringPrice = str_replace('.', '', $stringPrice);
$stringPrice = str_replace(',', '.', $stringPrice);
$shippingPrice = floatval($stringPrice);
$shippingPrice *= pow(2, $this->_splitUp);
$shippingDelivery = (int) $servicos->PrazoEntrega;

if ($shippingPrice <= 0) {
Expand Down Expand Up @@ -695,20 +697,23 @@ protected function _loadMidSize()
*/
protected function _removeInvalidServices()
{
foreach ($this->_postMethodsExplode as $key => $method) {
$this->_loadMidSize();
$tmpMethods = $this->_postMethodsExplode;
foreach ($tmpMethods as $key => $method) {
$isOverSize = ($this->_midSize > $this->getConfigData("validate/serv_{$method}/max/size"));
$isOverSize |= ($this->_midSize * 3 > $this->getConfigData("validate/serv_{$method}/max/sum"));
$isOverWeight = ($this->_packageWeight > $this->getConfigData("validate/serv_{$method}/max/weight"));

if ($isOverSize || $isOverWeight) {
unset($this->_postMethodsExplode[$key]);
unset($tmpMethods[$key]);
}
}

if (count($this->_postMethodsExplode) == 0) {
return false;
if (count($tmpMethods) == 0) {
return $this->_splitPack();
}

$this->_postMethodsExplode = $tmpMethods;
$this->_postMethods = implode(',', $this->_postMethodsExplode);
$this->_postMethodsFixed = $this->_postMethods;
return $this;
Expand Down Expand Up @@ -845,4 +850,22 @@ protected function _getFitHeight($item)

return $height;
}

/**
* Splits the package in two parts.
* If the package is already splited, each piece will be splited in two equal parts.
*
* @return boolean|PedroTeixeira_Correios_Model_Carrier_CorreiosMethod
*/
protected function _splitPack()
{
if ($this->getConfigFlag('split_pack')) {
$this->_splitUp++;
$this->_volumeWeight /= 2;
$this->_packageWeight /= 2;
$this->_packageValue /= 2;
return $this->_removeInvalidServices();
}
return false;
}
}
1 change: 1 addition & 0 deletions app/code/community/PedroTeixeira/Correios/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<add_prazo>0</add_prazo>
<showmethod>1</showmethod>
<filter_by_item>0</filter_by_item>
<split_pack>1</split_pack>

<!-- MESSAGES -->
<msgprazo>%s - Em média %d dia(s)</msgprazo>
Expand Down
10 changes: 10 additions & 0 deletions app/code/community/PedroTeixeira/Correios/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@
<show_in_store>1</show_in_store>
<comment>Esta configuração se aplica somente quando Correios Cache estiver ativo, em Sistema > Gerenciar Cache.</comment>
</cache_mode>
<split_pack translate="label">
<label>Habilitar Divisão de Pacotes</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>268</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>O pacote é dividido, caso o carrinho exceda os limites de peso e tamanho, para todos os serviços. A divisão se repete até que os limites sejam válidos, para um ou mais serviços.</comment>
</split_pack>
<sort_order translate="label">
<label>Ordenar Por</label>
<frontend_type>text</frontend_type>
Expand Down

0 comments on commit 4fa612d

Please sign in to comment.