laracart
laracart copied to clipboard
Give aiblity to use database instead of session
Will create a database version for those looking for it.
Is this what that migration was for? I see there's a migration with cart_session_id.
A nice feature would be following;
When a user is logged in (that exists in de database), and adds an item to his/her cart, and then leaves it would be saved to their account, so whenever they log back in, they have their cart filled up again fromout the data that has been saved.
That's basically what that does :-)
Unless they logout ><
I think that it would be nice to have the option to persist the session in the DB aswell. So if a user logs out and logs in to have the option to have that information in the DB aswell ;)
I dont think it would be to difficult, currently its loading it from the session data, we could serialize up the cart and produce the same results. Now for the proper way of doing it. Ill need to spend time actually designing the database migrations. Im currently working on a new project so it may be a couple of weeks before I can do this.
It would be a nice to, if you need an extra pair of hands I might be able to help you a bit. But don't worry about the timing at all. The library is already really good as it is.
Yah wouldn't mind some help on this if your up to the challenge.
@umbertix , can you either add me on skype or something ? Would like see how your thinking of doing this , feel free to add me : luke.a.policinski
If your on another timezone (im on est) Im willing to work around that as well.
And on that note have you seen the new docs ? http://laracart.lukepolo.com/
Nice jobs with the new docs, this library is great. I'm also interested in persistent carts. I'll play with it this week.
Take a look at the 2.0 branch, I think I started the database version , been swamped with a new project.
2.0 is highly not done though.
Nice, It's looking good. I will try to get into it and contribute soon.
Quick question related to the current method where the cart is stored in the session, is that information saved on the tmp folder in Linux? so if apache fails or the tmp folder is emptied all shopping carts would be lost?
How reliable using the session to store data is ?
Thanks!
So, what ever session your using as your default for laravel is being used to store that data.
For the reliability take a look at your session expires time and that is how reliable that is.
Ok, Now I understand. I just took a look at config/session.php
So it makes me feel better that this is currently saved by laravel using a file system. I could change the lifetime as a quick fix.
A better solution for now I think is serializing the cart content and saving that to the database and then unserialize it.
So I could save the contents of the cart by doing following:
$mycart = serialize(LaraCart::getItems()->toArray());
and then unserialize it and convert it back to a object (not sure how to do that yet, need to google it).
Thanks!
Sorry, I must have missed documenting something that is very useful here
https://github.com/lukepolo/laracart/issues/103#issuecomment-379557192
when you unserialize it , it will be an instance of Laracart ready for you to use.
@daniel-farina Only one big issue with this you will need to set it to the session manually, (if you want add it in and Ill accept it as a PR)
Read :
https://github.com/lukepolo/laracart/issues/103#issuecomment-379557192
Have you been able to make any progress on this? I was curious :)
I have not :-(. I've been working on too many projects as of late to finish this. I've started a 2.0 branch a year ago that could be a good starting point.
I am looking forward for this.
I think this is a good case for Abandoned Checkouts functionality.
I try the serialize and unserialize to use LaraCart object but it's not working. How can I load it as a LaraCart object ?
You say :
$this->session->set($this->prefix.'.'.$this->cart->instance, $this->cart);
But I have the entire object in a variable.
This should work :
Below : https://github.com/lukepolo/laracart/issues/103#issuecomment-379558802
Hi, thanks for your solution I try this :
session()->put(config('laracart.cache_prefix', 'laracart').'.default', json_decode($cart));
When I call Laracart via :
dd(LaraCart::getItems());
The result is an empty array. I think I must load the session in LaraCart object but how can I do ?
I try a json_encode and json_decode on the object cause serialize is not working event with SuperClosure package.
Ok got it to work :
$userCart =UserCart::firstOrNew([
'user_id' => \Auth::user()->id
]);
$userCart->fill([
'cart' => serialize(LaraCart::get()->cart)
]);
$userCart->save();
$cart = unserialize(\Auth::user()->cart->cart);
session()->put(config('laracart.cache_prefix').'.'.$cart->instance, $cart);
It's working perfectly, the key was the cart attribute of the returned method LaraCart::get(). Thanks for your help and your time !