[interchange-cvs] interchange - heins modified code/UserTag/weight.tag

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Thu Jul 10 19:23:00 EDT 2003


User:      heins
Date:      2003-07-10 22:23:46 GMT
Modified:  code/UserTag weight.tag
Log:
* Add ability to build weight adjustments based on Simple options
  settings. Requires a "weight" field in the options table.

Revision  Changes    Path
1.2       +53 -0     interchange/code/UserTag/weight.tag


rev 1.2, prev_rev 1.1
Index: weight.tag
===================================================================
RCS file: /var/cvs/interchange/code/UserTag/weight.tag,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- weight.tag	14 May 2003 15:38:40 -0000	1.1
+++ weight.tag	10 Jul 2003 22:23:46 -0000	1.2
@@ -17,6 +17,42 @@
 
 	my $field = $opt->{field} || 'weight';
 	my $table = $opt->{table};
+	my $osub;
+
+	if($opt->{options}) {
+	   BUILDO: {
+		 my $oattr = $Vend::Cfg->{OptionsAttribute}
+		 	or last BUILDO;
+		 my $odb = dbref($opt->{options_table} || 'options')
+		 	or last BUILDO;
+		 my $otab = $odb->name();
+		 my $q = qq{
+		 			SELECT o_group, weight FROM $otab
+					WHERE  sku = ?
+					AND    weight is not null
+					AND    weight != ''
+					};
+		 my $sth = $odb->dbh()->prepare($q)
+		 	or last BUILDO;
+		 if($oattr and $odb) {
+			 $osub = sub {
+				my $it = shift;
+				my $oweight = 0;
+				if($it->{$oattr} eq 'Simple') {
+					$sth->execute($it->{code});
+					while(my $ref = $sth->fetchrow_arrayref) {
+						my ($opt, $wtext) = @$ref;
+						next unless length($it->{$opt});
+						my $whash = get_option_hash($wtext);
+						next unless $whash;
+						$oweight += $whash->{$it->{$opt}};
+					}
+				}
+				return $oweight;
+			};
+		};
+	  }
+	}
 
 	if($attr) {
 		$attr = $opt->{field} || 'weight';
@@ -45,6 +81,8 @@
 	my $total = 0;
 	for(@$cart) {
 		$total += $_->{quantity} * $wsub->($_);
+		next unless $osub;
+		$total += $_->{quantity} * $osub->($_);
 	}
 	
 	unless($opt->{no_set}) {
@@ -116,6 +154,21 @@
 =item no-set
 
 Don't set the weight in scratch.
+
+=item options
+
+Scan the options table for applicable options and adjust weight
+accordingly. Only works for "Simple" type options set in the
+OptionsEnable attribute, and the o_group and weight fields must
+represent the option attribute and the weight text. The weight text is a
+normal Interchange option hash string type, i.e. 
+
+	titanium=-1.2, iron=1.5
+
+where "titanium" and "iron" are the values of an option
+setting like "blade".
+
+Will only work if your options table is SQL/DBI.
 
 =item table
 







More information about the interchange-cvs mailing list