[ic] Shipping woes

Andy Mayer interchange-users@icdevgroup.org
Wed May 7 04:16:01 2003


On Tue, 2003-05-06 at 23:08, Jamie Neil wrote:
> I've got a Usertag which adds VAT onto all the displayed prices in my
> catalog (it's a consumer oriented site), and I can wrap it around just about
> any tag I want (price, total etc.) by using the contained tag's noformat
> option.

I am also building a B2C site, and need VAT to be included in all the
prices displayed, but I have chosen a different solution which I would
value feedback on...

I have decided to make all prices stored in the products and shipping
table to be *inclusive* of VAT. I have then used code to display the VAT
element of the prices at checkout as follows.

First, I use a usertag called "justtax" to return the VAT element of
each product. (I use tax "multi" and make sure that the country and
products table is set up with tax categories as normal).

# return just the tax element for an item

UserTag justtax              Order        amount cat notax
UserTag justtax              addAttr
UserTag justtax              Routine   <<EOR
sub {
        my ($amount, $cat, $notax, $ref) = @_;
        return 0 if $notax;
        my $cfield = $::Variable->{MV_COUNTRY_FIELD} || 'country';
        my $country = $ref->{country} || $::Values->{$cfield};
        return 0 if ! $country;
        my $ctable   = $ref->{country_table}
                                || $::Variable->{MV_COUNTRY_TABLE}
                                || 'country';
        my $c_taxfield   = $ref->{country_tax_field}
                                || $::Variable->{MV_COUNTRY_TAX_FIELD}
                                || 'tax';
        my $type ||= $Tag->data($ctable, $c_taxfield, $country);
        return 0 if ! $type;
        $type =~ s/^\s+//;
        $type =~ s/\s+$//;
        my $tax = Vend::Util::get_option_hash($type);
        my $taxrate = defined $tax->{$cat} ? $tax->{$cat} :
$tax->{default};
        $taxrate =~ s/\s*%\s*$// and $taxrate /= 100;
        my $taxamount = $amount * $taxrate;
        return $taxamount;
}
EOR

Secondly, I have modified the checkout page to call the justtax usertag
for each item displayed in the basket and store it in the scratch
variable "totaljusttax".

[comment] Keep a running total of tax paid
[/comment]
[perl table="country"]
my $justtax = $Tag->justtax("[item-subtotal noformat=0]","[item-field
tax_category]","[item-field nontaxable]");
$Scratch->{totaljusttax} += $justtax;
return;
[/perl]

Thirdly, to stop the checkout adding tax to my already inclusive-of-VAT
prices I zero the salestax as follows:

[assign salestax=0]

And finally, I display the the calculated VAT, alongside the total
price, as follows:

<TR>
<TD ALIGN=left class="contentbar1">VAT:</TD>
<TD ALIGN=RIGHT class="contentbar1">[currency][scratchd
totaljusttax][/currency]</TD>
</TR>

(It needs a small modification to add the shipping tax in, but that's
basically it. No need to alter the shipping display, or any other price
display). 

It seems too easy to me! So I would value comments and feedback as to
whether I have missed anything, or am creating problems for myself
further down the line.

Cheers,

Andy

PS. Thanks to Jamie Neil who helped me with the usertag. See thread:

http://www.icdevgroup.org/pipermail/interchange-users/2003-May/033058.html