Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reserve & expire quantity when adding items to the cart? #147

Open
amitshrestha221 opened this issue Feb 1, 2022 · 4 comments
Open
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@amitshrestha221
Copy link

For some reasons, I have a requirement of expiring the cart in 5 minutes. I didnt find it in config/cart.php.
Is there any option for this?

@bumbummen99
Copy link
Owner

Can you elaborate more on the expire part? What exactly do you mean by "expiring the cart" and how will the timeout be renewed?

Out of my head and assuming i am correctly understanding the question i would do something like the following:

  • Write an "accessor" for the cart to wrap it into with your identifier as parameter
  • Before returning the cart instance, check if it is older than 5 min by setting some variable using the Cache facade
  • Cart in DB also has nullableTimestamps so you could use that to once and a while check for Carts that are overdue and delete them with a single query to remove unneccessary data

Maybe you could also do this by using the service container.

@amitshrestha221
Copy link
Author

Sir actually the scenario is this :

I am using this package for a canteen system to order items. My requirement was upon adding to cart, my stock gets reduced. So, if one person adds to the cart and goes idle, the item would be reserved for until session expires.

That's why I need to expire the cart in 5 minutes and invoke a action that could restock the items. I am planning to move ahead with the database part as you said.

@bumbummen99
Copy link
Owner

There is one issue with this that comes to my mind: The cart content is stored in the session or in the database (in a single row) so you can not do a query to determine the correct, avaliable qty to display on the product page. If the content of the cart was DB only the available qty would simply be qty - sum(qty) of all CartItem positions in DB. With the solution above you would need to check all carts to get the total qty currently in use by other carts. This is also a reason why this package is not good to use with API (since the lack of session).

@bumbummen99 bumbummen99 added enhancement New feature or request help wanted Extra attention is needed labels Feb 2, 2022
@bumbummen99 bumbummen99 changed the title How to expire expire in 5 mins? How to reserve & expire quantity when adding items to the cart? Feb 2, 2022
@amitshrestha221
Copy link
Author

@bumbummen99 sir I thought of a workaround :

So, I am planning to remove cart from the session data located inside storage/framework/sessions___ file.
I am trying to track user's session_id in a virtual table along with every cart add/update and then on basis of that session_id with cart_updated_time.
I am trying to run a cron job, which upon created every 5 minutes, IF NOT COMPLETED THE ORDER, will restock the quantity of the items and remove cart data from the user's session file based upon that same session_id.

Problem is I stored the session_id of the user and everything is working well, I am having trouble retreiving user's session data based on the session_id, could you suggest any mechanism for this?



$session = session();
dd($session);

I got this random sesison ID EE7868eFef...

This file exists in storage/framework/sessions/____

I want the content of that file using sessionID. Because I need to access that session data using cron job.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants