Azy Sır
Azy Sır

Reputation: 165

Custom Shopping Cart

I'm currently trying to create my own shopping cart for a client using JQuery. I was just wondering if the best way to store information for a custom cart is using cookies?

I have a product page that adds information via JQuery to Cookies and then a check out page that grabs the information from the cookies and display it on a check out page.

Is this the way to go about it, is there a better way?

Any help would be greatly apprecaited!

Upvotes: 0

Views: 140

Answers (2)

Nirmal Goswami
Nirmal Goswami

Reputation: 834

Cookies is also fine but LocalStorage is way to go to store cart related information on client side

Example

// Store
localStorage.setItem("lastname", "Smith");

//Get
localStorage.getItem("lastname");

//Remove
localStorage.removeItem("lastname");

Upvotes: 0

jeanj
jeanj

Reputation: 2166

In my opinion, the best to save a shopping card is server side:

Each time someone add a product send an AJAX request and store it (account if logged or use sessions).

It's a bit heavier but it's more secured, and more user friendly, if someone is shopping and don't have the time to checkout on his computer, he can grab his phone login and checkout with the same cart.

AJAX is not really hard as far as you know a bit about request. jQuery provide an AJAX function to send request you should start by this documentation.

An AJAX request is nothing more than a call to a page but instead of being synchron and then display the page to the user, it will asynchron, and just return a status and (in most case) a JSON object as response, to say how were the request if there was any errors or things like this. The backend wont be heavy so the request will be fast enough to be smooth to the user.

jQuery provide callback on error or success that allow you to easily manage to warn user or to update a cart preview without any page reloading or something.

Upvotes: 1

Related Questions