Post by amitn » Wed Sep 08, 2010 7:06 pm

Hi,

I want to make cart empty after user logs off. So when user logs in next time, I don't want user to see his last added items in cart.

How can I achieve this in code?

Thanks
Amit

New member

Posts

Joined
Mon Feb 08, 2010 2:10 pm

Post by scanreg » Wed Sep 08, 2010 7:35 pm

Would be neat if this could be targeted for specific products too

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by Miguelito » Wed Sep 08, 2010 7:40 pm

Isn't this already a feature in OpenCart? See the last line of this part of /catalog/controller/account/logout.php

Code: Select all

class ControllerAccountLogout extends Controller {
	public function index() {
    	if ($this->customer->isLogged()) {
      		$this->customer->logout();
	  		$this->cart->clear();

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by amitn » Wed Sep 08, 2010 7:48 pm

Miguelito wrote:Isn't this already a feature in OpenCart? See the last line of this part of /catalog/controller/account/logout.php

Code: Select all

class ControllerAccountLogout extends Controller {
	public function index() {
    	if ($this->customer->isLogged()) {
      		$this->customer->logout();
	  		$this->cart->clear();
I tried this but did not work. If user did not complete the order and logs off, in his next log in he sees last added products in cart.

New member

Posts

Joined
Mon Feb 08, 2010 2:10 pm

Post by amitn » Wed Sep 08, 2010 8:00 pm

Actually I have two order types: Pickup & Delivery.
Default is Pickup.
But when user selects products for Delivery order type and logs off without completing the order. Then in his next log in he sees last added items under order type Pickup.

That is why I want clear those old items or I can maintain a session for order type along with those items.

But i don't know where make these changes in code?

New member

Posts

Joined
Mon Feb 08, 2010 2:10 pm

Post by Qphoria » Wed Sep 08, 2010 8:05 pm

Yea it clears the cart, but the data is saved to the customer. You'd need to remove the serialized insert to the database when a product is added.

1. EDIT: system/library/customer.php

2. FIND AND COMMENT OUT:

Code: Select all

$this->db->query("UPDATE " . DB_PREFIX . "customer SET cart = '" . $this->db->escape(serialize($this->session->data['cart'])) . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->session->data['customer_id'] . "'");

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by amitn » Wed Sep 08, 2010 8:22 pm

Thanks a lot Qphoria.
It is working fine.

New member

Posts

Joined
Mon Feb 08, 2010 2:10 pm

Post by scanreg » Wed Sep 08, 2010 11:50 pm

Would there be a way to allow the customer to decide whether to save their cart?

Perhaps there could be a checkbox in the cart pages to save cart for later or something

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by edill3484 » Sun Sep 25, 2011 9:06 pm

Worked for me as well. Thanks!

Newbie

Posts

Joined
Tue Jun 21, 2011 7:41 pm
Who is online

Users browsing this forum: No registered users and 295 guests