[interchange-cvs] interchange - heins modified
code/UserTag/weight.tag
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Tue May 24 20:31:20 EDT 2005
User: heins
Date: 2005-05-25 00:31:20 GMT
Modified: code/UserTag weight.tag
Log:
* Add two new options to weight tag, exclude-attribute="attribute=regex"
and zero-unless-attribute="attribute=regex".
These are documented in the Documentation parameter -- short summary
is that zero-unless-attribute returns zero weight unless all items
match an attribute regular expression, and exclude-attribute makes
the weight of matching items zero.
Revision Changes Path
1.6 +99 -1 interchange/code/UserTag/weight.tag
rev 1.6, prev_rev 1.5
Index: weight.tag
===================================================================
RCS file: /var/cvs/interchange/code/UserTag/weight.tag,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- weight.tag 19 May 2005 01:07:24 -0000 1.5
+++ weight.tag 25 May 2005 00:31:20 -0000 1.6
@@ -1,10 +1,10 @@
# Copyright 2002 Interchange Development Group (http://www.icdevgroup.org/)
# Licensed under the GNU GPL v2. See file LICENSE for details.
-# $Id: weight.tag,v 1.5 2005/05/19 01:07:24 mheins Exp $
+# $Id: weight.tag,v 1.6 2005/05/25 00:31:20 mheins Exp $
UserTag weight Order attribute
UserTag weight addAttr
-UserTag weight Version $Revision: 1.5 $
+UserTag weight Version $Revision: 1.6 $
UserTag weight Routine <<EOR
sub {
my ($attr, $opt) = @_;
@@ -59,6 +59,50 @@
}
}
+ my $exclude;
+ my %exclude;
+ if(my $thing = $opt->{exclude_attribute}) {
+ eval {
+ if(ref($thing) eq 'HASH') {
+ for(keys %$thing) {
+ $exclude{$_} = qr{$thing->{$_}};
+ }
+ }
+ else {
+ my ($k, $v) = split /=/, $thing;
+ $exclude{$k} = qr{$v};
+ }
+ };
+ if($@) {
+ ::logError("Bad weight exclude option: %s", ::uneval($thing));
+ }
+ else {
+ $exclude = 1;
+ }
+ }
+
+ my $zero_unless;
+ my %zero_unless;
+ if(my $thing = $opt->{zero_unless_attribute}) {
+ eval {
+ if(ref($thing) eq 'HASH') {
+ for(keys %$thing) {
+ $zero_unless{$_} = qr{$thing->{$_}};
+ }
+ }
+ else {
+ my ($k, $v) = split /=/, $thing;
+ $zero_unless{$k} = qr{$v};
+ }
+ };
+ if($@) {
+ ::logError("Bad weight zero_unless option: %s", ::uneval($thing));
+ }
+ else {
+ $zero_unless = 1;
+ }
+ }
+
if($attr) {
$attr = $opt->{field} || 'weight';
$wsub = sub {
@@ -91,7 +135,20 @@
}
my $total = 0;
+ CARTCHECK:
for(@$cart) {
+ if($exclude) {
+ my $found;
+ for my $k (keys %exclude) {
+ $found = 1, last if $_->{$k} =~ $exclude{$k};
+ }
+ next if $found;
+ }
+ if($zero_unless) {
+ for my $k (keys %zero_unless) {
+ return 0 unless $_->{$k} =~ $zero_unless{$k};
+ }
+ }
next if $_->{mv_free_shipping} && ! $opt->{no_free_shipping};
$total += $_->{quantity} * $wsub->($_);
next unless $osub;
@@ -120,6 +177,8 @@
cart=cartname*
field=sh_weight*
fill-attribute=weight*
+ zero-unless-attribute="attribute=regex"
+ exclude-attribute="attribute=regex"
hide=1|0*
matrix=1
no-set=1|0*
@@ -155,6 +214,38 @@
The fieldname to use -- default "weight". This applies both to attribute
and database.
+=item exclude-attribute
+
+If an attribute I<already in the cart hash> matches the regex, it
+will not show up as weight. Can be a scalar or hash.
+
+ [weight exclude-attribute="prod_group=Gift Certificates"]
+
+and
+
+ [weight exclude-attribute.prod_group="Gift Certificates"]
+
+are identical, but with the second form you can do:
+
+ [weight
+ exclude-attribute.prod_group="Gift Certificates"
+ exclude-attribute.category="Downloads"
+ ]
+
+The value is a regular expression, so you can group with C<|>,
+or make case insensitive with:
+
+ [weight exclude-attribute.prod_group="(?i)certificate"]
+
+If the regular expression does not compile, an error is logged
+and no exclusion is done.
+
+It is IMPORTANT to note that you must have the attribute pre-filled
+for this to work -- no database accesses will be done. If you want
+to do this, use L<AutoModifier>, i.e. put in catalog.cfg:
+
+ AutoModifier prod_group
+
=item fill-attribute
Sets the attribute from the database the first time, and uses it thereafter.
@@ -198,6 +289,13 @@
=item weight-scratch
The scratch variable name to set -- default is "total_weight".
+
+=item zero-unless-attribute
+
+Same as C<exclude-attribute> except that a zero weight is returned
+unless B<all> items match the expression. This allows you to do
+something like only offer Book Rate shipping when all items have
+a prod_group of "Books".
=back
More information about the interchange-cvs
mailing list