I'm developing an extension for Expresso Store that updates the tax calculation for items to exclude any amounts in the modifiers as for this application they are tax free. For example, if the price is say $10 for a physical credit card and then through a modifier they add $20 of credit to the card. I need to total to still be $30, however the tax to be calculated just on the base $10. e.g. tax @10% would result in $31 including tax.
So far in the extension I am using the Store hooks "store_order_recalculate_end" & "store_order_item_add_end" and I can loop through removing the modifier prices to get the base price of the item, however I am unsure how to then :
- calculate the tax with the new item
- update the item price in the db
- recalculate the totals for the order
My current method is below.
public function modify_gst($order){
foreach ($order->items as $item) {
$pricefortax = $item-> item_subtotal;
//Modifier amounts are not subject to tax
foreach ($item->modifiers as $modifier) {
$pricefortax = $item->item_subtotal - $modifier["price_mod"];
}
// $pricefortax is now the amount excluding any modifiers
// NEED TO: calculate item_tax based of $pricefortax
// NEED TO: Update item_tax and item_total for the item
}
//NEED TO: calculate order_tax and order_total
//NEED TO: update order_tax and order_total
}
Any help would be greatly appreciated, I can't see in the Store docs how to achieve this, It's basically my first time working with an extension in EE or dealing int the internals of Store.
$item->item_subtotal_inc_discount
. You can't change that, since it may affect other calculations beyond taxes.