Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Interchange: cvs

interchange - pajamian modified 2 files

 

 

Interchange cvs RSS feed   Index | Next | Previous | View Threaded


interchange-cvs at icdevgroup

May 20, 2009, 3:13 PM

Post #1 of 2 (386 views)
Permalink
interchange - pajamian modified 2 files

User: pajamian
Date: 2009-05-20 22:13:32 GMT
Modified: . WHATSNEW-5.7
Modified: lib/Vend Cart.pm
Log:
MaxQuantity fixes:

* A null or non-numerical entry in the table(s) for the maxquantity field should
result in no maximum quantity enforcement for that product.

* Remove redundant code for fetching the quantity from the table(s).

* Fix instance where two DB hits are used to fetch one value.

* Get rid of goto.

* Basically a rewrite of the correspondign block of code.

Revision Changes Path
2.44 interchange/WHATSNEW-5.7


rev 2.44, prev_rev 2.43
Index: WHATSNEW-5.7
===================================================================
RCS file: /var/cvs/interchange/WHATSNEW-5.7,v
retrieving revision 2.43
retrieving revision 2.44
diff -u -r2.43 -r2.44
--- WHATSNEW-5.7 20 May 2009 09:39:19 -0000 2.43
+++ WHATSNEW-5.7 20 May 2009 22:13:32 -0000 2.44
@@ -111,6 +111,10 @@

* _set_acl() in UserDB.pm now uses adjust_time() instead of time_to_seconds().

+* Fix MaxQuantityField to allow a null, blank, or non-numerical entry in the
+ field to represent that no maximum quantity should be enforced for that
+ product.
+
Payment
-------




2.26 interchange/lib/Vend/Cart.pm


rev 2.26, prev_rev 2.25
Index: Cart.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Cart.pm,v
retrieving revision 2.25
retrieving revision 2.26
diff -u -r2.25 -r2.26
--- Cart.pm 16 Apr 2009 14:51:41 -0000 2.25
+++ Cart.pm 20 May 2009 22:13:32 -0000 2.26
@@ -1,8 +1,8 @@
# Vend::Cart - Interchange shopping cart management routines
#
-# $Id: Cart.pm,v 2.25 2009-04-16 14:51:41 mheins Exp $
+# $Id: Cart.pm,v 2.26 2009-05-20 22:13:32 pajamian Exp $
#
-# Copyright (C) 2002-2008 Interchange Development Group
+# Copyright (C) 2002-2009 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
#
# This program was originally based on Vend 0.2 and 0.3
@@ -25,7 +25,7 @@

package Vend::Cart;

-$VERSION = substr(q$Revision: 2.25 $, 10);
+$VERSION = substr(q$Revision: 2.26 $, 10);

use strict;

@@ -247,55 +247,65 @@
}
}

