I'm working on an extension for Magento and need to wrap a method (nextStep) in the Payment class of opcheckout.js
In my JS file, loading after the original checkout.js file, I have tried many variations of the following code, but none seem to work. The object definitely exists however.
Payment.prototype.nextStep
= Payment.prototype.nextStep.wrap(function(parentMethod){
alert("hello world");
});
I've also tried Payment.addMethod and replaced the method completely with my own, but this did not work.
Essentially in this method, I need to add a check to see if the JSON response 'error' comes back with a specific value that I define in my observer event. For the sake of the example, it returns like this:
"error" => "popup1"
Here is the nextStep function and a little idea of what I need. My code is added between the comments
nextStep: function(transport){
if (transport && transport.responseText){
try{
response = eval('(' + transport.responseText + ')');
}
catch (e) {
response = {};
}
}
/* START MY CODE - Need code added here as shown below */
if (response.error) {
if(response.error == 'popup1'){
// my code
}
}
/* END MY CODE */
/*
* if there is an error in payment, need to show error message
*/
if (response.error) {
if (response.fields) {
var fields = response.fields.split(',');
for (var i=0;i<fields.length;i++) {
var field = null;
if (field = $(fields[i])) {
Validation.ajaxError(field, response.error);
}
}
return;
}
alert(response.error);
return;
}
checkout.setStepResponse(response);
//checkout.setPayment();
},
This is the last issue in making my extension installable and the developer prior to me simply commented out the base opcheckout.js file and loaded a modified version which is not acceptable.
Any pointers? Suggestions?
Thanks