Page 1 of 1

Clear compare

Posted: Wed Aug 24, 2011 12:17 am
by onlinephilately
Hi

How can I add a function so that the customer can clear his product compare list with one button "Clear all"?

Re: Clear compare

Posted: Wed Aug 24, 2011 1:32 am
by uksitebuilder
You will need to add a link to the compare.tpl that links to itself with a querystring like

index.php?route=product/compare&removeall=1

then in the compare controller add a conditional to unset all session data for compare

i.e.

if(isset($this->request->get[removeall'])){

foreach($this->session->data['compare'] as $key => $value){
unset($this->session->data['compare'][$key]);
}

$this->redirect($this->url->link('product/compare'));
}

Re: Clear compare

Posted: Wed Aug 24, 2011 1:23 pm
by onlinephilately
This worked perfect - thx!

The code had one typo so use this code:

Code: Select all

if(isset($this->request->get['removeall'])) {

			foreach($this->session->data['compare'] as $key => $value) {
				unset($this->session->data['compare'][$key]);
		}

		$this->redirect($this->url->link('product/compare'));
		}