- if($Vend::Cfg->{MaxQuantityField}) {
- $item->{mv_max_quantity} = 0;
-
- foreach my $fieldspec (split('[,\s]+', $Vend::Cfg->{MaxQuantityField})) {
- next unless $fieldspec;
-
- my ($tab, $col) = split /:+/, $fieldspec;
- if(! length $col) {
- $col = $tab;
- $tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
- }
- if ( $tab =~ s/^=// ) {
- $item->{mv_max_quantity} = $quantity_cache{"$tab.$col.$item->{code}"} = ::tag_data($tab, $col, $item->{code});
- goto DONE_QUANTITY_ADJUST;
- }
- elsif ( $tab =~ s/^\?// ) {
- if ( $item->{mv_max_quantity} ) {
- $item->{mv_max_quantity} = $quantity_cache{"$tab.$col.$item->{code}"} = ::tag_data($tab, $col, $item->{code}) if
- ::tag_data($tab, $col, $item->{code});
- goto DONE_QUANTITY_ADJUST;
- }
- }
- else {
- $item->{mv_max_quantity} += $quantity_cache{"$tab.$col.$item->{code}"} || ($quantity_cache{"$tab.$col.$item->{code}"} = ::tag_data($tab, $col, $item->{code}));
- }
- }
- $item->{mv_max_quantity} -= $total_quantity{$item->{code}};
- $item->{mv_max_quantity} = 0 if $item->{mv_max_quantity} < 0;
-
- DONE_QUANTITY_ADJUST:
-
- if(
- length $item->{mv_max_quantity}
- and
- $item->{quantity} > $item->{mv_max_quantity}
- )
- {
- $old_item = { %$item } if $quantity_raise_event;
- $item->{quantity} = $item->{mv_max_quantity};
- $item->{mv_max_over} = 1;
- delete $item->{mv_min_under};
- trigger_update(
- $s,
- $item,
- $old_item,
- $event_cartname
- ) if $quantity_raise_event;
- }
- }
+ MAX_QUANTITY: {
+ last MAX_QUANTITY unless $Vend::Cfg->{MaxQuantityField};
+ my $mv_max = \$item->{mv_max_quantity};
+ undef $$mv_max;
+
+ QUANTITY_ADJUST: {
+ QUANTITY_FIELD: foreach my $fieldspec (split('[,\s]+', $Vend::Cfg->{MaxQuantityField})) {
+ next QUANTITY_FIELD unless $fieldspec;
+
+ my ($tab, $col) = split /:+/, $fieldspec;
+ if(! length $col) {
+ $col = $tab;
+ $tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
+ }
+
+ my ($prefix) = $tab =~ s/^([=\?])//;
+ $prefix ||= '';
+
+ my $max = \$quantity_cache{"$tab.$col.$item->{code}"};
+ $$max ||= ::tag_data($tab, $col, $item->{code});
+ undef $$max unless $$max =~ /\d/;
+
+ if ($prefix eq '=') {
+ $$mv_max = $$max;
+ last QUANTITY_ADJUST if defined $$max;
+ last MAX_QUANTITY;
+ }
+
+ elsif ($prefix = '?') {
+ next QUANTITY_FIELD if !defined $$max || $$max <= 0;
+ $$mv_max = $$max;
+ last QUANTITY_ADJUST;
+ }
+
+ elsif (defined $$max) {
+ $$mv_max ||= 0;
+ $$mv_max += $$max;
+ }
+ } # QUANTITY_FIELD
+
+ last MAX_QUANTITY unless defined $$mv_max;
+
+ $$mv_max -= $total_quantity{$item->{code}};
+ $$mv_max = 0 if $$mv_max < 0;
+ } # QUANTITY_ADJUST
+
+ if($item->{quantity} > $$mv_max) {
+ $old_item = { %$item } if $quantity_raise_event;
+ $item->{quantity} = $$mv_max;
+ $item->{mv_max_over} = 1;
+ delete $item->{mv_min_under};
+ trigger_update(
+ $s,
+ $item,
+ $old_item,
+ $event_cartname
+ ) if $quantity_raise_event;
+ }
+ } # MAX_QUANTITY

