Dear Andreashsalim,
Your approach is indeed the same as I would take (Except that you need to name the condition variable for PalReg Zipcheck2 ! And I would combine the two rules for each city by using the max(...) function):
Variable=TotByVol; Value =(Ceil(MaxLength*MaxWidth*MaxHeight)/6000)*Weight
Variable=Zipcheck1;Value=10110<=ZIP<=14530
Variable=Zipcheck2;Value=30111<=ZIP<=30268
Name=JktReg;condition=Zipcheck1; Shipping=max(TotByVol, 8000*Weight)
Name=PalReg; condition=Zipcheck2; Shipping=max(TotByVol, 20000*Weight)
If you have lots of different cities, then I suppose it would be more efficient to create a dedicated plugin to determine your particular shipping costs. This could either be a standalone shipping plugin, which hardcodes the whole shipping cost structure directly in PHP, or it can be a plugin for the shipping by rules plugins (see
open-tools.net/virtuemart/advanced-shipp...ipping-by-rules.html), which calculates your constants (8000 and 20000) from the ZIP and stores it into a variable or provides it as a function, which is then available in the rules. I would implement this in a plugin like:
function onVmShippingRulesRegisterCustomFunctions(&$cartvals, $cart, $products, $method, $cart_prices) {
return array (
'CostByZIP' => array ($this, 'calculate_cost_constant_by_zip'),
);
}
function calculate_cost_constant_by_zip($args, $rule) {
$zip = $args[0];
if (10110<=$zip && $zip <=14530) {
return 8000;
elseif (30111<=$zip && $zip<=30268) {
return 20000;
} elseif (.....) {
....
} else {
return 0;
}
}
You can then use this function in the rules:
Variable=TotByVol; Value =(Ceil(MaxLength*MaxWidth*MaxHeight)/6000)*Weight
Name=Shipping by zip; Shipping=max(TotByVol, CostByZIP(ZIP)*Weight)
In any case, I don't think there is an easy way around explicitly writing the checks for all zip ranges / individual zip values for your cities. Just putting this into the rules is not very efficient, because the plugin has to parse the rules for each cart modification, and parsing rules with several thousand conditions can take some time. Implementing it directly in php is certainly faster.
Best regards,
Reinhold