Magento – AJAX Auto Update on One Step Checkout

ajaxcheckoutjavascriptmagento-1onepage-checkout

What code that trigger the ajax auto reload on payment method and order review on one step checkout?
is it on the

/skin/frontend/base/default/js/checkout/opcheckout.js

Best Answer

Yes this is the file.

This file contains JavaScript class definitions for the following:

  • Checkout
  • Billing
  • Shipping
  • ShippingMethod
  • Payment
  • Review

For each step you have a save method that does several things, including the AJAX call to the controller.

For example, for the ShippingMethod, this method looks like this:

save: function(){

    if (checkout.loadWaiting!=false) return;
    if (this.validate()) {
        checkout.setLoadWaiting('shipping-method');
        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)
            }
        );
    }
},

When the AJAX call is successfull, the code call the onSave binded event listener:

this.onSave = this.nextStep.bindAsEventListener(this);

The nextStep is the method that handle the AJAX response:

nextStep: function(transport){
    if (transport && transport.responseText){
        try{
            response = eval('(' + transport.responseText + ')');
        }
        catch (e) {
            response = {};
        }
    }

    if (response.error) {
        alert(response.message);
        return false;
    }

    if (response.update_section) {
        $('checkout-'+response.update_section.name+'-load').update(response.update_section.html);
    }

    payment.initWhatIsCvvListeners();

    if (response.goto_section) {
        checkout.gotoSection(response.goto_section, true);
        checkout.reloadProgressBlock();
        return;
    }

    if (response.payment_methods_html) {
        $('checkout-payment-method-load').update(response.payment_methods_html);
    }

    checkout.setShippingMethod();
}
Related Topic