[interchange-cvs] interchange - heins modified lib/Vend/Cart.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Thu Jul 18 15:09:00 2002


User:      heins
Date:      2002-07-18 19:08:10 GMT
Modified:  lib/Vend Cart.pm
Log:
* Add support for slaving Levies cart to current shopping cart.

* Do a better job of finding the cart name when it is not known.

Revision  Changes    Path
2.7       +41 -4     interchange/lib/Vend/Cart.pm


rev 2.7, prev_rev 2.6
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.6
retrieving revision 2.7
diff -u -r2.6 -r2.7
--- Cart.pm	7 Jul 2002 04:02:27 -0000	2.6
+++ Cart.pm	18 Jul 2002 19:08:10 -0000	2.7
@@ -1,6 +1,6 @@
 # Vend::Cart - Interchange shopping cart management routines
 #
-# $Id: Cart.pm,v 2.6 2002/07/07 04:02:27 mheins Exp $
+# $Id: Cart.pm,v 2.7 2002/07/18 19:08:10 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -24,27 +24,64 @@
=20
 package Vend::Cart;
=20
-$VERSION =3D substr(q$Revision: 2.6 $, 10);
+$VERSION =3D substr(q$Revision: 2.7 $, 10);
=20
 use strict;
=20
 sub TIESCALAR {
 	my $class =3D shift;
 	my $instance =3D shift || undef;
+	$Vend::CurrentCart =3D 'main';
+	$::Levies =3D $Vend::Session->{levies}{main} ||=3D [];
 	return bless \$instance =3D> $class;
 }
=20
 sub FETCH {
-	return scalar ($::Carts->{$Vend::CurrentCart || 'main'} ||=3D []);
+	my $cartname =3D $Vend::CurrentCart;
+	$::Levies =3D $Vend::Session->{levies}{$cartname} ||=3D [];
+	return scalar ($::Carts->{$cartname} ||=3D []);
 }
=20
 sub STORE {
 	my ($self, $cart) =3D @_;
 	my $name;
-	if(ref $cart) {
+	if( ref($cart) eq 'ARRAY' ) {
 		for(keys %$::Carts) {
+#::logDebug("checking name $_ via ref comparison");
 			$name =3D $_ if $::Carts->{$_} eq $cart;
 		}
+
+		if (! $name) {
+			$name =3D $cart->[0]{mv_cartname} if $cart->[0]{mv_cartname};
+		}
+
+		if (! $name) {
+			for my $pname (keys %$::Carts) {
+#::logDebug("checking name $pname via line comparison");
+				my $pros =3D $::Carts->{$pname};
+				next if ref($pros) ne 'ARRAY';
+				next if @$pros !=3D @$cart;
+				CHECKLINES: {
+					for( my $i =3D 0; $i < @$pros; $i++ ) {
+						my $p =3D $pros->[$i];
+						my $c =3D $cart->[$i];
+						my @k1 =3D keys %$p;
+						my @k2 =3D keys %$c;
+						last CHECKLINES if @k1 !=3D @k2;
+						foreach my $k (@k1) {
+							last CHECKLINES
+								unless exists $c->{$k};
+							last CHECKLINES
+								unless $c->{$k} eq $p->{$k};
+						}
+					}
+#::logDebug("found name $pname via line comparison");
+					$name =3D $pname;
+				}
+				last if $name;
+			}
+		}
+
 		if (! $name) {
 			$name =3D 'UNKNOWN';
 			$::Carts->{UNKNOWN} =3D $cart;