On checkout ( billing page ) i want to add a condition like:
"if (something) { save billing info } else { save and go to next step}"

i tried to edit file opcheckout.js:

var Billing = Class.create();Billing.prototype = {
initialize: function(form, addressUrl, saveUrl){
    this.form = form;
    if ($(this.form)) {
        $(this.form).observe('submit', function(event){this.save();Event.stop(event);}.bind(this));
    this.addressUrl = addressUrl;
    this.saveUrl = saveUrl;
    this.onAddressLoad = this.fillForm.bindAsEventListener(this);
    this.onSave = this.nextStep.bindAsEventListener(this);
    this.onComplete = this.resetLoadWaiting.bindAsEventListener(this);
save: function(){
    if (checkout.loadWaiting!=false) return;

    var validator = new Validation(this.form);
    if (validator.validate()) {

        var request = new Ajax.Request(
                method: 'post',
                onComplete: this.onComplete,
                onSuccess:  this.onSave  ,
                onFailure: checkout.ajaxFailure.bind(checkout),
                parameters: Form.serialize(this.form)

I tried to change " this.onSave " to "function(){ if(true) { this.onSave; } }" to try if i can add a condition but after this change its not working - its not going to next step, i don't understand why

2 Answers 2


First to your answer. If you overwrite a function(-variable), you cant access the previous function, as its overwriting, not extending the "class"

For what you want, you can use the prototype.wrap() method. It allows you to wrap an own function call around the existing one.

for the case, someone uses a non prototype environment(which comes with some themes) here a link to a jquery equivalent:

If something in Javascript does not work as wished you need to be able to debug it, for having a better problem description.

so please read

Also you should know about scopes:

  • wrap() - great function, available in 1.7.2 only unfortunately :(
    – dchayka
    Mar 23, 2016 at 17:28

add this

var that = this;


var request = new Ajax.Request(...

then change the function you used to this:

function(){ if(true) { that.onSave; } }
  • Doesn't working , i also tried to add a new function in class " onSaveCustom: function(){ that.onSave } " and used " onSuccess: this.onSaveCustom()" but without success.
    – user4157
    Dec 24, 2013 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.