[interchange-cvs] interchange - heins modified 3 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Sat Jul 6 03:14:03 2002
User: heins
Date: 2002-07-06 07:13:02 GMT
Modified: lib/Vend Cart.pm Config.pm Interpolate.pm
Log:
* Add experimental multi-level taxing/handling/shipping charge system
called "Levies".
Basics are pretty simple. The levies are in a cart stucture,
$Vend::Session->{levies}, and the levies cart is named the
same as the shopping cart.
Levies can (initially) be of one of four types:
-- Salestax. Uses the current salestax setup. This should rarely
be used.
-- Shipping. This uses the shipping-type calculation, but can
easily be used for taxing. Perhaps a better name is needed,
which is not....
-- Handling. Same as shipping above, but sort order in list
is lower.
-- Custom. A mapped routine defined by Sub or GlobalSub.
The levies to be checked are defined by a Config directive "Levies".
Each Levy must have a Levy structure (locale type). A very basic
one is:
Levies salestax shipping
Levy salestax description "Sales Tax (%s)"
Levy salestax keep_if_zero 1
Levy salestax type salestax
Levy salestax sort 002
Levy shipping keep_if_zero 0
Levy shipping type shipping
Levy shipping mode_variable mv_shipmode
Levy shipping mode USPS
That would emulate the current setup.
The levies can be displayed by means of
[levy-list]
<tr>
<td colspan=3D5>
[levy-description]
</td>
<td align=3Dright>
[levy-param cost]
</td>
</tr>
[/levy-list]
This is very, very, early in development. Questions about taxing
previous levy levels, etc, remain to be answered.
Revision Changes Path
2.5 +4 -4 interchange/lib/Vend/Cart.pm
rev 2.5, prev_rev 2.4
Index: Cart.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Cart.pm,v
retrieving revision 2.4
retrieving revision 2.5
diff -u -r2.4 -r2.5
--- Cart.pm 28 Jun 2002 05:00:25 -0000 2.4
+++ Cart.pm 6 Jul 2002 07:13:01 -0000 2.5
@@ -1,6 +1,6 @@
# Vend::Cart - Interchange shopping cart management routines
#
-# $Id: Cart.pm,v 2.4 2002/06/28 05:00:25 mheins Exp $
+# $Id: Cart.pm,v 2.5 2002/07/06 07:13:01 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -24,7 +24,7 @@
=20
package Vend::Cart;
=20
-$VERSION =3D substr(q$Revision: 2.4 $, 10);
+$VERSION =3D substr(q$Revision: 2.5 $, 10);
=20
use strict;
=20
@@ -212,7 +212,6 @@
last DELETE;
}
=20
- return 1 unless @master;
my $mi;
my %save;
my @items;
@@ -239,7 +238,8 @@
@{$s} =3D @items[sort {$a <=3D> $b} keys %save];
}
}
- 1;
+ Vend::Interpolate::levies();
+ return 1;
}
=20
=3Dhead2 Test footer for item toss
2.52 +14 -9 interchange/lib/Vend/Config.pm
rev 2.52, prev_rev 2.51
Index: Config.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Config.pm,v
retrieving revision 2.51
retrieving revision 2.52
diff -u -r2.51 -r2.52
--- Config.pm 28 Jun 2002 05:06:05 -0000 2.51
+++ Config.pm 6 Jul 2002 07:13:01 -0000 2.52
@@ -1,6 +1,6 @@
# Vend::Config - Configure Interchange
#
-# $Id: Config.pm,v 2.51 2002/06/28 05:06:05 mheins Exp $
+# $Id: Config.pm,v 2.52 2002/07/06 07:13:01 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -44,7 +44,7 @@
use Vend::Parse;
use Vend::Util;
=20
-$VERSION =3D substr(q$Revision: 2.51 $, 10);
+$VERSION =3D substr(q$Revision: 2.52 $, 10);
=20
my %CDname;
=20
@@ -60,6 +60,7 @@
PriceField
PriceDefault
SalesTax
+ Levies
TaxShipping
=20
/ );
@@ -84,32 +85,33 @@
=20
@Locale_directives_scalar =3D (
qw/
- Autoload
AutoEnd
- CommonAdjust
+ Autoload
CategoryField
+ CommonAdjust
DescriptionField
+ HTMLsuffix
ImageDir
ImageDirSecure
PageDir
- SpecialPageDir
- PriceDivide
PriceCommas
- PriceField
PriceDefault
+ PriceDivide
+ PriceField
SalesTax
+ SpecialPageDir
StaticPath
- HTMLsuffix
TaxShipping
=20
/ );
=20
@Locale_directives_ary =3D (
qw/
+ AutoModifier
+ Levies
PriceAdjustment
ProductFiles
UseModifier
- AutoModifier
/ );
=20
# These are extra routines that are run if certain directives are
@@ -129,6 +131,7 @@
Mail 1
DatabaseDefault 1
Accounting 1
+ Levy 1
));
=20
my %DumpSource =3D (qw(
@@ -488,6 +491,8 @@
['PriceField', undef, 'price'],
['Shipping', 'locale', ''],
['Accounting', 'locale', ''],
+ ['Levies', 'array', ''],
+ ['Levy', 'locale', ''],
['AutoVariable', 'autovar', ''],
=20
];
2.81 +104 -4 interchange/lib/Vend/Interpolate.pm
rev 2.81, prev_rev 2.80
Index: Interpolate.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.80
retrieving revision 2.81
diff -u -r2.80 -r2.81
--- Interpolate.pm 4 Jul 2002 21:31:20 -0000 2.80
+++ Interpolate.pm 6 Jul 2002 07:13:01 -0000 2.81
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#=20
-# $Id: Interpolate.pm,v 2.80 2002/07/04 21:31:20 mheins Exp $
+# $Id: Interpolate.pm,v 2.81 2002/07/06 07:13:01 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA =3D qw(Exporter);
=20
-$VERSION =3D substr(q$Revision: 2.80 $, 10);
+$VERSION =3D substr(q$Revision: 2.81 $, 10);
=20
@EXPORT =3D qw (
=20
@@ -3124,8 +3124,8 @@
my $mode =3D shift;
$CacheInvalid =3D 1 unless $mode;
$mode =3D $mode || $::Values->{mv_shipmode} || 'default';
- return '' unless defined $Vend::Cfg->{Shipping_desc}->{$mode};
- $Vend::Cfg->{Shipping_desc}->{$mode};
+ return '' unless defined $Vend::Cfg->{Shipping_desc}{$mode};
+ return $Vend::Cfg->{Shipping_desc}{$mode};
}
=20
sub tag_calc {
@@ -6281,6 +6281,7 @@
tag_cart($cart);
}
=20
+#::logDebug("salestax entered, cart=3D$cart");
my $tax_hash;
my $cost;
if($Vend::Cfg->{SalesTax} eq 'multi') {
@@ -6422,6 +6423,11 @@
=20
$total =3D 0;
=20
+ if($Vend::Cfg->{Levies}) {
+ $total =3D subtotal();
+ $total +=3D levies();
+ }
+ else {
my $shipping =3D 0;
$shipping +=3D tag_shipping()
if $::Values->{mv_shipmode};
@@ -6431,6 +6437,7 @@
$total +=3D $shipping;
$total +=3D salestax();
=20
+ }
$Vend::Items =3D $save if defined $save;
$Vend::Session->{latest_total} =3D $total;
return $total;
@@ -6527,4 +6534,97 @@
return $cost;
}
=20
+sub levies {
+ my($set, $opt) =3D @_;
+ my $levies;
+#::logDebug("Calling levies");
+ return unless $levies =3D $Vend::Cfg->{Levies};
+ my $repos =3D $Vend::Cfg->{Levy_repository};
+ if(! $repos) {
+ logOnce('error', "Levies set but no levies defined! No tax or shipping."=
);
+ return;
+ }
+ $Vend::Levying =3D 1;
+ $set ||=3D $Vend::CurrentCart;
+ $set ||=3D 'main';
+
+ $Vend::Session->{levies} ||=3D {};
+ my $lcart =3D $Vend::Session->{levies}{$set} =3D [];
+=09
+ my $run =3D 0;
+ for my $name (@$levies) {
+ my $l =3D $repos->{$name};
+#::logDebug("Levying $name, repos =3D> " . uneval($l));
+ if(! $l) {
+ logOnce('error', "Levy '%s' called but not defined. Skipping.", $name);
+ next;
+ }
+ my $type =3D $l->{type} || ($name eq 'salestax' ? 'salestax' : 'shipping=
');
+ my $mode =3D $l->{mode} || $name;
+ my $cost =3D 0;
+ my $sort;
+ my $desc;
+ if($type eq 'salestax') {
+ my $save;
+ $sort =3D $l->{sort} || '010';
+ if($l->{tax_fields}) {
+ $save =3D $Vend::Cfg->{SalesTax};
+ $Vend::Cfg->{SalesTax} =3D $l->{tax_fields};
+ }
+ $cost =3D salestax();
+ $desc =3D errmsg(
+ $l->{description} || 'Sales Tax',
+ $::Values->{$Vend::Cfg->{SalesTax}},
+ );
+ $Vend::Cfg->{SalesTax} =3D $save if defined $save;
+ }
+ elsif ($type eq 'shipping' or $type eq 'handling') {
+ if(not $sort =3D $l->{sort}) {
+ $sort =3D $type eq 'handling' ? 100 : 500;
+ }
+ $cost =3D shipping($mode);
+ $desc =3D $l->{description} || shipping_desc($mode);
+ }
+ elsif($type eq 'custom') {
+ my $sub;
+ SUBFIND: {
+ $sub =3D $Vend::Cfg->{Sub}{$mode} || $Global::GlobalSub->{$mode}
+ and last SUBFIND;
+ eval {
+ $sub =3D $Vend::Cfg->{UserTag}{Routine}{$mode};
+ };
+ last SUBFIND if ! $@ and $sub;
+ eval {
+ $sub =3D $Global::UserTag->{Routine}{$mode};
+ };
+ }
+ if( ref($sub) ne 'CODE') {
+ ($cost, $desc, $sort) =3D $sub->($opt);
+ }
+ else {
+ logError("No subroutine found for custom levy '%s'", $name);
+ }
+ }
+ my $item =3D {
+ code =3D> $name,
+ mode =3D> $mode,
+ sort =3D> $sort,
+ cost =3D> $cost,
+ description =3D> $desc,
+ };
+ if($cost =3D=3D 0) {
+ next unless $l->{keep_if_zero};
+ $item->{free} =3D 1;
+ $item->{free_message} =3D $l->{free_message} || $cost;
+ }
+ push @$lcart, $item;
+ }
+ @$lcart =3D sort { $a->{sort} cmp $b->{sort} } @$lcart;
+
+ for(@$lcart) {
+ $run +=3D $_->{cost};
+ }
+ $run =3D round_to_frac_digits($run);
+ return $run;
+}
1;