[interchange] Add nodiscount attribute to [subtotal] tag.
Stefan Hornburg <[email protected]>
| Newsgroups | gmane.comp.web.interchange.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit d9e23173c07ec86550db9d7a610eebe0ae8b4f84 Author: Stefan Hornburg (Racke) <[email protected]> Date: Wed Jul 21 10:19:21 2010 +0200 Add nodiscount attribute to [subtotal] tag. code/SystemTag/subtotal.coretag | 2 +- lib/Vend/Interpolate.pm | 66 ++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 30 deletions(-) --- diff --git a/code/SystemTag/subtotal.coretag b/code/SystemTag/subtotal.coretag index 2b87f89..54d38f0 100644 --- a/code/SystemTag/subtotal.coretag +++ b/code/SystemTag/subtotal.coretag @@ -16,7 +16,7 @@ UserTag subtotal Version $Revision: 1.7 $ UserTag subtotal Routine <<EOR sub { my($cart, $noformat, $opt) = @_; - return currency( subtotal($cart, $opt->{discount_space}), + return currency( subtotal($cart, $opt->{discount_space}, $opt->{nodiscount}), $noformat, undef, $opt); } EOR diff --git a/lib/Vend/Interpolate.pm b/lib/Vend/Interpolate.pm index 9cdf751..4462632 100644 --- a/lib/Vend/Interpolate.pm +++ b/lib/Vend/Interpolate.pm @@ -5730,7 +5730,7 @@ sub salestax { # Returns just subtotal of items ordered, with discounts # applied sub subtotal { - my($cart, $dspace) = @_; + my($cart, $dspace, $nodiscount) = @_; ### If the user has assigned to salestax, ### we use their value come what may, no rounding @@ -5747,42 +5747,50 @@ sub subtotal { } levies() unless $Vend::Levying; - - # Use switch_discount_space unconditionally to guarantee existance of proper discount structures. - $oldspace = switch_discount_space($dspace || $Vend::DiscountSpaceName); - - my $discount = (ref($::Discounts) eq 'HASH' and %$::Discounts); - $subtotal = 0; - - foreach $i (0 .. $#$Vend::Items) { - $item = $Vend::Items->[$i]; - if($discount || $item->{mv_discount}) { - $subtotal += apply_discount($item); - } - else { - $subtotal += Vend::Data::item_subtotal($item); - } + $subtotal = 0; + + if ($nodiscount) { + foreach $i (0 .. $#$Vend::Items) { + $item = $Vend::Items->[$i]; + $subtotal += Vend::Data::item_subtotal($item); + } } + else { + # Use switch_discount_space unconditionally to guarantee existance of proper discount structures. + $oldspace = switch_discount_space($dspace || $Vend::DiscountSpaceName); + + my $discount = (ref($::Discounts) eq 'HASH' and %$::Discounts); + + foreach $i (0 .. $#$Vend::Items) { + $item = $Vend::Items->[$i]; + if ($discount || $item->{mv_discount}) { + $subtotal += apply_discount($item); + } else { + $subtotal += Vend::Data::item_subtotal($item); + } + } - if (defined $::Discounts->{ENTIRE_ORDER}) { - $formula = $::Discounts->{ENTIRE_ORDER}; - $formula =~ s/\$q\b/tag_nitems()/eg; - $formula =~ s/\$s\b/$subtotal/g; - $cost = $Vend::Interpolate::ready_safe->reval($formula); - if($@) { - logError - "Discount ENTIRE_ORDER has bad formula. Returning normal subtotal.\n$@"; - $cost = $subtotal; + if (defined $::Discounts->{ENTIRE_ORDER}) { + $formula = $::Discounts->{ENTIRE_ORDER}; + $formula =~ s/\$q\b/tag_nitems()/eg; + $formula =~ s/\$s\b/$subtotal/g; + $cost = $Vend::Interpolate::ready_safe->reval($formula); + if ($@) { + logError + "Discount ENTIRE_ORDER has bad formula. Returning normal subtotal.\n$@"; + $cost = $subtotal; + } + $subtotal = $cost; } - $subtotal = $cost; + + # Switch to original discount space if an actual switch occured. + switch_discount_space($oldspace) if $dspace and defined $oldspace; } + $Vend::Items = $save if defined $save; $Vend::Session->{latest_subtotal} = $subtotal; - # Switch to original discount space if an actual switch occured. - switch_discount_space($oldspace) if $dspace and defined $oldspace; - return $subtotal; }