Page 1 of 1
Opencart not clearing shopping cart
Posted: Sun Dec 04, 2016 1:36 am
by tt87
Opencart seems to save items in the shopping cart from previous shopping sessions. Is there an easy way to have shopping cart contents cleared after a certain amount of time? I have tried both extensions for this and neither of them work.
Version 2.0.3.1
Re: Opencart not clearing shopping cart
Posted: Sun Dec 04, 2016 1:56 am
by opencartmart
You mean logged customer shopping cart, right?
Re: Opencart not clearing shopping cart
Posted: Thu Dec 29, 2016 10:46 am
by tt87
Yes that is correct. Logged customer shopping cart
Re: Opencart not clearing shopping cart
Posted: Thu Dec 29, 2016 1:18 pm
by opencartmart
You can do it easily. In the file
system/library/cart/cart.php, find following line
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 1 HOUR)");
Above line basically remove all the expired carts with no customer ID. You can modify it for any customer. For example:
Code: Select all
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");
Re: Opencart not clearing shopping cart
Posted: Sun Jan 01, 2017 3:25 pm
by pipoy
This is actually interesting because my abandon cart module save the cart after every login by the customer.
Even when the abandon cart triggers the mail, then tomorrow when customer logs in, the products in cart are still there and abandon cart will save them once again.
@opencartmart
Will work on 2.1.0.2?
thanks!
Re: Opencart not clearing shopping cart
Posted: Sun Jan 01, 2017 3:29 pm
by opencartmart
I am not sure about working with abandon cart module. It depends how abandon cart module works actually.
Re: Opencart not clearing shopping cart
Posted: Sun Jan 01, 2017 6:54 pm
by pipoy
Well there is only 1 way to find out.
Using your query. Is there a way to make it in seconds or in minute interval only?
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");
Re: Opencart not clearing shopping cart
Posted: Sun Jan 01, 2017 8:35 pm
by opencartmart
Yes you can use MINUTE or SECOND instead of DAY but what is the point?
Re: Opencart not clearing shopping cart
Posted: Sun Jan 01, 2017 11:18 pm
by pipoy
to test if it really got cleared so I do not have to wait 1 hour
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 12:02 am
by tt87
do you put this query in a php file or where?
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 12:39 am
by opencartmart
The above solution will work for OC version > 2.1, for other version, you can do following
in the file
system/library/customer.php, You can replace following line
Code: Select all
$cart = unserialize($customer_query->row['cart']);
by
Thanks
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 1:41 am
by tt87
Thanks, what exactly does this change do?
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 2:02 am
by opencartmart
It will clear customer old cart whenever he/she login
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 2:32 am
by tt87
I just tried it and it didnt work.
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 3:19 am
by tt87
Could I insert this line below this code?
$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1' AND approved = '1'");
}
$this->db->query("UPDATE " . DB_PREFIX . "customer SET cart = ''");
Re: Opencart not clearing shopping cart
Posted: Mon Jan 02, 2017 2:03 pm
by opencartmart
Can you share your code? Have you replaced correctly?
Re: Opencart not clearing shopping cart
Posted: Fri Apr 14, 2017 9:25 pm
by mrnet
opencartmart wrote: ↑Thu Dec 29, 2016 1:18 pm
You can do it easily. In the file
system/library/cart/cart.php, find following line
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 1 HOUR)");
Above line basically remove all the expired carts with no customer ID. You can modify it for any customer. For example:
Code: Select all
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");
Thank you! This worked for me!
Re: Opencart not clearing shopping cart
Posted: Thu May 04, 2017 11:37 pm
by opencartmart
Glad to hear. Thanks
Re: Opencart not clearing shopping cart
Posted: Fri May 05, 2017 1:01 am
by IP_CAM
opencartmart wrote:in the file
system/library/customer.php, You can replace following line
Code: Select all
$cart = unserialize($customer_query->row['cart']);
by
worked on spot in my OC v.1.5.6.5_rc Version, just to mention it!
Ernie
