Skip to content
Snippets Groups Projects
Commit 2f360567 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Allow variables of the form {varname} in the rule names; They are replaced by...

Allow variables of the form {varname} in the rule names; They are replaced by the values of the cart variables
parent a7e1e09b
No related branches found
No related tags found
No related merge requests found
...@@ -223,10 +223,11 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -223,10 +223,11 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
foreach ($method->rules as $r) { foreach ($method->rules as $r) {
if ($r->matches($cartvals)) { if ($r->matches($cartvals)) {
vmdebug('Rule '.$r->name.' ('.$r->rulestring.') matched.'); $rulename=$r->getRuleName($cartvals);
vmdebug('Rule '.$rulename.' ('.$r->rulestring.') matched.');
$method->tax_id = $r->tax_id; $method->tax_id = $r->tax_id;
$method->matched_rule = $r; $method->matched_rule = $r;
$method->rule_name = $r->name; $method->rule_name = $r->getRuleName($cartvals);
$method->cost = $r->getShippingCosts($cartvals); $method->cost = $r->getShippingCosts($cartvals);
$method->includes_tax = $r->includes_tax; $method->includes_tax = $r->includes_tax;
return $method->cost; return $method->cost;
...@@ -469,10 +470,10 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -469,10 +470,10 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
foreach ($method->rules as $r) { foreach ($method->rules as $r) {
if ($r->matches($cartvals)) { if ($r->matches($cartvals)) {
$method->matched_rule = $r; $method->matched_rule = $r;
$method->rule_name = $r->name; $method->rule_name = $r->getRuleName($cartvals);
// If NoShipping is set, this method should NOT offer any shipping at all, so return FALSE, otherwise TRUE // If NoShipping is set, this method should NOT offer any shipping at all, so return FALSE, otherwise TRUE
if ($r->isNoShipping()) { if ($r->isNoShipping()) {
vmdebug('checkConditions '.$method->shipment_name.' indicates NoShipping for rule "'.$r->name.'" ('.$r->rulestring.').'); vmdebug('checkConditions '.$method->shipment_name.' indicates NoShipping for rule "'.$method->rule_name.'" ('.$r->rulestring.').');
return FALSE; return FALSE;
} else { } else {
return TRUE; return TRUE;
...@@ -845,6 +846,20 @@ class ShippingRule { ...@@ -845,6 +846,20 @@ class ShippingRule {
return true; return true;
} }
function getRuleName($vals) {
// Replace all {variable} tags in the name by the variables from $vals
$matches=array();
$name=$this->name;
preg_match_all('/{([A-Za-z0-9_]+)}/', $name, $matches);
foreach ($matches[1] as $m) {
if (isset($vals[$m])) {
$name = str_replace("{".$m."}", strval($vals[$m]), $name);
}
}
return $name;
}
function getShippingCosts($vals) { function getShippingCosts($vals) {
return $this->calculateShipping($vals); return $this->calculateShipping($vals);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment