/
discount.coretag
64 lines (57 loc) · 1.63 KB
/
discount.coretag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2002-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
UserTag discount Order code
UserTag discount AddAttr
UserTag discount attrAlias space discount_space
UserTag discount hasEndTag
UserTag discount PosNumber 1
UserTag discount Version 1.7
UserTag discount Routine <<EOR
# Sets the value of a discount field
sub {
my($code, $opt, $value) = @_;
# API compatibility
if(! ref $opt) {
$value = $opt;
$opt = {};
}
if (! ($::Discounts
and $Vend::Session->{discount_space}
and $Vend::Session->{discount}
and $Vend::DiscountSpaceName)) {
$::Discounts
= $Vend::Session->{discount}
= $Vend::Session->{discount_space}{ $Vend::DiscountSpaceName = 'main' }
||= ($Vend::Session->{discount} || {});
}
my $dspace;
if ($Vend::Cfg->{DiscountSpacesOn} and $dspace = $opt->{discount_space}) {
$dspace = $Vend::Session->{discount_space}{$dspace} ||= {};
}
else {
$dspace = $::Discounts;
}
if($opt->{subtract}) {
$value = <<EOF;
my \$tmp = \$s - $opt->{subtract};
\$tmp = 0 if \$tmp < 0;
return \$tmp;
EOF
}
elsif ($opt->{level}) {
$value = <<EOF;
return (\$s * \$q) if \$q < $opt->{level};
my \$tmp = \$s / \$q;
return \$s - \$tmp;
EOF
}
$dspace->{$code} = $value;
delete $dspace->{$code}
unless defined $value and $value;
return '';
}
EOR