get_zones_for_address() public static method

* Returns a DataSet of matching zones
public static get_zones_for_address ( Address $address )
$address Address
 function calculateRate(ShippingPackage $package, $address)
 {
     $rate = null;
     $ids = Zone::get_zones_for_address($address);
     if (!$ids) {
         return $rate;
     }
     $ids = $ids->map('ID', 'ID');
     $packageconstraints = array("Weight" => 'weight', "Volume" => 'volume', "Value" => 'value', "Quantity" => 'quantity');
     $constraintfilters = array();
     foreach ($packageconstraints as $db => $pakval) {
         $mincol = "\"ZonedShippingRate\".\"{$db}Min\"";
         $maxcol = "\"ZonedShippingRate\".\"{$db}Max\"";
         $constraintfilters[] = "(" . "{$mincol} >= 0" . " AND {$mincol} <= " . $package->{$pakval}() . " AND {$maxcol} > 0" . " AND {$maxcol} >= " . $package->{$pakval}() . " AND {$mincol} < {$maxcol}" . ")";
     }
     $filter = "(" . implode(") AND (", array("\"ZonedShippingMethodID\" = " . $this->ID, "\"ZoneID\" IN(" . implode(",", $ids) . ")", implode(" OR ", $constraintfilters))) . ")";
     //order by zone specificity
     $orderby = "";
     if (count($ids) > 1) {
         $orderby = "CASE \"ZonedShippingRate\".\"ZoneID\"";
         $count = 1;
         foreach ($ids as $id) {
             $orderby .= " WHEN {$id} THEN {$count} ";
             $count++;
         }
         $orderby .= "ELSE {$count} END ASC,";
     }
     $orderby .= "\"ZonedShippingRate\".\"Rate\" ASC";
     if ($sr = DataObject::get_one("ZonedShippingRate", $filter, true, $orderby)) {
         $rate = $sr->Rate;
     }
     $this->CalculatedRate = $rate;
     return $rate;
 }
 public function check(Discount $discount)
 {
     $zones = $discount->Zones();
     if (!$zones->exists()) {
         return true;
     }
     $address = $this->order->getShippingAddress();
     if (!$address) {
         $this->error(_t("OrderCouponModifier.NOTINZONE", "This coupon can only be used for a specific shipping location."));
         return false;
     }
     $currentzones = Zone::get_zones_for_address($address);
     if (!$currentzones || !$currentzones->exists()) {
         $this->error(_t("OrderCouponModifier.NOTINZONE", "This discount can only be used for a specific shipping location."));
         return false;
     }
     //check if any of currentzones is in zones
     $inzone = false;
     foreach ($currentzones as $zone) {
         if ($zones->find('ID', $zone->ID)) {
             $inzone = true;
             break;
         }
     }
     if (!$inzone) {
         $this->error(_t("OrderCouponModifier.NOTINZONE", "This discount can only be used for a specific shipping location."));
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 public function assertNoZoneMatch($address)
 {
     $zones = Zone::get_zones_for_address($address);
     $this->assertFalse($zones->exists(), "No zones exist");
 }