Skip to content

Instantly share code, notes, and snippets.

@deniscsz
Created October 9, 2012 14:00
Show Gist options
  • Save deniscsz/3858998 to your computer and use it in GitHub Desktop.
Save deniscsz/3858998 to your computer and use it in GitHub Desktop.
Calculando que os produtos terão custo de envio de 3 em 3 unidades.
/**
* calculates total value from quote
*
* @return int|float
*/
public function getShippingPrice() {
/**
* get quote items
*/
$items = Mage::getSingleton('checkout/cart')->getItems();
$sumTotal = 0;
$sumMax = 0;
$control = 3;
if($items){
foreach ($items as $item){
/**
* calculate price by items
*/
$priceByItem = $this->calculate($item);
if($sumMax < $priceByItem) {
$sumMax = $priceByItem;
}
if($control%3 == 2) {
$sumTotal += $sumMax;
$sumMax = 0;
}
$control += 1;
}
}
return $sumTotal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment