Post by gunner86 » Thu Nov 23, 2017 12:13 am

i looked for an extension like this , but i couldnt find any ...
on grid , list and product page a sign if becomes the cumstomer wont check the same products again ... is here any extension for this ? thanks ...

New member

Posts

Joined
Wed Jul 09, 2014 3:43 pm

Post by straightlight » Thu Nov 23, 2017 5:11 am

Which OC version are you using?

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by gunner86 » Fri Nov 24, 2017 12:08 am

OC 2.2.0.0

New member

Posts

Joined
Wed Jul 09, 2014 3:43 pm

Post by straightlight » Fri Nov 24, 2017 12:16 am

Based on your first post, what happens if you'd like to restrict the product so the product can be viewed once but the customer is also a guest customer?

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by gunner86 » Fri Nov 24, 2017 1:28 am

it will be usefull , when the customer searching a product on category page , wont add the product twice ... he will see the mark that the product in the cart and wont add again ...

New member

Posts

Joined
Wed Jul 09, 2014 3:43 pm

Post by straightlight » Fri Nov 24, 2017 2:14 am

Then, it is cart based - not from the list/grid product page. The subject of your topic has the wrong analogy. A tweak to accomplish this would be by editing your system/library/cart/cart.php file.

Find:

Code: Select all

public function hasProducts() {
add above:

Code: Select all

public function hasProduct($product_id) {
		$products = $this->getProducts();

		foreach ($products as $product) {
			if ((int)$product_id == (int)$product['product_id']) {
			    return true;
			}
		}
	}
Then, in your catalog/controller/checkout/cart.php file,

find:

Code: Select all

if (isset($this->request->post['quantity'])) {
				$quantity = (int)$this->request->post['quantity'];
			} else {
				$quantity = 1;
			}
add below:

Code: Select all

if ($this->cart->hasProduct($product_info['product_id'])) {
				$json['error']['same_product'] = sprintf($this->language->get('text_same_product'), html_entity_decode($product_info['name'], ENT_QUOTES, 'UTF-8'));
			}
Then, find:

Code: Select all

foreach ($this->request->post['quantity'] as $key => $value) {
				$this->cart->update($key, $value);
			}
replace with:

Code: Select all

$this->load->model('catalog/product');
			
			foreach ($this->request->post['quantity'] as $key => $value) {
				$product_info = $this->model_catalog_product->getProduct($key);
				
				if ($product_info && $this->cart->hasProduct($product_info['product_id'])) {
					$json['error']['same_product'] = $this->language->get('text_same_product');
				}			
			}
In your catalog/language/<your_language_code>/checkout/cart.php file,

add at the bottom:

Code: Select all

$_['text_same_product'] = 'The product name: %s has already been added to your cart.';
Then, in your catalog/view/javascript/common.js file,

in the:

Code: Select all

var cart = {
section, find:

Code: Select all

if (json['redirect']) {
add above:

Code: Select all

if (json['error']['same_product']) {
					$('#content').parent().before('<div class="alert alert-danger alert-dismissible">' + json['error']['same_product'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
				}
Then, in the

Code: Select all

'update': function(key, quantity) {
find:

Code: Select all

if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
add above:

Code: Select all

if (json['error']['same_product']) {
					$('#content').parent().before('<div class="alert alert-danger alert-dismissible">' + json['error']['same_product'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
				}
This should provide what you need.

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 12 guests