address_filter() public static method

Produce a SQL filter to get matching RegionRestrictions to a given address
public static address_filter ( Address $address )
$address Address
 function getRate($address = null)
 {
     if (!$address) {
         $address = singleton('Address');
     }
     $where = array("\"TaxRate\".\"TaxClassID\" = {$this->ID}", RegionRestriction::address_filter($address));
     $sort = implode(', ', array(RegionRestriction::wildcard_sort("PostalCode"), RegionRestriction::wildcard_sort("City"), RegionRestriction::wildcard_sort("State"), RegionRestriction::wildcard_sort("Country"), "\"Rate\" ASC"));
     if ($rate = DataObject::get_one("TaxRate", "(" . implode(") AND (", $where) . ")", true, $sort)) {
         return $rate->Rate;
     }
     return 0;
 }
Esempio n. 2
0
 /**
  * Find the appropriate shipping rate from stored table range metrics
  */
 public function calculateRate(ShippingPackage $package, Address $address)
 {
     $rate = null;
     $packageconstraints = array("Weight" => 'weight', "Volume" => 'volume', "Value" => 'value', "Quantity" => 'quantity');
     $constraintfilters = array();
     foreach ($packageconstraints as $db => $pakval) {
         $mincol = "\"TableShippingRate\".\"{$db}Min\"";
         $maxcol = "\"TableShippingRate\".\"{$db}Max\"";
         $constraintfilters[] = "(" . "{$mincol} >= 0" . " AND {$mincol} <= " . $package->{$pakval}() . " AND {$maxcol} > 0" . " AND {$maxcol} >= " . $package->{$pakval}() . " AND {$mincol} < {$maxcol}" . ")";
     }
     $filter = "(" . implode(") AND (", array("\"ShippingMethodID\" = " . $this->ID, RegionRestriction::address_filter($address), implode(" OR ", $constraintfilters))) . ")";
     if ($tr = DataObject::get_one("TableShippingRate", $filter, true, "Rate ASC")) {
         $rate = $tr->Rate;
     }
     $this->CalculatedRate = $rate;
     return $rate;
 }
 /**
  * Find the appropriate shipping rate from stored table range metrics
  */
 public function calculateRate(ShippingPackage $package, Address $address)
 {
     $rate = null;
     $packageconstraints = array("Weight" => 'weight', "Volume" => 'volume', "Value" => 'value', "Quantity" => 'quantity');
     $constraintfilters = array();
     $emptyconstraint = array();
     foreach ($packageconstraints as $db => $pakval) {
         $mincol = "\"TableShippingRate\".\"{$db}Min\"";
         $maxcol = "\"TableShippingRate\".\"{$db}Max\"";
         //constrain to rates with valid constraints
         $constraintfilters[] = "(" . "{$mincol} >= 0" . " AND {$mincol} <= " . $package->{$pakval}() . " AND {$maxcol} > 0" . " AND {$maxcol} >= " . $package->{$pakval}() . " AND {$mincol} < {$maxcol}" . ")";
         //also include a special case where all constraints are empty
         $emptyconstraint[] = "({$mincol} = 0 AND {$maxcol} = 0)";
     }
     $constraintfilters[] = "(" . implode(" AND ", $emptyconstraint) . ")";
     $filter = "(" . implode(") AND (", array("\"ShippingMethodID\" = " . $this->ID, RegionRestriction::address_filter($address), implode(" OR ", $constraintfilters))) . ")";
     if ($tr = DataObject::get_one("TableShippingRate", $filter, true, "LENGTH(\"RegionRestriction\".\"PostalCode\") DESC, Rate ASC")) {
         $rate = $tr->Rate;
     }
     $this->CalculatedRate = $rate;
     return $rate;
 }
Esempio n. 4
0
 public static function get_zones_for_address(Address $address)
 {
     $where = RegionRestriction::address_filter($address);
     return self::get()->where($where)->sort('PostalCode DESC, City DESC, State DESC, Country DESC')->innerJoin("ZoneRegion", "\"Zone\".\"ID\" = \"ZoneRegion\".\"ZoneID\"")->innerJoin("RegionRestriction", "\"ZoneRegion\".\"ID\" = \"RegionRestriction\".\"ID\"");
 }
 public function getRate(Address $address)
 {
     $where = RegionRestriction::address_filter($address);
     return DataObject::get_one("RegionRestriction_RateTest", $where, true, "Rate ASC");
 }