rendered paste bodyUserTag product_tax Order country type price taxonly noformat
UserTag product_tax addAttr
UserTag product_tax Routine <<EOR
sub {
my ($country,$type,$price,$taxonly,$noformat,$opt) = @_;
return undef unless $price;
$country = $::Values->{country} or return undef;
$type ||= 'default';
my $table = $::Variable->{MV_COUNTRY_TABLE} || 'country';
my $column = $::Variable->{MV_COUNTRY_TAX_FIELD} || 'tax';
my $db = ::database_exists_ref($table) or die qq{'$table' table doesn't exist};
$country = $db->quote($country);
my $query = qq{
SELECT $column
FROM $table
WHERE code = $country
};
my $resultset = $db->query($query);
return undef unless ($resultset && scalar(@$resultset));
my $tax = $resultset->[0]->[0] or return undef;
$tax =~ s/.*$type\s*=\s*([\d.]+)(%?).*/$1/;
$tax /= 100 if $2 eq '%';
if ($taxonly) {
$price *= $tax;
}
else {
$price += $price * $tax;
}
return currency($price,$noformat,undef,$opt)
}
EOR