[interchange-cvs] interchange - jon modified lib/Vend/Order.pm
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Thu Apr 25 13:08:01 2002
User: jon
Date: 2002-04-25 17:07:58 GMT
Modified: lib/Vend Order.pm
Log:
A couple of changes to order profiles:
* Fix bug that kept &calc, &return, etc. from ever failing (because no
variable name was associated with them). This appears to have been
broken since the Minivend days, so that there was no difference
between these two:
&calc=$Scratch->{blahblah} = "something"; return 1;
and
&calc=$Scratch->{blahblah} = "something"; return 0;
This should really go into the stable branch at some point.
* Make order profiles stackable:
<input type=hidden name=mv_form_profile value=check_profile_first>
<input type=hidden name=mv_form_profile value=check_profile_second>
First one to fail, fails the whole check.
Revision Changes Path
2.17 +70 -52 interchange/lib/Vend/Order.pm
rev 2.17, prev_rev 2.16
Index: Order.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Order.pm,v
retrieving revision 2.16
retrieving revision 2.17
diff -u -u -r2.16 -r2.17
--- Order.pm 5 Feb 2002 20:57:04 -0000 2.16
+++ Order.pm 25 Apr 2002 17:07:58 -0000 2.17
@@ -1,6 +1,6 @@
# Vend::Order - Interchange order routing routines
#
-# $Id: Order.pm,v 2.16 2002/02/05 20:57:04 mheins Exp $
+# $Id: Order.pm,v 2.17 2002/04/25 17:07:58 jon Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -28,7 +28,7 @@
package Vend::Order;
require Exporter;
-$VERSION = substr(q$Revision: 2.16 $, 10);
+$VERSION = substr(q$Revision: 2.17 $, 10);
@ISA = qw(Exporter);
@@ -849,12 +849,52 @@
);
return undef;
}
+#::logDebug("&Vend::Order::do_check returning \$val $val, \$var $var, \$message $message");
return ($val, $var, $message);
}
sub check_order {
+ my ($profiles, $vref) = @_;
+ my @profiles = split /\0+/, $profiles;
+ my $status;
+ @Errors = ();
+ $Vend::Session->{errors} = {}
+ unless ref $Vend::Session->{errors} eq 'HASH';
+
+ for my $profile (@profiles) {
+
+ $status = check_order_each($profile, $vref);
+
+ if ($status) {
+ $CGI::values{mv_nextpage} = $Success_page
+ if $Success_page;
+ }
+ elsif ($Fail_page) {
+ $CGI::values{mv_nextpage} = $Fail_page;
+ }
+ if ($Final and ! scalar @{$Vend::Items}) {
+ $status = 0;
+ $::Values->{"mv_error_items"} =
+ $Vend::Session->{errors}{items} =
+ errmsg(
+ "You might want to order something! No items in cart.",
+ );
+ }
+::logDebug("FINISH checking profile $profile: Fatal=$Fatal Final=$Final Status=$status");
+
+ # first profile to fail prevents all other profiles from running
+ last unless $status;
+
+ }
+
+ my $errors = join "\n", @Errors;
+::logDebug("Errors after checking profile(s) " . join(", ", @profiles) . ":\n" . $errors);
+ $errors = '' unless defined $errors and ! $Success;
+ return ($status, $Final, $errors);
+}
+
+sub check_order_each {
my ($profile, $vref) = @_;
- my($codere) = '[-\w_#/.]+';
my $params;
$Profile = $profile;
if(defined $Vend::Cfg->{OrderProfileName}->{$profile}) {
@@ -873,11 +913,9 @@
}
return undef unless $params;
- my $ref = \%CGI::values;
$params = interpolate_html($params);
$params =~ s/\\\n//g;
- @Errors = ();
$And = 1;
$Fatal = $Final = 0;
@@ -921,7 +959,6 @@
s/^\s+//;
s/\s+$//;
($val, $var, $message) = do_check($_, $vref);
- next if ! defined $var;
if(defined $And) {
if($And) {
$val = ($last_one && $val);
@@ -932,36 +969,36 @@
undef $And;
}
$last_one = $val;
- if ($val) {
- $::Values->{"mv_status_$var"} = $message
- if defined $message and $message;
- delete $Vend::Session->{errors}{$var};
- delete $::Values->{"mv_error_$var"};
- }
- else {
- $status = 0;
+ $status = 0 unless $val;
+ if ($var) {
+ if ($val) {
+ $::Values->{"mv_status_$var"} = $message
+ if defined $message and $message;
+ delete $Vend::Session->{errors}{$var};
+ delete $::Values->{"mv_error_$var"};
+ }
+ else {
# LEGACY
- $::Values->{"mv_error_$var"} = $message;
+ $::Values->{"mv_error_$var"} = $message;
# END LEGACY
- $Vend::Session->{errors} = {}
- if ! $Vend::Session->{errors};
- if( $No_error ) {
- # do nothing
- }
- elsif( $Vend::Session->{errors}{$var} ) {
- if ($message and $Vend::Session->{errors}{$var} !~ /\Q$message/) {
- $Vend::Session->{errors}{$var} = errmsg(
- '%s and %s',
- $Vend::Session->{errors}{$var},
- $message
- );
+ if( $No_error ) {
+ # do nothing
}
+ elsif( $Vend::Session->{errors}{$var} ) {
+ if ($message and $Vend::Session->{errors}{$var} !~ /\Q$message/) {
+ $Vend::Session->{errors}{$var} = errmsg(
+ '%s and %s',
+ $Vend::Session->{errors}{$var},
+ $message
+ );
+ }
+ }
+ else {
+ $Vend::Session->{errors}{$var} = $message ||
+ errmsg('%s: failed check', $var);
+ }
+ push @Errors, "$var: $message";
}
- else {
- $Vend::Session->{errors}{$var} = $message ||
- errmsg('%s: failed check', $var);
- }
- push @Errors, "$var: $message";
}
if (defined $Success) {
$status = $Success;
@@ -969,26 +1006,7 @@
}
last if $Fatal && ! $status;
}
- my $errors = join "\n", @Errors;
- $errors = '' unless defined $errors and ! $Success;
-#::logDebug("FINISH checking profile $Profile: Fatal=$Fatal Final=$Final Status=$status\nErrors:\n$errors\n");
- if($status) {
- $CGI::values{mv_nextpage} = $Success_page
- if $Success_page;
- }
- elsif ($Fail_page) {
- $CGI::values{mv_nextpage} = $Fail_page;
- }
- if($Final and ! scalar @{$Vend::Items}) {
- $status = 0;
- $::Values->{"mv_error_items"} =
- $Vend::Session->{errors}{items} =
- errmsg(
- "You might want to order something! No items in cart.",
- );
-
- }
- return ($status, $Final, $errors);
+ return $status;
}
my $state = <<EOF;