Note that there are some explanatory texts on larger screens.

plurals
  1. POApplication wide price formatting
    primarykey
    data
    text
    <p>I am working with an existing bespoke ecommerce platform which until recently had no requirement to manipulate the price which is stored with a product in the database (other than multiply by quantity etc). I've now been tasked with building the functionality which will allow these prices to be viewed with our without VAT, with customisable currency based on a site wide setting or per user with regard to both exchange rate and currency symbol. The theory behind the settings/per user/locale etc is not the problem, it's the best way to change all of the pricing across the whole site.</p> <p>A bit of background</p> <ul> <li>Output is buffered so I have access to the entire output before it's sent to the browser in <code>$output</code></li> <li>There's no existing abstraction on the pricing.</li> <li>There are places in the templates which have the price without the symbol in the format 0.00 (for Javascript based calculations) as well as ones with the symbol in the format £0.00</li> <li>Things like adding/removing from the basket are completed with Ajax and the new price returned in JSON format</li> <li>Some pricing variables are buried in large multidimensional arrays which are constructed in the core/application classes. Some of which are used for further calculations both within the core/application classes in the templates.</li> </ul> <p>Options I've considered</p> <ul> <li>Suffer the performance hit and <code>preg_replace_callback('/&amp;pound;(?:&lt;.*&gt;|\s*)?(\d*\.\d\d)/i'...);</code> on <code>$output</code>. This however doesn't resolve the problem for prices not with the £ in front as mentioned above. It also is no use when prices are returned using Ajax.</li> <li>Go through every template file, every module class, every core class, every helper and every bit of Javascript and leave the output as it is at present and duplicate whatever array key/object var is generated but suffix it with _formatted or similar and output that where necessary in the template. I'd also have to have a _calculated suffix too. So I'd have 10.00, 8.00, and £8.00 values for 10, 10*0.8 (vat) and £10*0.8 respectively.</li> <li>Go through all of the above mentioned files/sections/classes bar the templates and keep the single output but precalculated ready for templates so that I don't need to go through every template file.</li> </ul> <p>The first option can't really work unfortunately for the reasons described above so Options 2, 3 and any you might suggest are on the cards I suppose. Unfortunately there's only 2 weeks scheduled in for the entire process (loads of other unmentioned but technically unrelated) functionality to go in) and the above options, given the size of the application will probably take me about a week.</p> <p>Any suggestions or advice you might be able to give would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload