melihovv / laravel-shopping-cart

Laravel shopping cart package
MIT License
73 stars 29 forks source link

Can we use in stateless environment? #6

Closed shirshak55 closed 5 years ago

shirshak55 commented 5 years ago

I wonder who cart is saved . Is it per user ?

Cart::add(1, 'iPhone 7', 500, 1);
Cart::add(1, 'iPad Pro', 700, 2);
Cart::getTotal(); // return 1900

Cart::getTotal() gets total from which cart because we know there can be 100 users each having a cart?

Plz let me know if it is stateless i would like to read code too :)

by stateless i mean just using rest api without session

melihovv commented 5 years ago

By default card is saved with "default" prefix.

Cart::currentInstance(); // default
Cart::instance($user->id)->currentInstance(); // will return user id
melihovv commented 5 years ago

Yeah, this package doesn't depend on session or anything like that.

shirshak55 commented 5 years ago

@melihovv lets say there are 10 users each having cart. by logic Cart::currentInstance(); which is default should all be different for different user right? I just wanted to know how are they stored in redis. Are they based on userid or what .

melihovv commented 5 years ago

It is stored per what you pass to store() method.

Cart::store()
Persist current shopping cart instance to storage.

Cart::store($user->id);
Cart::instance('cart')->store($user->id);
Cart::instance('wishlist')->store($user->id);