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;
}