0

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()) {
        checkout.setLoadWaiting('billing');

        var request = new Ajax.Request(
            this.saveUrl,
            {
                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

3

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.
http://prototypejs.org/doc/latest/language/Function/prototype/wrap/

for the case, someone uses a non prototype environment(which comes with some themes) here a link to a jquery equivalent:
https://stackoverflow.com/questions/5258829/wrapping-a-function-in-javascript-jquery

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
https://developers.google.com/chrome-developer-tools/docs/javascript-debugging

Also you should know about scopes:
https://stackoverflow.com/questions/500431/javascript-variable-scope

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

add this

var that = this;

before

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 '13 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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