1

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.

  • Have you thought about 2 products - 1 being the card (taxable), the other being credit to go on the card x quantity (not-taxable)? And you can only purchase credit if you combine with the card (in your basket)...? – Peter Lewis Nov 10 '14 at 14:01
  • Hi Peter, yes I considered that but I can't think of a way to implement that makes a good user experience if the user want to buy multiple cards. Using an extension to modify the tax calculation seems the best method, I'm just not sure about working with the item update/refresh as there is no documentation. – MrTomTom Nov 10 '14 at 17:05
  • @PeterLewis Unless you have an idea that could make adding two products appear to be a smooth action? – MrTomTom Nov 10 '14 at 18:57
  • Don't think this is doable - looking at the Store tax calculation code, it uses $item->item_subtotal_inc_discount. You can't change that, since it may affect other calculations beyond taxes. – Derek Hogue Nov 12 '14 at 21:05
2
+25

A concern would be that whatever you do to adjust price calculation, you have to be sure it's being adjusted in all instances - not just display of a product, but basket addition, basket display, quantity adjustments, right through to handshaking with the payment provider. You may even have to lookup the tax adjustments if you're dealing with differing tax amounts depending on customer location.

I would try to keep it simple and use Store to try to achieve what you need. In my answer I'm going to focus on your objective, rather than the approach you're currently taking. Prices in Store should already include tax:

In Store 2, prices are entered in the control panel exactly as you want them to be displayed. Taxes may be configured as "included in price", which indicates that the tax should not be added to the order total. For example, say you create a product which sells for $20.00, and a tax of 10% which is included in the price. In the checkout, when the customer purchases this item, they will see the item price as $20.00, a tax of $1.82, and an order total of $20.00.

By having the card as one taxable product and the credit as another non-taxable product, the solves the entire problem with tax calculation and you don't then need to write an extension to modify price. But your concern was customer journey.

I expect you're already using the Product Tag to display and allow the customer to add a product to their basket - change this instead to the Product Form tag, which will allow for multiple products to be added to the basket at the same time. So on the frontend, you display the card ($10) and then list credit options next to it with one "credit" pre-selected (e.g. $20). Upon adding to basket, both are added together. When displaying tax in the basket, it will only be shown for the taxable product (the cards) and because the prices already include tax, it won't adjust the customers total price of $30 (using your example), but will show total order tax as $1 already included in the total.

But there's a flaw - what if the customer purchases 2 cards with $30 credit on one and $20 credit on the other? If your "credit" product is $10 and you rely on quantity, then this approach will hit problems, As the basket will show 2xcard ($20) and 5xcredit ($50) with no idea of the distribution of credit across the 2 cards.

So to avoid this, approach the "credit" product as having a multiplier for "Size" (or similar label) which has the values of $10, $20, $30, etc and used price modifiers for each of these options, then the basket would show 2xcard ($20), 1x$30 credit, 1x$20 credit. Problem solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.