Delete database data after 20 minutes

Asked

Viewed 49 times

1

Colleagues.

I’m finishing a virtual store, but the customer will work with stocks. The proposal is that after 20 minutes of idleness of this user, the products are automatically excluded from the cart so the stock does not get stuck in a cart abandonment.

The data deletion I am doing by PHP and so far everything is ok. I also managed by Cpanel to configure the cron task for my PHP script.

The entries of the cart, I am storing the date in the DATETIME() field, as I would to compare the date field with another 20 minutes and after that run the exclusion query?

I thought of something like that:

SELECT DataAbertura, ADDTIME( DataAbertura,  '1 0:20:0:0.0000' ) AS DataVinte
FROM  `loja
  • 4

    The correct thing is for all the code to be on your server and run by a cron. But here, I’ll make a suggestion. Do not delete the data. Use a flag to mark that this product is again available, but leave the die there in the bank. This is a strategy to allow the store to offer the same product later if the customer has not bought. If you delete, this information may be lost.

  • Hello Eduardo. I agree with you about not deleting the data from the bank, but the customer unfortunately has no interest in offering the same product to the customer in case of abandonment of the cart.

  • Seriously? what kind of business is it that has no interest to sell if it is not co prado in 20min? What if the user access from another machine? or if you want to be logged in?

  • It is because it works with few Celsom stocks and unfortunately the customer is always right, however much we show him the correct solution. But the client’s decision is not the merit of the post.

  • @Yes, but that’s why I asked other questions. How do you do this check? Because if I’m not logged in, you don’t know who I am, or if I access from another machine, my data won’t be on storage.

  • Some colleagues store their cart products in sessions/cookies until the purchase is complete. I store in a database table and use the same reasoning of eduardosouza, but as far as I know, it is impossible to see from another machine the shopping cart without being logged in, I do not see how. Open any online store, place a purchase in the cart, then open another browser and access the same online store. You will see that your cart will be empty. But sign up and access it. Some stores store the cart in BD sessions. I use the second option.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.