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

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Mon Apr 28 11:24:01 2003


User:      heins
Date:      2003-04-28 15:23:37 GMT
Modified:  lib/Vend Interpolate.pm
Log:
* Allow redirection of shipping modes; I had intended to do this a long time
  ago but I think the project that needed it got axed.

  Basically, you can do:

  upsg_or_free	UPS Ground	[subtotal noformat=1]	0	99.99	>>upsg
  upsg_or_free	UPS Ground	price	100	99999	0		{ free => 'Free!' }

  upsg	UPS Ground	weight	0	150	u Ground

  The first mode redirects to the second one if the order total is
  less that $100; if it is more, it gives free shipping.

* Add [shipping widget="Vend::Form widget" mode="mode1 mode2"] to
  automatically build widget with Vend::Form. Works just like
  [shipping label=1 ...] but produces a complete widget.

Revision  Changes    Path
2.159     +39 -7     interchange/lib/Vend/Interpolate.pm


rev 2.159, prev_rev 2.158
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.158
retrieving revision 2.159
diff -u -r2.158 -r2.159
--- Interpolate.pm	24 Apr 2003 16:06:35 -0000	2.158
+++ Interpolate.pm	28 Apr 2003 15:23:36 -0000	2.159
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.158 2003/04/24 16:06:35 jon Exp $
+# $Id: Interpolate.pm,v 2.159 2003/04/28 15:23:36 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.158 $, 10);
+$VERSION = substr(q$Revision: 2.159 $, 10);
 
 @EXPORT = qw (
 
@@ -2926,7 +2926,7 @@
 	my $mode = 	shift;
 	$mode = $mode || $::Values->{mv_shipmode} || 'default';
 	return '' unless defined $Vend::Cfg->{Shipping_desc}{$mode};
-	return $Vend::Cfg->{Shipping_desc}{$mode};
+	return errmsg($Vend::Cfg->{Shipping_desc}{$mode});
 }
 
 sub tag_calc {
@@ -5915,6 +5915,10 @@
 			$final += $cost;
 			last SHIPIT unless $o->{continue};
 		}
+		elsif ($what =~ /^>>(\w+)/) {
+			my $newmode = $1;
+			return shipping($newmode, $opt);
+		}
 		elsif ($what eq 'x') {
 			$final += ($o->{multiplier} * $total);
 			last SHIPIT unless $o->{continue};
@@ -6032,7 +6036,8 @@
 		return $final unless $opt->{label};
 		my $number;
 		if($o->{free} and $final == 0) {
-			$number = $opt->{free};
+			$number = $opt->{free} || $o->{free};
+#::logDebug("This is free, mode=$mode number=$number");
 		}
 		else {
 			return $final unless $opt->{label};
@@ -6042,6 +6047,9 @@
 											$opt->{noformat},
 									);
 		}
+
+		$opt->{format} ||= '%M=%D (%F)' if $opt->{output_options};
+		
 		my $label = $opt->{format} || '<OPTION VALUE="%M"%S>%D (%F)';
 		my $sel = $::Values->{mv_shipmode} eq $mode;
 #::logDebug("label start: $label");
@@ -6061,6 +6069,14 @@
 						e => $error_message,
 						Q => $qual,
 					);
+#::logDebug("labeling, subst=" . ::uneval(\%subst));
+		$subst{D} = errmsg($subst{D});
+		if($opt->{output_options}) {
+			for(qw/ D E F f /) {
+				next unless $subst{$_};
+				$subst{$_} =~ s/,/&#44;/g;
+			}
+		}
 		$label =~ s/(%(.))/exists $subst{$2} ? $subst{$2} : $1/eg;
 #::logDebug("label intermediate: $label");
 		$label =~ s/(\$O{(.*?)})/$o->{$2}/eg;
@@ -6161,10 +6177,26 @@
 		undef $opt->{default}
 			if tag_shipping($::Values->{mv_shipmode});
 	}
-	if($opt->{label}) {
-		$out = '';
+	if($opt->{label} || $opt->{widget}) {
+		my @out;
+		if($opt->{widget}) {
+			$opt->{label} = 1;
+			$opt->{output_options} = 1;
+		}
 		for(@modes) {
-			$out .= shipping($_, $opt);
+			push @out, shipping($_, $opt);
+		}
+		@out = grep /=.+/, @out;
+		if($opt->{widget}) {
+			my $o = { %$opt };
+			$o->{type} = delete $o->{widget};
+			$o->{passed} = join ",", @out;
+			$o->{name} ||= 'mv_shipmode';
+			$o->{default} ||= $::Values->{mv_shipmode};
+			$out = Vend::Form::display($o);
+		}
+		else {
+			join "", @out;
 		}
 	}
 	else {