how to manage shopping cart sessions without login


In MVC - In E commerce - how to add products in add to cart without Login and managed this session after Login and also show those products which are added before Login Like Flipkart and Amazon.

its very urgent for me because my site is delay for this.

 

Regard's

Hemant Modi 


Asked by:- HEMANTMODI
1
: 470 At:- 6/7/2017 4:57:23 PM
asp.net mvc sql javascript json

Hemant , can you use Sessions for this? Or it is not allowed? 0
By : vikas_jk - at :- 6/7/2017 5:07:42 PM





1 Answers
profileImage Answered by:- vikas_jk

Hemant, I have solution for you, maybe it is correct for your requirement

Step 1: If someone adds a product in shopping cart, save a cookie in user browser, you can use javascript/jquery to save cookie in users browser

function createCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}


$(document).ready(function(){

//Create Cookie for 1 year, when user add's a product
createCookie('ppkcookie','Unique_Guid',365);

//Save Cookie Unique_Guid in database, with product using ajax call

//getCookie
var x = readCookie('ppkcookie')
if (x) {
   // do something here, like load shopping cart products from database using ajax
}

})

Step 2: Save products in database with unique_id(if user add a product in cart), and fetch products from database where unique_id matches

Let me know if this work's for you, thanks

0
At:- 6/7/2017 5:53:41 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use