public function getShipping()
{
if (!$this->address) {
return 0;
}
$rate = $this->address->shippingRate();
$total = 0;
$primaryShipping = 0;
$nextShipping = 0;
//first find the highest shipping cost, and use that as a base
foreach ($this->items as $i) {
if ($i->product->base_shipping > $primaryShipping) {
$primaryShipping = $i->product->base_shipping;
}
}
//then add up the total
foreach ($this->items as $i) {
if ($primaryShipping === $i->product->base_shipping) {
$total += $i->product->base_shipping * 1 + ($i->quantity - 1) * $i->product->next_shipping;
} else {
$total += $i->quantity * $i->product->next_shipping;
}
}
return $total * $rate;
}