0

I want to make an add to cart, until now I am still confused how to make it? do I have to use cookies or local storage? because so far I only understand a little using localstorage. I use vue.js using Vuex. what I hope is if the user presses the add to cart button it will be stored in local storage and can see it in the shopping cart.

i want to check if product:id and productsize id same in other index so give a warning or alert

IMAGE RESULT

NOTE : What am I doing right? if not please explain :(

Faris Dewantoro
  • 1,597
  • 4
  • 17
  • 31
  • 1
    And what is not working for you? Please post what you've tried that isn't working out. – Nicklas Kevin Frank Sep 11 '18 at 11:47
  • i dont know how to check 1 by 1 array if the data have same product:id and productsize:id @NicklasKevinFrank – Faris Dewantoro Sep 11 '18 at 11:48
  • You need to break down your problem. First learn how to access an array, then learn how to compare values, then how to iterate an array. Then build up the logic you want gradually. – Nicklas Kevin Frank Sep 11 '18 at 11:52
  • What I am confused about is how to make a shopping cart. in this problem it has been successful but, what if the stock in the database is not available, because only the data stored at localstorage is available at that time. @NicklasKevinFrank – Faris Dewantoro Sep 11 '18 at 12:59

2 Answers2

0

Using cookies is a good way to achieve this.

Laravel provides functionalities, you can find it there: https://laravel.com/docs/5.6/requests#cookies

thchem
  • 113
  • 1
  • 6
0

I think you can use both of the solutions,

but what is the difference between (local storage/cookie)?

local storage:: local storage stored data in client side only and you can't inject to it some options such as expiry date.

cookie: cookie stored data to the server by each request, and you can add the expiry date to it.

if you want to save it in both of side (client/server), we have a package for does it, it's implemented by vue and nuxt , you can use it,

https://github.com/alibaba-aero/nuxt-universal-storage

Hozhabr
  • 454
  • 2
  • 9
  • What I am confused about is how to make a shopping cart. in this problem it has been successful but, what if the stock in the database is not available, because only the data stored at localstorage is available at that time. – Faris Dewantoro Sep 11 '18 at 12:59