We can say that it is time to add some automated tests to your application and run them at least every time you want to deploy your application to your production server - and if some of them do not work, cancel the deployment.
You will have tests for both PHP and JS code, and some of these tests will calculate some total amounts / costs / shipping costs; and if something goes wrong due to some code change, you can detect the problem automatically, without your application disrupting the production process.
Of course, this requires a little more work (both for writing tests, setting up the building platform, and for maintaining test data); but it will be of great value ...
Another possible solution would be to write your calculation code only in Javascript and run it both on the client side (this is not difficult, obviously), and on the server side.
From PHP, you can execute JS code using the Spidermonkey PECL extension (note that it is still in beta, and you need to be able to install PHP extensions, which are likely to be possible only if you are the administrator of your server and are not sure of stability).
Here's an article about it: Using JavaScript in PHP with PECL and SpiderMonkey .
With this solution, you can use JS for code that only works on the client; PHP for code that runs only on the server ... And JS for code that works on both sides.
source share