Hello all,
I'm new to this forum so I apologize now if this post is in the wrong board.
I'm working on an extension that fires after save payment, before review on checkout. I've got everything as far as the module complete and I'm having an issue with overriding a method in the Payment class (in opcheckout.js).
The prior developer to me, simply added their own copy of the file with modified information, and commented out the original call for this file. This would not work as we'd like this to be done without needing any override or manual changes in .ptml files. I've already had to rewrite everything else used, and this is my last step in completing the extension.
I am attempting to use addMethods() from prototype, or wrap the function, however the original method is being called still (I have a console message in both functions).
The particular method I am trying to override is Payment.nextStep. I need to add an additional check within this function which incurs a pop-up to the user when JSON sends back error => popup (I am using popup1 to test)
Here is my code to override the function. It's found in a file opcheckoutmod.js included AFTER the original opcheckout.js.
PHP Code:
// Start addMethods(); to override Magento
if (typeof Payment !== 'undefined') {
Payment.addMethods({
nextStep: function(transport){
console.log('Here'); // Added to see if this runs
if (transport && transport.responseText){
try{
response = eval('(' + transport.responseText + ')');
}
catch (e) {
response = {};
}
}
if (response.error) {
if (response.error == 'popup1'){
// Run my code
}
}
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();
}
});
} // End addMethods();
I've not had any luck using this and I've included it both inline and within a separate file, but both times in DOM it shows the correct path to the function definition so it does not make sense why this original is being used.
The same occurs with prototype wrap, which an example is below:
PHP Code:
Payment.prototype.nextStep
= Payment.prototype.nextStep.wrap(function(parentMethod){
alert("hello world");
});
Does anyone have a clue as to what else is missing? I can provide access to see the site via PM if needed.
Thanks in advance!
View more threads in the same category:
Bookmarks