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?
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)");
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)");
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
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
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.
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?
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.
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
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.Any ideas what might be calling the function and deleting the cart items?
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.
Users browsing this forum: No registered users and 130 guests