Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Shipping by Rules for VirtueMart
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VirtueMart
Shipping by Rules for VirtueMart
Commits
069db14b
Commit
069db14b
authored
11 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Implement list handling functions and digit and substring functions
parent
1b13640e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
+4
-1
4 additions, 1 deletion
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
rules_shipping_base.php
+43
-0
43 additions, 0 deletions
rules_shipping_base.php
with
47 additions
and
1 deletion
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
+
4
−
1
View file @
069db14b
...
...
@@ -52,4 +52,7 @@ VMSHIPMENT_RULES_EVALUATE_UNKNOWN_OPERATOR="Unknown operator '%s' encountered du
VMSHIPMENT_RULES_EVALUATE_UNKNOWN_FUNCTION
=
"Unknown function '%s' encountered during evaluation of rule '%s'."
VMSHIPMENT_RULES_EVALUATE_UNKNOWN_ERROR="Unknown error occurred during evaluation of rule '%s'."
VMSHIPMENT_RULES_EVALUATE_ASSIGNMENT_TOPLEVEL
=
"Assignments are not allows inside expressions (rule given was '%s')"
VMSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE="Evaluation yields unknown value while evaluating rule part '%s'."
\ No newline at end of file
VMSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE="Evaluation yields unknown value while evaluating rule part '%s'."
VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_ARGS
=
"List function '%s' requires all arguments to be lists. (Full rule: '%s')"
VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_UNKNOWN="Unknown list function '%s' encountered. (Full rule: '%s')"
This diff is collapsed.
Click to expand it.
rules_shipping_base.php
+
43
−
0
View file @
069db14b
...
...
@@ -766,6 +766,35 @@ class ShippingRule {
return
true
;
}
function
evaluateListFunction
(
$function
,
$args
)
{
# First make sure that all arguments are actually lists:
$allarrays
=
True
;
foreach
(
$args
as
$a
)
{
$allarrays
=
$allarrays
&&
is_array
(
$a
);
}
if
(
!
$allarrays
)
{
JFactory
::
getApplication
()
->
enqueueMessage
(
JText
::
sprintf
(
'VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_ARGS'
,
$function
,
$this
->
rulestring
),
'error'
);
return
false
;
}
switch
(
$func
)
{
case
"length"
:
return
count
(
$args
[
0
]);
break
;
case
"union"
:
case
"join"
:
return
call_user_func_array
(
"array_merge"
,
$args
);
break
;
case
"complement"
:
return
call_user_func_array
(
"array_diff"
,
$args
);
break
;
case
"intersection"
:
return
call_user_func_array
(
"array_intersect"
,
$args
);
break
;
case
"issubset"
:
# Remove all of superset's elements to see if anything else is left:
return
!
array_diff
(
$args
[
0
],
$args
[
1
]);
break
;
case
"contains"
:
# Remove all of superset's elements to see if anything else is left:
# Notice the different argument order compared to issubset!
return
!
array_diff
(
$args
[
1
],
$args
[
0
]);
break
;
case
"list_equal"
:
return
array_unique
(
$args
[
0
])
==
array_unique
(
$args
[
1
]);
break
;
default
:
JFactory
::
getApplication
()
->
enqueueMessage
(
JText
::
sprintf
(
'VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_UNKNOWN'
,
$function
,
$this
->
rulestring
),
'error'
);
return
false
;
}
}
function
evaluateFunction
(
$function
,
$args
)
{
$func
=
strtolower
(
$function
);
// Functions with no argument:
...
...
@@ -792,6 +821,20 @@ class ShippingRule {
case
"not"
:
return
!
$args
[
0
];
break
;
}
}
if
(
count
(
$args
)
==
2
)
{
switch
(
$func
)
{
case
"digit"
:
return
substr
(
$args
[
0
],
$args
[
1
]
-
1
,
1
);
break
;
}
}
if
(
count
(
$args
)
==
3
)
{
switch
(
$func
)
{
case
"substring"
:
return
substr
(
$args
[
0
],
$args
[
1
],
$args
[
2
]);
break
;
}
}
// List functions
if
(
in_array
(
$func
,
array
(
"length"
,
"complement"
,
"issubset"
,
"contains"
,
"union"
,
"join"
,
"intersection"
,
"list_equal"
)))
{
return
evaluateListFunction
(
$func
,
args
);
}
// Functions with variable number of args
switch
(
$func
)
{
case
"max"
:
return
max
(
$args
);
break
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment