# Copyright (c) 2001 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: CartItemListForm.pm,v 2.3 2006/10/16 21:08:04 moeller Exp $ package Bivio::PetShop::Model::CartItemListForm; use strict; $Bivio::PetShop::Model::CartItemListForm::VERSION = sprintf('%d.%02d', q$Revision: 2.3 $ =~ /\d+/g); $_ = $Bivio::PetShop::Model::CartItemListForm::VERSION; =head1 NAME Bivio::PetShop::Model::CartItemListForm - editable cart item list =head1 RELEASE SCOPE bOP =head1 SYNOPSIS use Bivio::PetShop::Model::CartItemListForm; =cut =head1 EXTENDS L =cut use Bivio::Biz::ListFormModel; @Bivio::PetShop::Model::CartItemListForm::ISA = ('Bivio::Biz::ListFormModel'); =head1 DESCRIPTION C =cut #=IMPORTS use Bivio::Agent::TaskId; use Bivio::PetShop::Type::Price; #=VARIABLES =head1 METHODS =cut =for html =head2 execute_empty_row() Sets the quantity in the form row for editing. =cut sub execute_empty_row { my($self) = @_; $self->internal_put_field('CartItem.quantity' => $self->get_list_model->get('CartItem.quantity')); return; } =for html =head2 execute_ok_end() Redirects to the checkout form if OK is pressed. =cut sub execute_ok_end { my($self) = @_; # ensure the the cart grand total doesn't exceed the Price precision my($value, $err) = Bivio::PetShop::Type::Price->from_literal( $self->new_other('Cart')->load_from_cookie->get_total); if ($err) { # put the error on the first row $self->reset_cursor; $self->next_row; $self->internal_put_error('CartItem.quantity' => 'TOTAL_EXCEEDS_PRECISION'); return; } if ($self->get('ok_button')) { # redirect to the checkout page $self->get_request->client_redirect(Bivio::Agent::TaskId->CHECKOUT); } return; } =for html =head2 execute_ok_row() Updates or deletes the current row depending on the button selected. =cut sub execute_ok_row { my($self) = @_; my($cart_item) = $self->get_list_model->get_model('CartItem'); if ($self->get('CartItem.quantity') <= 0 || $self->get('remove')) { $cart_item->delete; } else { $cart_item->update({ quantity => $self->get('CartItem.quantity'), }); } return; } =for html =head2 internal_initialize() : hash_ref; B =cut sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { version => 1, list_class => 'CartItemList', visible => [ { name => 'CartItem.quantity', in_list => 1, }, { name => 'remove', type => 'OKButton', constraint => 'NONE', in_list => 1, }, { name => 'update_cart', type => 'OKButton', constraint => 'NONE', }, ], }); } #=PRIVATE METHODS =head1 COPYRIGHT Copyright (c) 2001 bivio Software, Inc. All rights reserved. Visit http://www.bivio.biz for more info. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; If not, you may get a copy from: http://www.opensource.org/licenses/lgpl-license.html =head1 VERSION $Id: CartItemListForm.pm,v 2.3 2006/10/16 21:08:04 moeller Exp $ =cut 1;