I’m using this package "darryldecode/cart"
for shopping cart functionality in laravel,
for adding items to cart using this method
Cart::session($userID)->add([
'id' => $productId,
'name' => $productDetails['name'],
'price' => $productDetails['price'],
'quantity' => $productDetails['quantity'],
'attributes' => [],
'associatedModel' => $productDetails,
]);
but i have doubt if user is not logged in then how we are going to add the items to cart and after user is logged then associate the product with logged in user Id.
Any solution Thanks
2
Answers
you can use a temp user make a cookie with the user token to assign the cart to him and if he login remove the user and reassign to the actual user
I believe if you associate that guest client with a session id, you can later get that guest client session id and associate with the newly logged session id
an example for that:
Then you need to handle those sessions and assosiate them with an account
I believe this can work in your project, If anything just ask and i’ll adapt the response to your actual code.
cheers.