[Handel] subclassing Handel::Order in Catalyst
Ryan Lauterbach
ryan at radianit.com
Tue Oct 10 01:37:25 CEST 2006
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:
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 = $cart->items(undef, RETURNAS_ITERATOR);
}
while (my $item = $items->next) {
my %copy;
foreach (RMA::M::HandelItem->columns) {
next if $_ =~ /^(id|cart)$/i;
$copy{$_} = $item->$_;
};
$copy{'id'} = $self->uuid unless constraint_uuid($copy{'id'});
$copy{'orderid'} = $order->id;
$copy{'total'} = $copy{'quantity'}*$copy{'price'};
$copy{logo} = 'logotest';
$order->add_to_items(\%copy);
};
}
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;
More information about the Handel
mailing list