[interchange-cvs] interchange - heins modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Mon Jun 25 12:26:43 EDT 2007


User:      heins
Date:      2007-06-25 16:26:43 GMT
Modified:  lib/Vend Ship.pm
Modified:  code/SystemTag shipping_desc.coretag
Log:
* Change [shipping-desc] to allow access to arbitrary keys in the shipping
  configuration.

* Adds key parameter so that you can access any member of the initial shipping
  hash for a mode. You can see things like zone, aggregate, adder, etc. as
  well as any arbitrary keys you set.

* Allows something like:

	usps: USPS 1st class
		crit        [onlyitems]
        min         0
        max         0
        cost        e No shipping needed!
        at_least    0
        adder       0
        p_time      1-2 business days
        s_time      3-7 business days
        foo         bar

        min         1
        max         6
        cost        4.00

        min         7
        max         12
        cost        7.00

        [loop list="[shipping possible=1]"]
                Shipping Mode:   [shipping-desc mode="[loop-code]"]
                Processing time: [shipping-desc mode="[loop-code]" key=p_time]
                Shipping time:   [shipping-desc mode="[loop-code]" key=s_time]
                Cost:            [shipping mode="[loop-code]"]
        [/loop]

* Thanks to Paul Jordan for suggesting and supporting this!

Revision  Changes    Path
2.22      +54 -15    interchange/lib/Vend/Ship.pm


rev 2.22, prev_rev 2.21
Index: Ship.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Ship.pm,v
retrieving revision 2.21
retrieving revision 2.22
diff -u -r2.21 -r2.22
--- Ship.pm	30 Mar 2007 11:39:46 -0000	2.21
+++ Ship.pm	25 Jun 2007 16:26:43 -0000	2.22
@@ -1,6 +1,6 @@
 # Vend::Ship - Interchange shipping code
 # 
-# $Id: Ship.pm,v 2.21 2007/03/30 11:39:46 pajamian Exp $
+# $Id: Ship.pm,v 2.22 2007/06/25 16:26:43 mheins Exp $
 #
 # Copyright (C) 2002-2005 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -97,6 +97,30 @@
 		,
 );
 
+sub process_new_beginning {
+	my ($record, $line) = @_;
+	my @new;
+
+	if($line =~ /^[^\s:]+\t/) {
+		@new = split /\t/, $line;
+	}
+	elsif($line =~ /^(\w+)\s*:\s*(.*)/s) {
+		@new = ($1, $2, 'quantity', 0, 99999999, 0);
+	}
+
+	$Vend::Cfg->{Shipping_desc}{$new[MODE]} ||= $new[DESC];
+
+	my $old_mode = $record->[MODE];
+	if ($old_mode and ! $Vend::Cfg->{Shipping_hash}{$old_mode}) {
+		if(! ref($record->[OPT]) ) {
+			$record->[OPT] = string_to_ref($record->[OPT]);
+		}
+		$record->[OPT]{description} ||= $Vend::Cfg->{Shipping_desc}{$old_mode};
+		$Vend::Cfg->{Shipping_hash}{$old_mode} = $record->[OPT];
+	}
+	return @new;
+}
+
 sub read_shipping {
 	my ($file, $opt) = @_;
 	$opt = {} unless $opt;
@@ -167,8 +191,8 @@
 		}
 	}
 	
-	$Vend::Cfg->{Shipping_desc} = {}
-		if ! $Vend::Cfg->{Shipping_desc};
+	$Vend::Cfg->{Shipping_desc} ||= {};
+
 	my %seen;
 	my $append = '00000';
 	my @line;
@@ -211,20 +235,35 @@
 
 		next if ! /\S/ or /^\s*#/;
 		s/\s+$//;
-		if(/^[^\s:]+\t/) {
+
+		if(/^[^\s:]+\t/ or /^\w+\s*:/s) {
+			## This along with process_new_beginning replaces
+			## two previous branches that had same code doing
+			## same thing.
+
+			my @new = process_new_beginning(\@line, $_);
 			push (@shipping, [@line]) if @line;
-			@line = split(/\t/, $_);
-			$Vend::Cfg->{Shipping_desc}->{$line[0]} = $line[1]
-				unless $seen{$line[0]}++;
-			push @shipping, [@line];
-			@line = ();
+			@line = @new;
 		}
 		elsif(/^(\w+)\s*:\s*(.*)/s) {
-			push (@shipping, [@line]) if @line;
-			@line = ($1, $2, 'quantity', 0, 999999999, 0);
+			my $id = $1;
+			my $desc = $2;
+			my ($opt, $former);
+
+			if(@line) {
+				push (@shipping, [@line]);
+				$opt = $line[OPT];
+				$former = $line[MODE];
+			}
+
+			@line = ($id, $desc, 'quantity', 0, 999999999, 0);
 			$first = 1;
-			$Vend::Cfg->{Shipping_desc}->{$line[0]} = $line[1]
-				unless $seen{$line[0]}++;
+			if( $seen{$line[MODE]}++ ) {
+				$Vend::Cfg->{Shipping_hash}{$former} ||= $opt;
+			}
+			else {
+				$Vend::Cfg->{Shipping_desc}->{$line[MODE]} = $line[DESC];
+			}
 			next;
 		}
 		elsif(/^\s+min(?:imum)?\s+(\S+)/i) {
@@ -1231,9 +1270,9 @@
 
 sub tag_shipping_desc {
 	my $mode = 	shift;
+	my $key = shift || 'description';
 	$mode = $mode || $::Values->{mv_shipmode} || 'default';
-	return '' unless defined $Vend::Cfg->{Shipping_desc}{$mode};
-	return errmsg($Vend::Cfg->{Shipping_desc}{$mode});
+	return errmsg($Vend::Cfg->{Shipping_hash}{$mode}{$key});
 }
 
 =head1 NAME



1.5       +3 -4      interchange/code/SystemTag/shipping_desc.coretag


rev 1.5, prev_rev 1.4
Index: shipping_desc.coretag
===================================================================
RCS file: /var/cvs/interchange/code/SystemTag/shipping_desc.coretag,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- shipping_desc.coretag	30 Mar 2007 23:40:49 -0000	1.4
+++ shipping_desc.coretag	25 Jun 2007 16:26:43 -0000	1.5
@@ -5,9 +5,8 @@
 # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  See the LICENSE file for details.
 # 
-# $Id: shipping_desc.coretag,v 1.4 2007/03/30 23:40:49 pajamian Exp $
+# $Id: shipping_desc.coretag,v 1.5 2007/06/25 16:26:43 mheins Exp $
 
-UserTag shipping-desc       Order        mode
-UserTag shipping-desc       PosNumber    1
-UserTag shipping-desc       Version      $Revision: 1.4 $
+UserTag shipping-desc       Order        mode key
+UserTag shipping-desc       Version      $Revision: 1.5 $
 UserTag shipping-desc       MapRoutine   Vend::Ship::tag_shipping_desc








More information about the interchange-cvs mailing list