Extension for redirecting to cart page when user logs in from checkout page.
Code snippet:
define(
'JJ.CheckoutLogin_custom.checkoutLogin'
, [
'LoginRegister.Login.View',
'Configuration',
'Profile.Model',
'Utils',
'LiveOrder.Model',
'Backbone.FormView',
'Backbone.View',
'Session',
'underscore'
]
, function (
LoginRegisterLoginView,
Configuration,
ProfileModel,
Utils,
LiveOrderModel,
BackboneFormView,
BackboneView,
Session,
_
)
{
'use strict';
return {
mountToApp: function mountToApp(container) {
{
_.extend(LoginRegisterLoginView.prototype, {
refreshApplication: function (response) {
const current_language = Session.get('language.locale');
const {application} = this;
// @class LoginRegister.LoginResponseData
// @property language {locale:String} language
console.log("testtcheckoutlogin", response);
if (
response.language &&
response.language.locale &&
current_language !== response.language.locale
) {
window.location.href = response.touchpoints.viewcart;
} else {
const profile_model = ProfileModel.getInstance();
console.log("testtcheckoutlogin_else")
// @property {String} user serialized JSON user information
response.user && profile_model.set(response.user);
// @property {String} cart serialized JSON cart information
response.cart && LiveOrderModel.getInstance().set(response.cart);
// @property {String} address serialized JSON addresses information
response.address && profile_model.get('addresses').reset(response.address);
// @propert••••••••y {String} credit-card serialized JSON creditcards information
response.paymentmethod &&
profile_model.get('paymentmethods').reset(response.paymentmethod);
// @property {core:String} currency
response.currency &&
response.currency.code &&
Session.set('currency', response.currency);
// @property {Object} touchpoints
console.log('response.touchpoints', response.touchpoints.viewcart)
//this line is to redirect the login page on the checkout into the cart
window.location.href = response.touchpoints.viewcart
}
}
})
}
}
}
});