Added the methods for the pluggable tax system that add templ vars to the cart and cart items.

This commit is contained in:
Martin Kamerbeek 2009-05-08 13:34:42 +00:00
parent 9d90b92629
commit 7fb87de71d
5 changed files with 154 additions and 14 deletions

View file

@ -63,24 +63,75 @@ readonly session => my %session;
readonly messages => my %messages;
private options => my %options;
#-----------------------------------------------------------
=head2 appendTaxDetailVars ($var)
=head2 appendCartItemVars ( var, cartItem )
=head3 $var
Adds tax driver specific template variables for the given cart item to the supplied hashref.
=head3 var
The template variable hash ref to add the tax vars to.
=head3 cartItem
The instanstance of WebGUI::Shop::CartItem to add the vars for.
=cut
sub appendTaxDetailVars {
sub appendCartItemVars {
my $self = shift;
my $var = shift;
my $item = shift;
return $var;
WebGUI::Error::InvalidParam->throw( 'Must supply a hash ref' )
unless $var && ref $var eq 'HASH';
WebGUI::Error::InvalidObject->throw( expected => 'WebGUI::Shop::CartItem', got => ref $item, error => 'Must pass a cart item' )
unless $item && $item->isa( 'WebGUI::Shop::CartItem' );
my $sku = $item->getSku;
my $address = eval { $item->getShippingAddress };
my $taxRate = $self->getTaxRate( $sku, $address );
my $quantity = $item->get( 'quantity' );
my $price = $sku->getPrice;
my $tax = $price * $taxRate / 100;
$var->{ taxRate } = $taxRate;
$var->{ taxAmount } = $item->cart->formatCurrency( $tax );
$var->{ pricePlusTax } = $item->cart->formatCurrency( $price + $tax );
$var->{ extendedPricePlusTax } = $item->cart->formatCurrency( $quantity * ( $price + $tax ) );
}
#-----------------------------------------------------------
=head2 canManage
=head2 appendCartVars ( var, cart )
Extend this method to add tax driver specific template variables to those supplied to the cart template.
=head3 var
The hash ref to add the template variables to.
=head3 cart
The instance of WebGUI::Shop::Cart to add the template variables for.
=cut
sub appendCartVars {
my $self = shift;
my $var = shift;
my $cart = shift;
WebGUI::Error::InvalidParam->throw( 'Must supply a hash ref' )
unless $var && ref $var eq 'HASH';
WebGUI::Error::InvalidObject->throw( expected => 'WebGUI::Shop::Cart', got => ref $cart, error => 'Must pass a cart' )
unless $cart && $cart->isa( 'WebGUI::Shop::Cart' );
}
#-----------------------------------------------------------
=head2 canManage ( )
Returns true if the current user can manage taxes.