View Full Version : jQuery/Ajax Advanced Order Handler for osCommerce 2.3.3

07-08-2014, 12:10 AM
Advanced Order Handler Rev3 for osCommerce 2.3.3
Copyright (C) 2014 Jonas [email protected]

This file is part of Advanced Order Handler Rev3.

Advanced Order Handler Rev3 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Advanced Order Handler Rev3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Advanced Order Handler Rev3. If not, see .

OK, since there's a limit of 3MB per upload I had to first compress the files with xz and then with tar gzip. This way I could slide under the limit without the need to butcher the included screenshots to cut size. :=P
I also fixed the tax calculation bug that Flaggi mentioned in the Support Thread.

This Add-On requires MySQL Native Driver (mysqlnd). I have included a simple file and instructions on how you can check if mysqlnd module is loaded on your server.
If you for some reason can't use mysqlnd and want to convert the SQL statements to work without mysqlnd, I'll try to help you as long as you upload the result so others can use it when you're done.
Fixing this shouldn't be too much work. ;=)

Entire Add-On rewritten (more than once, probably..).

The Order Handler will now take order information as a JSON response from the server, parse the JSON to html and update your order table with new rows. This is a very fast and effective way of 'handling the orders', limiting the required server resources and instead puts much of the hard work on your computer.

Instead of having anonymous functions in the hundreds I have rewritten the jQuery to a module pattern instead.

The PHP code is organized as a large class with a function for every action. Hopefully, this will make it easier for those who want to start developing AJAX to see how jQuery.ajax and PHP can work together. It will also simplify the process of maintaining/improving/modifying existing functions or adding extensions/new functionality to the Order Handler as it is as simple as adding a new class function in PHP and a new module function in jQuery. ;=)

I have also implemented an error handling system where jQuery's Global Ajax Event Handler will take care of any error messages passed on from the server, or at least it should take care of them.. Anyway, jQuery will parse the error message and display a Gritter Notification with whatever the server had to say.

Important note for those who want to fiddle with the javascript and/or CSS (I forgot to add this info to the instructions..):
In ./admin/get_table.php there are 2 occurrences each of these two functions:

tep_preload_scripts( $store_country_iso_2[0]['countries_iso_code_2'], true );
tep_afterload_scripts( true );

Changing true to false will load the unminified JS instead of the two large minified JS files.
Same thing goes for CSS, if you want to change the CSS, then change the function argument below to false in get_table.php:
tep_load_css( true );

Some of the new Features for this Revision:

- Support for and tested on osCommerce 2.3.3 and 2.3.4

- Tested successfully on Google Chrome and Firefox

- Compatible with jQuery 2.1.0

- It's now possible to edit multiple orders simultaneously.

- Orders are now displayed as drop down Child Tables, meaning that you never need to go to 'Edit Order' page to do any actions.

- I have also added some simple statistics with amCharts, the idea is to work on this more further on when I have figured out what statistics that could be useful. As it is now, it's just a simple line graph of order totals and products purchased per hour and based on your selections on the table of course.

- It's now possible to mail the customer directly from the order handler.

- The order handler now uses the PHPMailer class for email, making updating orders really fast. Updating 100 orders with both updating status and sending email via external SMTP server is done almost in an instant, at least for me this was pretty slow before with PHPs mail(). Using PHPMailer is optional and toggled off as default. Before you start using it you need to configure ./admin/includes/modules/order_handler/phpmailer_config.php

- Configuration and User Preferences will be saved using either Cookies or HTML5 localStorage object. Most of the preferences available like column visibility, width, sorting etc. will be saved. Remember though that clearing your browser cache & cookies will delete your preferences.

- For those that like to work in a Print-And-Go type of workflow :rolleyes: , I have added an option that will immediately open the print dialog when invoices have finished loading and also close the new tab/window as soon as print dialog is closed on Print/Cancel. This will help to reduce 'risk' of opening a lot of tabs/windows which I have found some less experienced computer hackers to have trouble to handle.

- The display of the Header as well as the Admin Menu is now both togglable using CSS3 classes.

- Option to remove updated orders from the list or just update the status but keep them on the table have been added.

- Overlay of Dialogs is also togglable, so that you can work with the fields below the dialog when dialog is displayed.

- I have added some benchmarking functionality which will give you the proper load time for the table both in console and as notification.

- I was planning on removing the old 'Edit Order' page altogether since it was a pain to get it compatible but eventually I calmed down and now it should work as expected. There's an option that you can select to make the 'Edit Order' page open in a new tab/window.

- Some of the SQL Statements have been optimized, I worked a lot with the 'Big One', the one that gets all orders for the table, tried a lot of different approaches, but as it is now it will not risk missing any orders (I hope) and is quite fast. Loading 100 orders without cache and on remote production server the request took around 40 ms to finish and it took around 1-1.5 seconds in total for the jTable to parse the JSON and create the table.

- Keyboard Shortcuts - Bind a keyboard button for refreshing the table or any other custom function you want. Shortcuts will be saved in HTML5 localStorage.

- Modals like 'Add a new Order Totals field' should now work flawlessly.

- Available Shipping & Payment Modules will now be displayed as Bootstrap Drop downs with the option to manual input new module.

- Qtip2 - Toggleable Tooltips for most actions. I recommend turning these off when you don't need them anymore since they use up quite a bit of resources. Toggling Tooltips off will not remove the tooltips for order comments.

- Right Click Menu - Alternative to using the toolbar for actions - can be switched off in Configuration.

- Quick Delete when you only want to remove one specific order.

- Automatic Capitalization of Name and Address Fields. Since there is an awful lot of names in the world and the Regex Pattern used perhaps doesn't work for all of them, you might want to turn this off. Ask on the forum if you need to do this and I'll help you.

- Tax Calculation is rewritten and more advanced. E.g. it will 'remember' tax rate when adding new order totals field with specific tax to it. It will also reload all the order total modules and try to get all the sort orders right.

- I have put a lot of time on the shipping, payment and order totals modules to load and calculate their values correctly based on your input. This is not an easy task since there is a lot of modules out there that work very differently. E.g. Some payment modules add a cost and tax, but some don't. Some are dependent on the customer zone/country and others depend on which shipping modules that were selected and of course many depend on all these things and many more.

- Put simply, it will be almost impossible to get a perfect solution for all this, especially when quality standards on modules might differ. Worst case scenario is that you simply need to disable 'module handling' and manually input name and price for the order totals.

- All order fields should now be editable (including tax rate), one exception being the order number. You can however only change the tax rate to a rate that you have configured in your store. This is the only way to do this as osCommerce relies on data from the tax tables and adding custom tax would not be pretty..

- Total Products Purchased in order will now always be displayed.

- Simple Calculate Orders Totals button added.

- To select multiple rows - simply hold the SELECT key when selecting a second row, then all rows in between will be selected as well.

- Mail Confirmation should now work properly, including any email footer in the message. An important note however is that you should test this first by simply sending some mail to yourself to make sure they look OK.

- Error Handling - On Error the PHP will output an error header which will be caught by jQuery and translated to a Gritter Notification.

- Real time Progress will be displayed when updating/deleting orders using HTML5 ProgressEvent.

- jQuery code is now a Module Pattern instead of 100 anonymous functions..

- Ajax Long Polling for new orders should now work more smoothly.

- Navigation Bars and Modals have been moved to separate files

*** 21 Screenshots included in package! ***

Forum Support Link:

More... (http://addons.oscommerce.com/info/9055)