# 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: CartItemList.pm,v 2.2 2006/10/16 21:08:04 moeller Exp $ package Bivio::PetShop::Model::CartItemList; use strict; $Bivio::PetShop::Model::CartItemList::VERSION = sprintf('%d.%02d', q$Revision: 2.2 $ =~ /\d+/g); $_ = $Bivio::PetShop::Model::CartItemList::VERSION; =head1 NAME Bivio::PetShop::Model::CartItemList - items in a cart =head1 RELEASE SCOPE bOP =head1 SYNOPSIS use Bivio::PetShop::Model::CartItemList; =cut =head1 EXTENDS L =cut use Bivio::Biz::ListModel; @Bivio::PetShop::Model::CartItemList::ISA = ('Bivio::Biz::ListModel'); =head1 DESCRIPTION C =cut #=IMPORTS use Bivio::PetShop::Model::Item; use Bivio::PetShop::Type::Price; use Bivio::PetShop::Type::StockStatus; #=VARIABLES =head1 METHODS =cut =for html =head2 static execute_load_for_order(Bivio::Agent::Request req) Loads the list for the order present on the request. =cut sub execute_load_for_order { my($proto, $req) = @_; # store the cart_id on the request, used in internal_pre_load() $req->put(cart_id => $req->get('Model.Order')->get('cart_id')); $proto->new($req)->load_all; return; } =for html =head2 internal_initialize() : hash_ref; B =cut sub internal_initialize { return { version => 1, # List of fields which uniquely identify each row in this list primary_key => [ # Causes join of Item, Inventory, and Product on item_id [qw(Item.item_id Inventory.item_id CartItem.item_id)], ], # Allow sorting by Item.attr1 order_by => ['Item.attr1'], other => [ # Joins Item and Product on product_id [qw(Item.product_id Product.product_id)], 'CartItem.quantity', 'CartItem.unit_price', 'Inventory.quantity', 'Product.name', # Locally computed fields { name => 'total_cost', type => 'Price', constraint => 'NOT_NULL', }, { name => 'in_stock', type => 'StockStatus', constraint => 'NOT_NULL', }, { name => 'item_name', type => 'Line', constraint => 'NOT_NULL', }, ], }; } =for html =head2 internal_pre_load(Bivio::SQL::ListQuery query, Bivio::SQL::ListSupport support, array_ref params) : string Adds the current cart_id to the query. =cut sub internal_pre_load { my($self, $query, $support, $params) = @_; # use the cart_id on the request, otherwise from the cookie push(@$params, $self->get_request->unsafe_get('cart_id') || $self->new_other('Cart')->load_from_cookie->get('cart_id')); return 'cart_item_t.cart_id=?'; } =for html =head2 internal_post_load_row(hash_ref row) : boolean Computes the total cost for the row. =cut sub internal_post_load_row { my($self, $row) = @_; $row->{total_cost} = Bivio::PetShop::Type::Price->mul( $row->{'CartItem.quantity'}, $row->{'CartItem.unit_price'}); $row->{in_stock} = $row->{'Inventory.quantity'} - $row->{'CartItem.quantity'} >= 0 ? Bivio::PetShop::Type::StockStatus->IN_STOCK : Bivio::PetShop::Type::StockStatus->NOT_IN_STOCK; $row->{item_name} = Bivio::PetShop::Model::Item->format_name( $row->{'Item.attr1'}, $row->{'Product.name'}); return 1; } #=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: CartItemList.pm,v 2.2 2006/10/16 21:08:04 moeller Exp $ =cut 1;