Bug fixing the eWay plugin for OpenCart

posted in: JavaScript, JQuery, OpenCart | 0

Last week, one my my clients changed their online payments processor to eWay, but the eWay plugin did not seem to work on the custom version of OpenCart which we had created from them.

Cutting to the chase, I eventually tracked the down a bug in the eWay plugin for OpenCart 1.5.x which had been caused by the use of a JQuery function that had been deprecated since JQuery 1.7.

I alerted eWay to the issue last week and it has been forwarded to their dev team, along with my fix; but at the time of writing, eWay have not released a new version of the plugin containing the fix, so I thought it was worthwhile publishing the fix here, in case anyone else has the same problem.

You can download the update version here eway-opencart-rapid-3-1-transparent-redirect-module-1.1.4-rogerclark.net


Some background..

We built a custom website for www.1300TonerInk.com.au starting development back in November 2014. TonerInk had already had some initial development produced by another company, using OpenCart V however it did not meet their needs as all.

The key criteria to selection of eCommerce solution was that it needed to have an existing payment gateway plugin for SecurePay, who are a division of Australia Post. And OpenCart had been chosen by the previous developers, and we agreed that this seemed a suitable choice for the client.

To make the site mobile friendly we used the oc-bootstrap theme which seemed to work fine, and development continued on and off until March 2015 when the site was given its soft launch.

Unfortunately it soon became clear that the SecurePay plugin for OpenCart had serious issues and did not work with V and the client opted to switch to using eWay as their payments processor.

But the eWay plug-in also failed to work on the site, with the plugin failing to render on the Checkout page.

Debugging was difficult, because the way OpenCart uses PHP files as template. No PHP errors were being logged or displayed on screen, but no output seemed to be rendered onto the page.

Just to complicate matters, the eWay plugin must be running on server via https (SSL) with a valid SSL certificate. So the only machine that it could be debugged on was the internet web server its self.

Eventually by a process of elimination, the error was tracked down to being in the Javascript code in the view code eWay.tpl, and on closer investigation, the code that handled the click event from the Confirm button seemed to cause the plug html not to be displayed at all.

On closer investigation, the function that was causing the error was live(); which I’d personally never used or even heard of, mainly because its been deprecated since JQuery 1.7!

The reason that the default install of OpenCart does not exhibit this problem, is that it uses JQuery 1.7, where although the function is deprecated, it was still present  Рas it didnt get removed until JQuery V1.9

The simple solution was to replace live() with on() as suggested in the JQuery API docs.  http://api.jquery.com/live/

To confirm whether this fix would be applicable to all versions of OpenCart 1.5 Рfor which the plugin was intended, I confirmed which version of JQuery 1.7 had the replacement function of on() http://api.jquery.com/on/  which it did, as it was introduced in JQuery 1.7 when live() was deprecated.

I’m hoping that eWay take this fix onboard, and hopefully credit me with finding and fixing, something which has been a possible issue since they originally wrote the plug, but at the time of writing I’m still waiting for feedback from their dev team or to see an updated version posted to the OpenCart Extensions page