diff --git a/rules_shipping_base.php b/rules_shipping_base.php index 7c4b97f09230c451c5057a226d205ea0a8971418..5014e82e332aa50deb2e9a93d0b2f7f96540e86c 100644 --- a/rules_shipping_base.php +++ b/rules_shipping_base.php @@ -223,10 +223,11 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { foreach ($method->rules as $r) { 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->matched_rule = $r; - $method->rule_name = $r->name; + $method->rule_name = $r->getRuleName($cartvals); $method->cost = $r->getShippingCosts($cartvals); $method->includes_tax = $r->includes_tax; return $method->cost; @@ -469,10 +470,10 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { foreach ($method->rules as $r) { if ($r->matches($cartvals)) { $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 ($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; } else { return TRUE; @@ -845,6 +846,20 @@ class ShippingRule { 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) { return $this->calculateShipping($vals); }