[ic] Bug found: get_cart with merge=1

Brian Kaney brian at vermonster.com
Fri Mar 4 19:10:41 EST 2005

On Sun, 2005-02-27 at 20:19, brian at vermonster.com wrote:
> Hello,
> I am on IC 5.2 and think I've discovered a bug with the userdb get_cart function
> with the merge="1" flag.
> Consider a saved cart consisting of a master item with one or more sub-items.  A
> user imports this saved cart twice.  Deleting one of the master items causes
> all the sub-items are deleted.
> I looked in the [dump] and noticed that the mv_mi id's for the two groups are
> the same.  It seems that get_cart with merge="1" does not consider the mv_mi
> values of items already in the shopping cart.  It should and I believe this is
> a bug.

I solved this by creating a usertag that looks into a user's saved carts
and finds the maximum mv_mi.  I then increment this and loop around the
items in the cart, forcing the mv_mi the new max value.  Then I save the
cart using the save_cart tag:

[perl userdb]
   my $max = $Tag->mvmi_max();
   foreach my $item (@$Items) { $item->{'mv_mi'} = $max + 1; }

[save_cart nickname="[cgi cart_nickname]" hide="1"]

And here is the code I wrote for the usertag:

# $Id:mvmi_max.usertag p,v 2005/03/04 23:17:41 bkaney $
# This routine loops though a user's saved carts and
# finds and returns the maximum master id.  This lets
# us save grouped carts.
UserTag mvmi_max Routine <<EOR
sub {
    my $key = $Vend::Session->{username};
    my $cs =  $Tag->data({table => 'userdb', field => 'carts', key =>
    my @csa = split(/,/, $cs);
    my $max = 0; my $cnt = 1;
        if($_ =~ /\'mv_mi\' =\> \'?([0-9]*)\'?/)
            $max = $1 if ($1 > $max);
        return $max if $cnt > 500;
    return $max;

- Brian

More information about the interchange-users mailing list