10, 'a2000' => 20 )); WeightShippingModifier::set_shippingCostsZone2(array( 'a500' => 15, 'a1000' => 20, 'a1500' => 25, 'a2000' => 30 )); */ class WeightShippingModifier extends OrderModifier { static $default_charge = 0; static function set_default_charge($defaultCharge) { self::$default_charge = $defaultCharge; } static $shippingCostsZone1 = array(); //CEE static function set_shippingCostsZone1($array) { self::$shippingCostsZone1 = array_merge(self::$shippingCostsZone1, $array); } static $shippingCostsZone2 = array(); //EXTRA CEE static function set_shippingCostsZone2($array) { self::$shippingCostsZone2 = array_merge(self::$shippingCostsZone2, $array); } function LiveAmount() { $order = ShoppingCart::current_order(); /* function totalWeight(){ $total = 0; $order = ShoppingCart::current_order(); $items = $order->Items(); if($items){ foreach($items as $item) { $total += $item->Weight * $item->Quantity; } } return $total; } */ $totalWeight = $order->totalWeight(); $shippingZone = $this->Zone(); $country = ''; // if there is a shipping country then check whether it is national or international if($shippingZone) { if($shippingZone == 'CEE') return $this->getCostFromWeightList($totalWeight, self::$shippingCostsZone1); else return $this->getCostFromWeightList($totalWeight, self::$shippingCostsZone2); } else { if($order->MemberID && $member = DataObject::get_by_id('Member', $order->MemberID)) { if($member->Country) $country = $member->Country; else $country = Geoip::visitor_country(); } if(!$country) $country = 'CEE'; if($country == 'IT') return $this->getCostFromWeightList($totalWeight, self::$shippingCostsZone1); else return $country; } } /** * Get the cost from a list of max-weight => cost pairs */ function getCostFromWeightList($totalWeight, $shippingCosts) { if($shippingCosts) { foreach($shippingCosts as $weight => $cost) { $weight = intval(substr($weight,1)); if($totalWeight < $weight) return $cost; } return array_pop($shippingCosts); } } function Country() { return $this->ID ? $this->Country : $this->LiveCountry(); } function Zone() { $zone = ''; $id = $this->Country(); switch($id){ case 'IT': $zone = "CEE"; break; default: $zone = $id; } return $zone; } function IsDefaultCharge() { return $this->ID ? $this->ShippingChargeType == 'Default' : $this->LiveIsDefaultCharge(); } protected function LiveCountry() { $order = ShoppingCart::current_order(); return $order->findShippingCountry(true); } protected function LiveIsDefaultCharge() { return !$this->LiveCountry() || !array_key_exists($this->LiveCountry(), self::$charges_by_country); } function Currency() { if(class_exists('Payment')) { return Payment::site_currency(); } } function ShowInCart() { return $this->Total() > 0; } /** * @TODO Add i18n entities to the text. * @return string */ function TableTitle() { if($this->Country()) { $countryList = Geoip::getCountryDropDown(); return "{$countryList[$this->Country()]}"; } else { return; } } } ?>