Page 1 of 1
( ✔ In your Cart ) on List/Grid/Product - an extension for this ?
Posted: Thu Nov 23, 2017 12:13 am
by gunner86
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 ...
Re: ( ✔ In your Cart ) on List/Grid/Product - an extension for this ?
Posted: Thu Nov 23, 2017 5:11 am
by straightlight
Which OC version are you using?
Re: ( ✔ In your Cart ) on List/Grid/Product - an extension for this ?
Posted: Fri Nov 24, 2017 12:08 am
by gunner86
OC 2.2.0.0
Re: ( ✔ In your Cart ) on List/Grid/Product - an extension for this ?
Posted: Fri Nov 24, 2017 12:16 am
by straightlight
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?
Re: ( ✔ In your Cart ) on List/Grid/Product - an extension for this ?
Posted: Fri Nov 24, 2017 1:28 am
by gunner86
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 ...
Re: ( ✔ In your Cart ) on List/Grid/Product - an extension for this ?
Posted: Fri Nov 24, 2017 2:14 am
by straightlight
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:
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:
section, find:
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">×</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">×</button></div>');
}
This should provide what you need.