本文整理汇总了PHP中Zone::get_zones_for_address方法的典型用法代码示例。如果您正苦于以下问题:PHP Zone::get_zones_for_address方法的具体用法?PHP Zone::get_zones_for_address怎么用?PHP Zone::get_zones_for_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zone
的用法示例。
在下文中一共展示了Zone::get_zones_for_address方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculateRate
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;
}
示例2: check
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;
}
示例3: assertNoZoneMatch
public function assertNoZoneMatch($address)
{
$zones = Zone::get_zones_for_address($address);
$this->assertFalse($zones->exists(), "No zones exist");
}