Commit 66aa27da authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

First attempts at returning multiple rates...

parent 416b2392
BASE=rules_shipping
BASE_ADV=rules_shipping_advanced
PLUGINTYPE=vmshipment
VERSION=2.2.0
VERSION=2.3.0
PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE).script.php $(BASE).xml index.html
PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html
......
......@@ -16,6 +16,14 @@ VMSHIPMENT_RULES_HELP_ADV="<div style='background: #DDDDDD; padding:5px; margin:
VMSHIPMENT_RULES_LENGTH_UNIT="Length Unit"
VMSHIPMENT_RULES_LENGTH_UNIT_DESC="The length unit, in which the length, width and heights are given, and from which the volume is calculated."
VMSHIPMENT_RULES_OFFER="Offer matching rules"
VMSHIPMENT_RULES_OFFER_DESC="Select whether to offer only the first matching rule of this method, all matching rules, or zone-based."
VMSHIPMENT_RULES_OFFER_FIRST="Offer only the first matching rule"
VMSHIPMENT_RULES_OFFER_FIRST_ZONE_ALL="Offer all matching rules of the zone with the first match"
VMSHIPMENT_RULES_OFFER_FIRST_EACH_ZONE="Offer the first matching rule of each zone"
VMSHIPMENT_RULES_OFFER_ALL="Offer all matching rules"
VMSHIPMENT_RULES_COUNTRIES1_LABEL="<b>Rules for country set 1</b>"
VMSHIPMENT_RULES_COUNTRIES2_LABEL="<b>Rules for country set 2</b>"
VMSHIPMENT_RULES_COUNTRIES3_LABEL="<b>Rules for country set 3</b>"
......
......@@ -36,6 +36,7 @@
stripext="0" exclude="^_" />
<param name="weight_unit" type="vmweightunit" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_UNIT" description="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_UNIT_DESC"/>
<param name="length_unit" type="vmlengthunit" size="10" default="" label="VMSHIPMENT_RULES_LENGTH_UNIT" description="VMSHIPMENT_RULES_LENGTH_UNIT_DESC"/>
<param name="offer_rules" type="hidden" default="0" label="VMSHIPMENT_RULES_OFFER" description="VMSHIPMENT_RULES_OFFER_DESC" />
<param type="rklabel" default='VMSHIPMENT_RULES_HELP' />
......
......@@ -35,6 +35,12 @@
stripext="0" exclude="^_" />
<param name="weight_unit" type="vmweightunit" size="10" default="" label="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_UNIT" description="VMSHIPMENT_WEIGHT_COUNTRIES_WEIGHT_UNIT_DESC"/>
<param name="length_unit" type="vmlengthunit" size="10" default="" label="VMSHIPMENT_RULES_LENGTH_UNIT" description="VMSHIPMENT_RULES_LENGTH_UNIT_DESC"/>
<param name="offer_rules" type="list" default="0" label="VMSHIPMENT_RULES_OFFER" description="VMSHIPMENT_RULES_OFFER_DESC" >
<option value="0">VMSHIPMENT_RULES_OFFER_FIRST</option>
<option value="1">VMSHIPMENT_RULES_OFFER_FIRST_ZONE_ALL</option>
<option value="2">VMSHIPMENT_RULES_OFFER_FIRST_EACH_ZONE</option>
<option value="3">VMSHIPMENT_RULES_OFFER_ALL</option>
</param>
<param type="rklabel" default='VMSHIPMENT_RULES_HELP_ADV' />
......
......@@ -290,25 +290,25 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
return new ShippingRule($r, $countries, $tax);
}
private function parseMethodRule ($rulestring, $countries, $tax, &$method) {
private function parseMethodRule ($nr, $rulestring, $countries, $tax, &$method) {
$rules1 = preg_split("/(\r\n|\n|\r)/", $rulestring);
foreach ($rules1 as $r) {
// Ignore empty lines
if (empty($r)) continue;
$method->rules[] = $this->createMethodRule ($r, $countries, $tax);
$method->rules[$nr][] = $this->createMethodRule ($r, $countries, $tax);
}
}
protected function parseMethodRules (&$method) {
if (!isset($method->rules)) $method->rules = array();
$this->parseMethodRule ($method->rules1, $method->countries1, $method->tax_id1, $method);
$this->parseMethodRule ($method->rules2, $method->countries2, $method->tax_id2, $method);
$this->parseMethodRule ($method->rules3, $method->countries3, $method->tax_id3, $method);
$this->parseMethodRule ($method->rules4, $method->countries4, $method->tax_id4, $method);
$this->parseMethodRule ($method->rules5, $method->countries5, $method->tax_id5, $method);
$this->parseMethodRule ($method->rules6, $method->countries6, $method->tax_id6, $method);
$this->parseMethodRule ($method->rules7, $method->countries7, $method->tax_id7, $method);
$this->parseMethodRule ($method->rules8, $method->countries8, $method->tax_id8, $method);
$this->parseMethodRule (1, $method->rules1, $method->countries1, $method->tax_id1, $method);
$this->parseMethodRule (2, $method->rules2, $method->countries2, $method->tax_id2, $method);
$this->parseMethodRule (3, $method->rules3, $method->countries3, $method->tax_id3, $method);
$this->parseMethodRule (4, $method->rules4, $method->countries4, $method->tax_id4, $method);
$this->parseMethodRule (5, $method->rules5, $method->countries5, $method->tax_id5, $method);
$this->parseMethodRule (6, $method->rules6, $method->countries6, $method->tax_id6, $method);
$this->parseMethodRule (7, $method->rules7, $method->countries7, $method->tax_id7, $method);
$this->parseMethodRule (8, $method->rules8, $method->countries8, $method->tax_id8, $method);
}
protected function getOrderArticles (VirtueMartCart $cart) {
......@@ -427,16 +427,26 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
protected function checkConditions ($cart, $method, $cart_prices) {
if (!isset($method->rules)) $this->parseMethodRules($method);
// $method->offer_rules has the following possible values:
// 0 ... Offer only the first matching rule (default)
// 1 ... Offer all matching rules of the first zone with a match
// 2 ... Offer the first matching rule of each zone
// 3 ... Offer all matching rules from all zones
$cartvals = $this->getCartValues ($cart, $method, $cart_prices);
foreach ($method->rules as $r) {
if ($r->matches($cartvals)) {
$method->matched_rule = $r;
$method->rule_name = $r->name;
return TRUE;
$nr = 0;
foreach ($method->rules as $zone) {
foreach ($zone as $r) {
if ($r->matches($cartvals)) {
$method->matched_rule = $r;
$method->rule_name = $r->name;
$nr++;
}
}
}
vmdebug('checkConditions '.$method->name.' does not fit');
return FALSE;
if ($nr==0) {
vmdebug('checkConditions '.$method->name.' does not fit');
}
return $nr;
}
/**
......@@ -542,14 +552,14 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
if (isset($data['rules1'])) {
// Try to parse all rules (and spit out error) to inform the user:
$method = new StdClass ();
$this->parseMethodRule ($data['rules1'], isset($data['countries1'])?$data['countries1']:array(), $data['tax_id1'], $method);
$this->parseMethodRule ($data['rules2'], isset($data['countries2'])?$data['countries2']:array(), $data['tax_id2'], $method);
$this->parseMethodRule ($data['rules3'], isset($data['countries3'])?$data['countries3']:array(), $data['tax_id3'], $method);
$this->parseMethodRule ($data['rules4'], isset($data['countries4'])?$data['countries4']:array(), $data['tax_id4'], $method);
$this->parseMethodRule ($data['rules5'], isset($data['countries5'])?$data['countries5']:array(), $data['tax_id5'], $method);
$this->parseMethodRule ($data['rules6'], isset($data['countries6'])?$data['countries6']:array(), $data['tax_id6'], $method);
$this->parseMethodRule ($data['rules7'], isset($data['countries7'])?$data['countries7']:array(), $data['tax_id7'], $method);
$this->parseMethodRule ($data['rules8'], isset($data['countries8'])?$data['countries8']:array(), $data['tax_id8'], $method);
$this->parseMethodRule (1, $data['rules1'], isset($data['countries1'])?$data['countries1']:array(), $data['tax_id1'], $method);
$this->parseMethodRule (2, $data['rules2'], isset($data['countries2'])?$data['countries2']:array(), $data['tax_id2'], $method);
$this->parseMethodRule (3, $data['rules3'], isset($data['countries3'])?$data['countries3']:array(), $data['tax_id3'], $method);
$this->parseMethodRule (4, $data['rules4'], isset($data['countries4'])?$data['countries4']:array(), $data['tax_id4'], $method);
$this->parseMethodRule (5, $data['rules5'], isset($data['countries5'])?$data['countries5']:array(), $data['tax_id5'], $method);
$this->parseMethodRule (6, $data['rules6'], isset($data['countries6'])?$data['countries6']:array(), $data['tax_id6'], $method);
$this->parseMethodRule (7, $data['rules7'], isset($data['countries7'])?$data['countries7']:array(), $data['tax_id7'], $method);
$this->parseMethodRule (8, $data['rules8'], isset($data['countries8'])?$data['countries8']:array(), $data['tax_id8'], $method);
}
$ret=$this->setOnTablePluginParams ($name, $id, $table);
return $ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment