[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: How to delete item programmatically?
Bas,
Thanks a lot for you response. I was playing around with
this last night after I posted my message, and I ran into
the same problem with not having the changes to the cart
be visible immediately.
I found that if I did a direct array assignment, that the
cart WOULD change immediately. e.g. :
Take the line:
$Vend::Session->{carts}{$basket} = \@newcart;
and change it to:
@{$Vend::Session->{carts}{$basket}} = @newcart;
Thanks again for responding. I was a little worried that
I might be doing something verboten by messing around with
the cart directly.
Regards,
Lee Nelson
P.S. This was my solution, with code borrowed from the Perl Cookbook.
[perl values scratch carts]
# This code will remove duplicate entries of item
# number 1001 in the cart. It will always favor
# the last (newest) entry in the array.
my %seen = ();
my @new = ();
foreach $el (@{$Safe{carts}->{main}}) {
# if we've seen this one, copy over the last occurence.
if (defined ($seen{$el->{'code'}}) and $el->{'code'} eq '1001')
{
$new[$seen{$el->{'code'}}] = $el;
} else
# if this is a new one, stash it's item-code and index in the hash.
{
push (@new, $el);
$seen{$el->{'code'}} = @new - 1;
}
}
@{$Safe{carts}->{main}} = @new;
'';
[/perl]