Opencart add product to wishlist without login or creating an account

Opencart doesn’t allow you to add products into wishlist without login. You will find a message “You must login or create an account to save Apple cinema to your wishlist!”, when adding a products to wishlist. To solve above problem, follow below steps and add products to wishlist without creating or login in your account. I have posted this solution for opencart version 3.0.3.2 but it will works for all other version also.

Go to catalog/controller/account/wishlist.php and find below code at line 4 and delete it.

if (!$this->customer->isLogged()) {
	$this->session->data['redirect'] = $this->url->link('account/wishlist', '', true);
	$this->response->redirect($this->url->link('account/login', '', true));
}

Now find below code in same file wishlist.php at line 76.

if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
	$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
	$price = false;
}

and change with below code.

$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);

Now at the last find below code in your controller (same file) wishlist.php at line 132

if ($this->customer->isLogged()) {
     // Edit customers cart
     $this->load->model('account/wishlist');
     $this->model_account_wishlist->addWishlist($this->request->post['product_id']);
     $json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
     $json['total'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
} else {
     if (!isset($this->session->data['wishlist'])) {
	$this->session->data['wishlist'] = array();
      }
      $this->session->data['wishlist'][] = $this->request->post['product_id'];
      $this->session->data['wishlist'] = array_unique($this->session->data['wishlist']);
      $json['success'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', '', true), $this->url->link('account/register', '', true), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
      $json['total'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
}

and replace with below code.

$this->load->model('account/wishlist');
$this->model_account_wishlist->addWishlist($this->request->post['product_id']);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
$json['total'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());

Thats all, now you can add product in wishlist without login or creating an account.

Leave a Reply