Delivery Methods Not Appearing in One Page Checkout

In some cases, not all delivery methods appear when using the One Page Checkout flow. This issue sometimes occurs after a user enters a zip code when checking out as a guest.

To correct this error, extend the mountToApp() method located in the CheckoutSkipLogin.js file and hide the following line within comment tags:

data.cart && LiveOrderModel.getInstance().set(data.cart);

In addition to making these changes, you must create an ns.package.json file and update your distro.json file for any custom modules you include. You can download the code samples described in this procedure here: OnePageCheckoutDeliveryMethodsPatch.zip.
js code :

define(
   'CheckoutSkipLogin.Extension'
,   [

      'CheckoutSkipLogin'
   ,   'Account.RegisterAsGuest.Model'

   ,   'jQuery'
   ,   'underscore'
   ]

,   function (
      CheckoutSkipLogin
   ,   AccountRegisterAsGuestModel

   ,   jQuery
   ,   _
   )

{

   'use strict';

      _.extend(CheckoutSkipLogin.prototype,
      {

         mountToApp: function(application)
         {
            // do nothing if the mode is disabled
            if (!application.getConfig('checkout.skipLogin'))
            {
               return;
            }

            //this function is called only if skip login mode is enabled
            var registerUserAsGuest = function ()
            {
               var promise = jQuery.Deferred()
               ,   profile_model = ProfileModel.getInstance();
               if (profile_model.get('isGuest') === 'F' && profile_model.get('isLoggedIn') === 'F')
               {
                  var checkoutStep = application.getLayout().currentView.currentStep;

                  checkoutStep && checkoutStep.disableNavButtons();

                  new AccountRegisterAsGuestModel().save().done(function(data)
                  {
                     var skipLoginDontUpdateProfile = profile_model.get('skipLoginDontUpdateProfile');

                     if(skipLoginDontUpdateProfile && data.user)
                     {
                        _.each(skipLoginDontUpdateProfile, function(attr)
                        {
                           delete data.user[attr];
                        });
                     }

                     data.user && profile_model.set(data.user);
                     application.getLayout().currentView.wizard.options.profile = profile_model;
                     //data.cart && LiveOrderModel.getInstance().set(data.cart);
                     data.touchpoints && (application.Configuration.siteSettings.touchpoints = data.touchpoints);
                     promise.resolve();
                     checkoutStep && checkoutStep.enableNavButtons();
                     jQuery('[data-action="skip-login-message"]').remove();
                  });
               }
               else
               {
                  promise.resolve();
               }
               return promise;
            };

            // add 'this.application' to models that doesn't have it.
            AddressModel.prototype.application = application;
            CreditCardModel.prototype.application = application;
            ProfileModel.prototype.application = application;

            // wrap save() method to LiveOrderModel, AddressModel and CreditCardModel
            var wrapper = function(superFn)
            {
               var self = this
               ,   super_arguments = Array.prototype.slice.apply(arguments, [1, arguments.length])
               ,   promise = jQuery.Deferred();

               if (!promiseGuest)
               {
                  promiseGuest = registerUserAsGuest();
               }

               promiseGuest.done(function ()
               {
                  var result = superFn.apply(self, super_arguments);

                  if (result)
                  {
                     result.done(function ()
                     {
                        promise.resolve.apply(result, arguments);
                     }).fail(function()
                     {
                        promise.reject.apply(result, arguments);
                     });
                  }
                  else
                  {
                     // Notify future promises that a front end validation took place and no promise is returned
                     promise.frontEndValidationError = true;
                     promise.reject.apply(result, super_arguments);
                  }
               });

               _(promise).extend({error: function(){return this;},success: function(){return this;}});

               return promise;
            };

            // don't wrap on non-secure domains (Site Builder cart is in Checkout :/ )
            if (window.location.protocol !== 'http:')
            {
               LiveOrderModel.prototype.save = _.wrap(LiveOrderModel.prototype.save, wrapper);
            }

            AddressModel.prototype.save = _.wrap(AddressModel.prototype.save, wrapper);

            CreditCardModel.prototype.save = _.wrap(CreditCardModel.prototype.save, wrapper);

            ProfileModel.prototype.save = _.wrap(ProfileModel.prototype.save, wrapper);
         }

      });
});

Leave a comment

Your email address will not be published. Required fields are marked *