[Handel] subclassing Handel::Order in Catalyst
Christopher H. Laco
claco at chrislaco.com
Tue Oct 10 19:44:44 CEST 2006
Ryan Lauterbach wrote:
> 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
Also, my brain is on another task at the moment...so I'm a little non
focused on the topic at the moment...
Something else to check... Make sure to tell Checkout to use your
order_class, otherwise it will try to use Handel::Order instead...
But, that brings up a bug...
MyOrderClass uses Handel::Checkout during create(), which defaults to
Handel::Order...
Order::create should tell the checkout class it's using to use itself in
Checkout->order_class.... ugh...
What does your order->create call look like again?
-=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/f7c6cb78/attachment.pgp
More information about the Handel
mailing list