Added the methods for the pluggable tax system that add templ vars to the cart and cart items.
This commit is contained in:
parent
9d90b92629
commit
7fb87de71d
5 changed files with 154 additions and 14 deletions
|
|
@ -735,6 +735,7 @@ sub www_view {
|
|||
my $url = $session->url;
|
||||
my $i18n = WebGUI::International->new($session, "Shop");
|
||||
my @items = ();
|
||||
my $taxDriver = WebGUI::Shop::Tax->getDriver( $session );
|
||||
|
||||
if($url->forceSecureConnection()){
|
||||
return "redirect";
|
||||
|
|
@ -785,6 +786,9 @@ sub www_view {
|
|||
unless (WebGUI::Error->caught) {
|
||||
$properties{shippingAddress} = $address->getHtmlFormatted;
|
||||
}
|
||||
|
||||
$taxDriver->appendCartItemVars( \%properties, $item );
|
||||
|
||||
push(@items, \%properties);
|
||||
}
|
||||
my %var = (
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,33 @@ sub addVATNumber {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 appendCartItemVars ( var, cartItem )
|
||||
|
||||
See WebGUI::Shop::TaxDriver->appendCartItemVars.
|
||||
|
||||
Additionally adds VAT number to var.
|
||||
|
||||
=cut
|
||||
|
||||
sub appendCartItemVars {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
my $item = shift;
|
||||
|
||||
$self->SUPER::appendCartItemVars( $var, $item );
|
||||
|
||||
my $address = eval { $item->getShippingAddress };
|
||||
unless ( WebGUI::Error->caught ) {
|
||||
my $countryCode = $self->getCountryCode( $address->get( 'country' ) );
|
||||
if ( $countryCode && $self->hasVATNumber( $countryCode ) ) {
|
||||
$var->{ VATNumber } = $self->getVATNumbers( $countryCode )->[0]->{ vatNumber };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 className
|
||||
|
||||
Returns the name of this class.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue