Tags/topics: 
2
Answers
Vote up!
1
Vote down!

Basket summary to show EX. VAT total.

Hi,

I'm currently building a site which has user role dependent pricing. I have two sets of prices (one for trade customers and one for retail customers).

All products have two price fields commerce_price and field_trade_price. All prices are entered with "Include tax in this price: none" so that the VAT is calculated later on.

Retail customers browse the site and view all products inclusive of VAT. Once they get through to the checkout they see the VAT breakdown and totals the same as the trade customers.

Trade customers browse the site and view all the products exclusive of VAT. I use rules to override the default commerce_price field with a new field_trade_price field which holds the trade price for the product. Once they have built their order, the basket and checkout displays the VAT amount and calculates the total based on this new price.

The shipping rules are also different for the two user bases. The trade customers must reach a basket total of £150 Ex. VAT in order to receive free shipping on their order.

My problem: the views Commerce Line Item: Line item summary container provided by commerce always shows the final basket total, including shipping, vat, discounts etc etc. When this summary is used as part of a 'mini basket' view, displayed at the top of the site on every page, we ideally need to show Ex. VAT totals for trade customers, so they know if they meet the free delivery rules. Is there an easy way to achieve this?

Many thanks!

Asked by: Orphans
on June 28, 2013

2 Answers

Vote up!
0
Vote down!

For all those interested... I decided to try to achieve this with Views and Views PHP. My solution was messy... but it worked.

I inserted the following PHP code into the views footer:

<?php
global $user;
$trade_role = 4;

$items = 0;
$total = 0;
foreach (
$results as $r){
  foreach (
$r->field_commerce_total[0]['raw']['data']['components'] as  $component){
    if (
$component['name'] == 'base_price' || !in_array($trade_role, array_keys($user->roles)) ){
     
$total += $component['price']['amount'];
    }
  }
 
$items += $r->commerce_line_item_field_data_commerce_line_items_quantity;
}

$total = number_format($total / 100, 2);

$variables = array(
 
'quantity_raw' => $items,
 
'quantity_label' => '',
 
'total' => "&pound;" . $total,
 
'total_label' => 'Your Basket - ',
 
'links' => '<ul class="links inline"><li class="line-item-summary-view-cart first"><a rel="nofollow" href="/basket">View Basket</a></li><li class="line-item-summary-checkout last"><a rel="nofollow" href="/basket">Checkout</a></li></ul>'
);

echo
theme('commerce_line_item_summary', $variables);
?>

Hope this helps someone.

Answer by: Orphans
Posted: Jul 5, 2013