[interchange-cvs] interchange - heins modified 2 files
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Thu Apr 16 14:51:42 UTC 2009
User: heins
Date: 2009-04-16 14:51:42 GMT
Modified: lib/Vend Cart.pm Order.pm
Log:
* Add ability to recalculate AutoModifier values based on a sku change.
Specifying a ! (exclamation point) before the AutoModifier callout
indicates the attribute should be reloaded when the cart is "tossed".
To give an example from the standard demo, when you initially order a
Matrix option item, it pulls AutoModifier attributes based on anything
from a base sku to a certain variant. When you next change the options
on the item, the code (if not the base sku) changes. If the attribute
is different for that product code, then the attribute may no longer
pertain.
This change moves the AutoModifier load to a separate routine
called only if AutoModifier is used, and the recalculation routine
is only done if recalculating attributes are specified.
Example:
!download pricing:price_group
The price_group attribute will not be reloaded on cart toss, but the
download attribute will (and will come from whatever the mv_ib of
the item is).
TODO: Allow specification of attributes that should always be loaded
based on mv_sku if present.
Revision Changes Path
2.25 interchange/lib/Vend/Cart.pm
rev 2.25, prev_rev 2.24
Index: Cart.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Cart.pm,v
retrieving revision 2.24
retrieving revision 2.25
diff -u -r2.24 -r2.25
--- Cart.pm 26 Jun 2008 08:45:08 -0000 2.24
+++ Cart.pm 16 Apr 2009 14:51:41 -0000 2.25
@@ -1,6 +1,6 @@
# Vend::Cart - Interchange shopping cart management routines
#
-# $Id: Cart.pm,v 2.24 2008-06-26 08:45:08 docelic Exp $
+# $Id: Cart.pm,v 2.25 2009-04-16 14:51:41 mheins Exp $
#
# Copyright (C) 2002-2008 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -25,7 +25,7 @@
package Vend::Cart;
-$VERSION = substr(q$Revision: 2.24 $, 10);
+$VERSION = substr(q$Revision: 2.25 $, 10);
use strict;
@@ -297,6 +297,12 @@
}
}
+ for(@{$Vend::Cfg->{AutoModifier}}) {
+ next unless /^!/;
+ # Second passed parameter indicates it is recalculation not initial load
+ Vend::Order::auto_modifier($item, 1);
+ }
+
$total_quantity{$item->{code}} += $item->{quantity};
next unless $::Limit->{cart_quantity_per_line}
2.108 interchange/lib/Vend/Order.pm
rev 2.108, prev_rev 2.107
Index: Order.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Order.pm,v
retrieving revision 2.107
retrieving revision 2.108
diff -u -r2.107 -r2.108
--- Order.pm 16 Mar 2009 19:34:00 -0000 2.107
+++ Order.pm 16 Apr 2009 14:51:41 -0000 2.108
@@ -1,6 +1,6 @@
# Vend::Order - Interchange order routing routines
#
-# $Id: Order.pm,v 2.107 2009-03-16 19:34:00 jon Exp $
+# $Id: Order.pm,v 2.108 2009-04-16 14:51:41 mheins Exp $
#
# Copyright (C) 2002-2009 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
@@ -26,7 +26,7 @@
package Vend::Order;
require Exporter;
-$VERSION = substr(q$Revision: 2.107 $, 10);
+$VERSION = substr(q$Revision: 2.108 $, 10);
@ISA = qw(Exporter);
@@ -2219,6 +2219,51 @@
}
+## This routine loads AutoModifier values
+## The $recalc parameter indicates it is a recalc load and not
+## an initial load, so that you don't reload all parameters only ones
+## that should change based on an option setting (different SKU)
+
+sub auto_modifier {
+ my ($item, $recalc) = @_;
+ my $code = $item->{code};
+ for my $mod (@{$Vend::Cfg->{AutoModifier}}) {
+ my $attr;
+ my ($table,$key,$foreign) = split /:+/, $mod, 3;
+
+ if($table =~ s/^!\s*//) {
+ # This is an auto-recalculating attribute
+ }
+ elsif($recalc) {
+ # Don't want to reload non-auto-recalculating attributes
+ next;
+ }
+
+ if($table =~ /=/) {
+ ($attr, $table) = split /\s*=\s*/, $table, 2;
+ }
+
+ if(! $key and ! $foreign) {
+ $attr ||= $table;
+ $item->{$attr} = item_common($item, $table);
+ next;
+ }
+
+ unless ($key) {
+ $key = $table;
+ $table = $item->{mv_ib};
+ }
+
+ $attr ||= $key;
+
+
+ my $select = $foreign ? $item->{$foreign} : $code;
+ $select ||= $code;
+
+ $item->{$attr} = ::tag_data($table, $key, $select);
+ }
+}
+
sub add_items {
my($items,$quantities) = @_;
@@ -2449,37 +2494,8 @@
$item->{$i} = $attr{$i}->[$j];
}
}
- if($Vend::Cfg->{AutoModifier}) {
- foreach $i (@{$Vend::Cfg->{AutoModifier}}) {
- my $attr;
- my ($table,$key,$foreign) = split /:+/, $i, 3;
-
- if($table =~ /=/) {
- ($attr, $table) = split /\s*=\s*/, $table, 2;
- }
-
- if(! $key and ! $foreign) {
- $attr ||= $table;
- $item->{$attr} = item_common($item, $table);
- next;
- }
- unless ($key) {
- $key = $table;
- $table = $item->{mv_ib};
- }
-
- $attr ||= $key;
-
-
- my $select = $foreign ? $item->{$foreign} : $code;
- $select ||= $code;
-
-#::logDebug("attr=$attr table=$table key=$key select=$select foreign=$foreign");
- $item->{$attr} = ::tag_data($table, $key, $select);
-#::logDebug("item->$attr=$item->{$attr}");
- }
- }
+ auto_modifier($item) if $Vend::Cfg->{AutoModifier};
if(my $oe = $Vend::Cfg->{OptionsAttribute}) {
eval {
More information about the interchange-cvs
mailing list