3

I would like the ability to round the grand total of any order to the next whole dollar utilizing a variable tax. The store I'm using is already leveraging a 3rd party tax service, so my thought was to either create a custom tax type or repurpose VAT/WEEE.

I will need to implement my own rounding algorithm as a standard rounding is only partially sufficient:

  • I will always round up to the next dollar, and never down.
  • If the total is <=.50 from the next dollar, we will still round up.
  • If the total is ==.00 we will add a full dollar

Some examples:

Grand total before tax: $3.50
Grand total after round:$4.00

Grand total before tax: $5.02
Grand total after round:$6.00

Grand total before tax: $1.99
Grand total after round:$2.00

Grand total before tax: $10.00
Grand total after round:$11.00

I'm looking for a concrete approach - either repurposing an in-built tax type or rolling my own.

philwinkle
  • 35,751
  • 5
  • 91
  • 145
  • How do you want it to show in cart & checkout? Should the rounding difference show as a separate item like tax and discount? – Martijn Schot Apr 16 '15 at 16:10
  • The approach from @parassood is absolutely correct but I figured we could get away with repurposing something like Variable Product taxes. It makes more sense to implement a custom total with a collector. It would definitely show as a separate item like tax and discount. – philwinkle Apr 16 '15 at 16:33

1 Answers1

2

Creating a new order total rather than using an existing TAX type would leave room for more flexibility. Say in future the customer wants to start using the TAX feature or want to show/hide tax in cart etc etc.

Unless the amount, by which the grand total is rounded up, is actually Tax in my humble opinion you might just be better of using a new custom total collector that is collected right before grand total and rounds up the grand total. You would then also have the option to show it as a separate total in the cart and other places.

I would just use the collector as an observer to round up the grand total if the round up amount doesn't belong to any other head than just grand total.

As for the grand total, it could be:

$grandTotal = floor($grandTotal+1.00);
Raphael at Digital Pianism
  • 70,385
  • 34
  • 188
  • 352
Paras Sood
  • 2,540
  • 1
  • 14
  • 23