for(@{$Vend::Cfg->{AutoModifier}}) {
next unless /^!/;





_______________________________________________
interchange-cvs mailing list
interchange-cvs [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs


interchange-cvs at icdevgroup

May 20, 2009, 4:37 PM

Post #2 of 2 (343 views)
Permalink
interchange - pajamian modified 2 files [In reply to]

User: pajamian
Date: 2009-05-20 23:37:27 GMT
Modified: . WHATSNEW-5.7
Modified: code/UI_Tag user_merge.tag
Log:
New user_merge specialsub is run from the [user-merge] usertag. Arguments
passed to the sub are: ($from_user, $from_urec, $to_user, $to_urec, $udb, $tdb)
with the following values:

$from_user - The username of the user being merged from.
$from_urec - Hashref of columns in the userdb table for the user being merged
from.
$to_user - The username of the user being merged to.
$to_urec - Hashref of columns in the userdb table for the user being merged
to. Any changes made to this hashref will be recorded back into
the userdb for this user.
$udb - $db object for the userdb table.
$tdb - $db object for the transactions table.

The return value should be false to indicate that normal processing of the merge
should continue as normal for this from user (continue on to merge carts and
transactions) or true to indicate that no further processing should be done for
this user (do not merge the carts or transactions). A false return value will
also cause any changes to $to_urec to be recorded into the userdb for the to
user at the conclusion of the merge. Note that if there are multiple from users
then this specialsub will be run for each of the from users.

Example:

SpecialSub user_merge user_merge_sub
Sub user_merge_sub <<EOS
sub {
my ($from_user, $from_urec, $to_user, $to_urec, $udb, $tdb) = @_;

# Copy first and last name over from from user:
$to_urec->{fname} = $from_urec->{fname};
$to_urec->{lname} = $from_urec->{lname};

# False return value tells the [user-merge] tag to save the new $to_urec
# structure off as well as to continue with normal processing of the
# merge.
return;
}
EOS

Revision Changes Path
2.45 interchange/WHATSNEW-5.7


rev 2.45, prev_rev 2.44
Index: WHATSNEW-5.7
===================================================================
RCS file: /var/cvs/interchange/WHATSNEW-5.7,v
retrieving revision 2.44
retrieving revision 2.45
diff -u -r2.44 -r2.45
--- WHATSNEW-5.7 20 May 2009 22:13:32 -0000 2.44
+++ WHATSNEW-5.7 20 May 2009 23:37:27 -0000 2.45
@@ -169,6 +169,9 @@

* Allow file removal with uploadhelper widget (#180).

+* New user_merge specialsub is run from the [user-merge] tag when two users are
+ merged.
+
Standard demo
-------------




1.4 interchange/code/UI_Tag/user_merge.tag


rev 1.4, prev_rev 1.3
Index: user_merge.tag
===================================================================
RCS file: /var/cvs/interchange/code/UI_Tag/user_merge.tag,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- user_merge.tag 21 Jan 2008 19:22:55 -0000 1.3
+++ user_merge.tag 20 May 2009 23:37:27 -0000 1.4
@@ -1,11 +1,11 @@
-# Copyright 2005-2007 Interchange Development Group and others
+# Copyright 2005-2009 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
-# $Id: user_merge.tag,v 1.3 2008-01-21 19:22:55 mheins Exp $
+# $Id: user_merge.tag,v 1.4 2009-05-20 23:37:27 pajamian Exp $

UserTag user-merge Order from to
UserTag user-merge addAttr
@@ -134,10 +134,33 @@

my $logfile = $opt->{logfile} || 'logs/merged_users.log';
my $done_one;
+ my $save_rec;

for my $user (@users) {
$Tag->log({ type => 'text', file => $logfile, body => $Tag->time() . "\n" } )
unless $done_one++;
+
+ my $from_urec = $udb->row_hash($user);
+
+ # If there's a user_merge specialsub run it here
+ if (my $subname = $Vend::Cfg->{SpecialSub}{user_merge}) {
+ my $sub = $Vend::Cfg->{Sub}{$subname} || $Global::GlobalSub->{$subname};
+ my $status;
+ eval { $status = $sub->($user, $from_urec, $to_user, $urec, $udb, $tdb) };
+ if ($@) {
+ ::logError("Error running %s subroutine %s: %s", 'user_merge', $subname, $@);
+ }
+
+ elsif ($status) {
+ # Skip further processing of this user
+ next;
+ }
+
+ else {
+ $save_rec = 1;
+ }
+ }
+
for(@ttab) {
$sth{$_}->execute($to_user, $user)
or $err->("%s update failed: %s", $_, $dbh{$_}->errstr);
@@ -147,12 +170,11 @@
push @record, $o;
}

- my $urec = $udb->row_hash($user);
- my $chash = string_to_ref($urec->{carts});
+ my $chash = string_to_ref($from_urec->{carts});
if(ref $chash) {
for(keys %$chash) {
if($cart_hash->{$_}) {
- $Tag->log({ type => 'text', file => $logfile, body => "unable to merge cart=$_ (already exists). Contents=$urec->{carts}\n"} );
+ $Tag->log({ type => 'text', file => $logfile, body => "unable to merge cart=$_ (already exists). Contents=$from_urec->{carts}\n"} );
}
else {
$cart_hash->{$_} = $chash->{$_};
@@ -160,7 +182,7 @@
}
}
}
- my $ustring = ::uneval($urec);
+ my $ustring = ::uneval($from_urec);
$Tag->log({ type => 'text', file => $logfile, body => "delete user $user=$ustring\n"} );
$udb->delete_record($user)
unless $opt->{no_delete};
@@ -168,8 +190,20 @@
}

if($carts_changed) {
- $udb->set_field($to, 'carts', ::uneval($cart_hash));
+ if ($save_rec) {
+ $urec->{carts} = ::uneval($cart_hash);
+ }
+
+ else {
+ $udb->set_field($to, 'carts', ::uneval($cart_hash));
+ }
}
+
+ if ($save_rec) {
+ delete $urec->{$udb->[$Vend::Table::DBI::KEY]};
+ $udb->set_slice($to, $urec);
+ }
+
push @record, '';

$Tag->log({ type => 'text', file => $logfile, body => join("\n", @record)} );





_______________________________________________
interchange-cvs mailing list
interchange-cvs [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs

Interchange cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.