[Handel] subclassing Handel::Order in Catalyst

Christopher H. Laco claco at chrislaco.com
Tue Oct 10 15:23:36 CEST 2006


Ryan Lauterbach wrote:
> Hi,
> 
> I have successfully subclassed Handel::Cart and Handel::Cart::Items in 
> .99_14 to add extra fields in cart_items.  Now i need to copy the 
> cart_items fields over to order_items upon checkout.  I believe I need 
> to override copy_cart_items per the Handel::Order POD so here are my 
> classes which don't work.  Thanks for looking:

The good news is, you're most of the way there I think.
For the sake of asking, please define "don't work" in further detail...

I'm assuming that the ->can($custcol) fails, and no column value is copied?

> 
> package RMA::M::Order;
> use strict;
> use warnings;
> 
> BEGIN {
>     use base qw/Catalyst::Model::Handel::Order/;
> };
> 
> __PACKAGE__->config(
>     connection_info => ['dbi:mysql:db', 'dbuser', 'dbpass'],
>     order_class => 'RMA::M::HandelOrder',
> );

> 
> package RMA::M::HandelOrder;
> use strict;
> use warnings;
> use base qw/Handel::Order/;
> 
> __PACKAGE__->cart_class('RMA::M::HandelCart');
> 
> sub copy_cart_items {
>     my ($self, $order, $cart) >     my $items;
> 
>     {
>         no strict 'subs';
>         $items >     }
> 
>     while (my $item >         my %copy;
> 
>         foreach (RMA::M::HandelItem->columns) {
>             next if $_ =~ /^(id|cart)$/i;
>             $copy{$_} >         };
> 
>         $copy{'id'} >         $copy{'orderid'} >         $copy{'total'} > 
>         $copy{logo} > 
>         $order->add_to_items(\%copy);
>     };
> }


That copy_cart_items looks old... much older than 0.99_14...
This is what's in 0.99_14:

sub copy_cart_items {
    my ($self, $order, $cart) 
    foreach my $item ($cart->items) {
        $order->add($item);
    };

    return;
};


> 
> 1;
> 
> package RMA::M::HandelCart;
> use strict;
> use warnings;
> use base qw/Handel::Cart/;
> 
> __PACKAGE__->item_class('RMA::M::HandelItem');
> 
> 1;
> 
> 
> 
> package RMA::M::HandelItem;
> 
> use strict;
> use warnings;
> use base qw/Handel::Cart::Item/;
> 
> __PACKAGE__->storage->add_columns(qw/logo logo_data logo_type photo_type 
> photo_data photo c .../
> 
> 1;

I think this is the problem, and it's my fault for not mentioning it here:

http://search.cpan.org/~claco/Handel/lib/Handel/Manual/Cookbook/AddingColumns.pod

You'll notice in the Good/Better versions, they call
__PACKAGE__->create_accessors after adding columns. This creats
accessors for the columns in the current class; otherwise, just the
default Handel accessors are available in the stock subclass.


So, I think if you add:

__PACKAGE__->create_accessors;

right after your add_columns call, it should work.

I would sumize that if you were to do $item->logo on a cart item outside
of catalyst and outside of copy_cart_items .... it would also fail...

-=Chris

-------------- 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/20061010/75e8365d/attachment.pgp 


More information about the Handel mailing list