How can I use the vat price altered in a custom product template?

I was using $node->sell_price to display the price, but it doesn't have any tax alteration apply to it. Do I have to recalculate the price myself, or is it possible to call a variable that would have already have the right price?

Comments

longwave’s picture

Status: Active » Fixed

You need to call uc_price() as follows to obtain altered prices for a node (which includes VAT and any other module that might change the sell price):

$context = array(
  'revision' => 'themed',
  'type' => 'product',
  'class' => array('product', 'sell_price'),
  'subject' => array('node' => $node),
);

print uc_price($node->sell_price, $context);

A documentation note for this has been added to README.txt.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

egill80’s picture

Status: Closed (fixed) » Active

I have e site where i want to display the price incl. VAT on a custom product.tpl by using $node->sell_price and $node->list_price.

i tried to use this code in VAT readme file but i need some more specific information on how to get it to work.

i have a template product.tpl.php and i added the line and the code

 print uc_price($node->sell_price, $context)

$context = array(
  'revision' => 'themed',
  'type' => 'product',
  'class' => array('product', 'sell_price', 'list_price'),
  'subject' => array('node' => $node),
);

which gave me the following error:

Fatal error: Unsupported operand types in /mounted-storage/home40b/sub001/sc16032-XYBW/ssl/sandemo.dk/sites/all/modules/ubercart/uc_store/includes/uc_price.inc on line 96.

can anybody explain me what im doing wrong and how and where to implement the code so it works.

Thanks

EDIT: Sorry, i placed the context code after print uc_price so of course the database could read my $context, i changed it around and it works fine.

longwave’s picture

Status: Active » Closed (fixed)