[Handel] subclassing Handel::Order in Catalyst

Ryan Lauterbach ryan at radianit.com
Tue Oct 10 19:30:56 CEST 2006


Christopher H. Laco wrote:
> 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?
>   
Thanks for the reply Chris.  That is correct 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',
>> );
>>     

>
> 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;
> };
>
>   
Order class now looks like:


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) 
    foreach my $item ($cart->items) {
        $order->add($item);
    }


   # Uncommenting below gives cat error
   #  
   #
   # Caught exception in RMA::C::Checkout->load 
"DBIx::Class::Relationship::Base::create_related(): No such column logo 
on Handel::Storage::DBIC::Order::029E536E588611DBB0517C1592004FF5::Items 
at /usr/local/lib/perl5/site_perl/5.8.8/Handel/Storage/  DBIC.pm line 84"

   # $order->add({logo => 'logo test'});

    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.
>   
Now, if I add

__PACKAGE__->create_accessors;


to the above item class no column values are copied at all, not even the 
default ones.   I feel as if I'm really close, just missing some key 
link.  I have attached my model classes if that helps clarify anything.  
Is there an example of a subclassed catalyst handel cart item class 
anywhere?

Thanks again,

Ryan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Cart.pm
Type: application/x-perl
Size: 235 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/handel/attachments/20061010/5e6a0da0/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DBIC.pm
Type: application/x-perl
Size: 342 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/handel/attachments/20061010/5e6a0da0/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HandelCart.pm
Type: application/x-perl
Size: 134 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/handel/attachments/20061010/5e6a0da0/attachment-0002.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HandelItem.pm
Type: application/x-perl
Size: 236 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/handel/attachments/20061010/5e6a0da0/attachment-0003.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Order.pm
Type: application/x-perl
Size: 238 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/handel/attachments/20061010/5e6a0da0/attachment-0004.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HandelOrder.pm
Type: application/x-perl
Size: 646 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/handel/attachments/20061010/5e6a0da0/attachment-0005.bin 


More information about the Handel mailing list