Post by Ctsimpos » Mon Mar 25, 2019 6:11 pm

Hello all

I just realized that items in opencart cart get delete once every hour with the below query

$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");

Unfortunately because of the way the query works if I add 3 products in my cart with 5 minutes interval between them and return in one hour to the page two of them will be there and one will be deleted. The query deletes products from basket based on their individual timestamps. I think that's far from ideal. Its one thing to delete everything from a basket and another to mess with someone's basket like that.

How could one extend the time items stay in the cart to say 24hrs?Would simply changing the INTERVAL above do it? or do we need to change settings somewhere else as well?

Newbie

Posts

Joined
Fri Aug 12, 2016 6:00 pm


Post by xxvirusxx » Mon Mar 25, 2019 6:18 pm

Ctsimpos wrote:
Mon Mar 25, 2019 6:11 pm

How could one extend the time items stay in the cart to say 24hrs?Would simply changing the INTERVAL above do it?
Should work

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 24 HOUR)");
or

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 48 HOUR)");

Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - RO

Post by Ctsimpos » Mon Mar 25, 2019 6:35 pm

thank you for your kind and prompt answer

When/How often is public function __construct($registry) { } called?

That's the one which includes the above cart command and would like to get an idea when it resets.

1) server reboot?
2) apache restart?
3) other function calls it?

many thanks

Newbie

Posts

Joined
Fri Aug 12, 2016 6:00 pm


Post by letxobnav » Mon Mar 25, 2019 7:54 pm

I would guess every page request.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Active Member
Online

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Ctsimpos » Mon Mar 25, 2019 7:55 pm

Something really odd going on

I have now amended to 12 hours and restarted server but still the cart empties after one hour. I’m using journal and cleared cache

Any ideas what might be calling the function and deleting the cart items?

Newbie

Posts

Joined
Fri Aug 12, 2016 6:00 pm


Post by letxobnav » Tue Mar 26, 2019 12:14 am

no need for cleaning anything, just set it to 10 SECOND and see the items disappear very quickly.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Active Member
Online

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by ogun » Mon Apr 01, 2019 8:27 am

If you want to change the behaviour (so it deletes the whole cart instead of one item at a time) then you'll need to group the delete by the session_id with something like:

Code: Select all

DELETE oc_cart
FROM oc_cart JOIN (
  SELECT session_id
  FROM oc_cart
  WHERE (api_id > '0' OR customer_id = '0')
  GROUP BY session_id
  HAVING MAX(date_added) < DATE_SUB(NOW(), INTERVAL 1 HOUR)
 ) AS x
 ON oc_cart.session_id = x.session_id
Have made a mod (attached) that does that and it seems to work. That said, it's only had a very quick test and the query could probably do with being optimised.

Any ideas what might be calling the function and deleting the cart items?
Where are you making your changes? It might be that a mod or extension you have installed is modifying system/library/cart/cart.php and somehow causing your changes to be overwritten/ignored.

If you want to make a temporary change (just for testing/debugging etc,.) to a file that's been affected by an extension/modification, you'll need to edit the modified copy of that file in your 'storage/modification' dir rather than editing the actual file. Note that your changes will be lost the moment you click 'refresh' in the 'Modifications' section of the admin panel, when everything in 'storage/modification' will be regenerated.

Attachments

This mod empties the whole cart for visitors if the most recent item in their cart is more than an hour old.


Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am
Who is online

Users browsing this forum: paulfeakins and 30 guests