This is a tough one. Ok, so looked at this some more. The main problem is virtuemart assumes once a discount is processed it is on all products, you would have to make changes to the core to get it to work correctly. Here is what I came up with, working with virtuemart 1.1.9:
in www/administrator/components/com_virtuemart/classes/ps_checkout.php, function calc_order_tax, around line 1617 (in the else loop) is this code
<?php
for($i = 0; $i < $cart["idx"]; $i++) {
$item_weight = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity'];
if ($item_weight !=0 or TAX_VIRTUAL) {
$price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
$price['product_price'] = $GLOBALS['CURRENCY']->convert( $price['product_price'], $price['product_currency']);
$tax_rate = $ps_product->get_product_taxrate($cart[$i]["product_id"]);
if( (!empty( $_SESSION['coupon_discount'] ) || !empty( $d['payment_discount'] ))
&& PAYMENT_DISCOUNT_BEFORE == '1' ) {
$use_coupon_discount= @$_SESSION['coupon_discount'];
if( !empty( $_SESSION['coupon_discount'] )) {
if( $auth["show_price_including_tax"] == 1 ) {
$use_coupon_discount = $_SESSION['coupon_discount'] / ($tax_rate+1);
}
}
$factor = (100 * ($use_coupon_discount + @$d['payment_discount'])) / $this->_subtotal;
$price["product_price"] = $price["product_price"] - ($factor * $price["product_price"] / 100);
@$order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate * $cart[$i]["quantity"];
}
$order_tax += $price["product_price"] * $tax_rate * $cart[$i]["quantity"];
$total += $price["product_price"] * $cart[$i]["quantity"];
}
}
?>
change it to this:
<?php
{ # seyi_code
$coupon_subtotal = 0;
$discount_products = array();
if(!empty($_SESSION['coupon_awo_productids'])) {
$discount_products = @explode(',',$_SESSION['coupon_awo_productids']);
for($i = 0; $i < $cart["idx"]; $i++) {
if(!in_array($cart[$i]["product_id"],$discount_products)) continue;
$price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
$price['product_price'] = $GLOBALS['CURRENCY']->convert( $price['product_price'], $price['product_currency']);
$coupon_subtotal += $price['product_price']*$cart[$i]['quantity'];
}
}
if($coupon_subtotal == 0) $coupon_subtotal = $this->_subtotal;
}
for($i = 0; $i < $cart["idx"]; $i++) {
$item_weight = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity'];
if ($item_weight !=0 or TAX_VIRTUAL) {
$price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
$price['product_price'] = $GLOBALS['CURRENCY']->convert( $price['product_price'], $price['product_currency']);
$tax_rate = $ps_product->get_product_taxrate($cart[$i]["product_id"]);
if( (!empty( $_SESSION['coupon_discount'] ) || !empty( $d['payment_discount'] ))
&& PAYMENT_DISCOUNT_BEFORE == '1' ) {
if(!in_array($cart[$i]["product_id"],$discount_products)) # seyi_code
@$order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate * $cart[$i]["quantity"]; # seyi_code
else {
$use_coupon_discount= @$_SESSION['coupon_discount'];
if( !empty( $_SESSION['coupon_discount'] )) {
if( $auth["show_price_including_tax"] == 1 ) {
//$use_coupon_discount = $_SESSION['coupon_discount'] / ($tax_rate+1); # seyi_code COMMENT OUT
}
}
//$factor = (100 * ($use_coupon_discount + @$d['payment_discount'])) / $this->_subtotal;
$factor = (100 * ($use_coupon_discount + @$d['payment_discount'])) / $coupon_subtotal; # seyi_code
$price["product_price"] = $price["product_price"] - ($factor * $price["product_price"] / 100);
@$order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate * $cart[$i]["quantity"];
}
}
$order_tax += $price["product_price"] * $tax_rate * $cart[$i]["quantity"];
$total += $price["product_price"] * $cart[$i]["quantity"];
}
}
?>
This checks the products that have been discounted and calculates the taxes based on those