[Handel] shopping cart
Christopher H. Laco
claco at chrislaco.com
Thu Aug 3 16:43:16 CEST 2006
Christopher H. Laco wrote:
> 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'});
> };
> };
>
> 1;
Crap.
s/$cart/$self/;
-------------- 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/9d7ea523/attachment.pgp
More information about the Handel
mailing list