[Handel] shopping cart

Christopher H. Laco claco at chrislaco.com
Thu Aug 3 16:39:55 CEST 2006

Jan Gerene wrote:
> Another question about Handel:
> When I add the same item to the shopping cart more than once, then a new order 
> line will be created each time.  Is this on purpose and if so, why?
> Would an update of the existing article not be more appropriate?
> Thanks for your ideas on this or am I doing something wrong?
> Thanks,

For some people, it is certainly possible to have two line items with
the same SKU, like two gift certificates for two different amounts, or
two customizable parts with the same sku, but different options
attached. Rather than restrict what people can do, I simply left that
functionality open ended.

You can always do this in your script:

if ( my $item = $cart->items({sku => 'ABC123'}) ) {
    print "Item Exists";
} else {
   $cart->add({sku => 'ABC123'});

or subclass:

package CustomCart;
use base qw/Handel::Cart/;

sub add {
    my ($self, $data) = @_;

    if ( my $item = $cart->items({sku => $data->{'sku'}}, 1)->first ) {
	$item->quantity($item->quantity + 1);
    } else {
        return $cart->add({sku => 'ABC123'});


I assume you're working with Handel 0.33? I would also suggest taking a
look at the 0.99_04 version on CPAN. 1.0 should be out sometime soon,
and it is a major redesign.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.rawmode.org/pipermail/handel/attachments/20060803/b7d0428d/attachment.pgp 

More information about the Handel mailing list