alexshimov Posted June 10, 2014 Share Posted June 10, 2014 Hi everyone! I have a lot of questions, ill start with a first one here. So I have virtual products only in my store, what i need is to check if a product is already added to the cart, because i want customer to be able only to add one of each product. And if product is already in the cart, than do nothing basically. This is the first question. And then the second one that comes from the first one: I can delete all the lines of code that display quantity on the website in the template, but how can I just disable this quantity, so that only one of each product can be added? Thank you! Link to comment Share on other sites More sharing options...
bellini13 Posted June 10, 2014 Share Posted June 10, 2014 Sounds like you need a little bit of customization to occur 1) You would likely want to override the CartController and add your logic to check quantity. The function processChangeProductInCart looks like this correct place. The Cart class has a function called containsProduct, so you could invoke this function and then cancel the add/update if the product is already in the cart. 2) You would want to revise the template files to remove or hide the quantity fields so it defaults to 1 quantity. You would also want to override CartController again for this, so it would ignore the quantity and always use 1. If you properly remove everything from template, then this is just added protection 1 Link to comment Share on other sites More sharing options...
alexshimov Posted June 10, 2014 Author Share Posted June 10, 2014 Sounds like you need a little bit of customization to occur 1) You would likely want to override the CartController and add your logic to check quantity. The function processChangeProductInCart looks like this correct place. The Cart class has a function called containsProduct, so you could invoke this function and then cancel the add/update if the product is already in the cart. 2) You would want to revise the template files to remove or hide the quantity fields so it defaults to 1 quantity. You would also want to override CartController again for this, so it would ignore the quantity and always use 1. If you properly remove everything from template, then this is just added protection Ok. Thank you. Ill try it n will come back with what i get after customization. Link to comment Share on other sites More sharing options...
ayin Posted October 3, 2014 Share Posted October 3, 2014 Sounds like you need a little bit of customization to occur 1) You would likely want to override the CartController and add your logic to check quantity. The function processChangeProductInCart looks like this correct place. The Cart class has a function called containsProduct, so you could invoke this function and then cancel the add/update if the product is already in the cart. 2) You would want to revise the template files to remove or hide the quantity fields so it defaults to 1 quantity. You would also want to override CartController again for this, so it would ignore the quantity and always use 1. If you properly remove everything from template, then this is just added protection With purpuse of learning, can how explain how it should be accomplished? Thanks Link to comment Share on other sites More sharing options...
ventura Posted October 4, 2014 Share Posted October 4, 2014 Try it with {if ($cart->containsProduct($product.id_product, $product.id_product_attribute))} Already in cart {/if} 2 Link to comment Share on other sites More sharing options...
ayin Posted October 6, 2014 Share Posted October 6, 2014 (edited) Try it with {if ($cart->containsProduct($product.id_product, $product.id_product_attribute))} Already in cart {/if} Hi Ventura, This works! Can you explain me why? 1. Where is defined the variable $Cart? 2. Where is defined the function containsProduct()? I checked the post: http://www.prestashop.com/forums/topic/342788-show-that-product-is-already-in-cart-on-the-product-list/ Thanks again : ) EDIT: Removed 2. Edited October 6, 2014 by ayin (see edit history) Link to comment Share on other sites More sharing options...
dusticelli Posted February 13, 2016 Share Posted February 13, 2016 Hi Folks, I have found this post, and probably you can help me with my issue: I want to hide a message that is given in my cart, when a selected product is in the cart. The above snippet seems to be quite near to my needs, but I dont now how to customize it correctly? The target is to have something like {if ($cart->containsProduct($product.id != 12)) }This is the message!{/if} But this one does not work. Thx for any help Link to comment Share on other sites More sharing options...
prostrona Posted August 25, 2016 Share Posted August 25, 2016 Works on 1.6.1 : in product.tpl <!-- check if you have this product in cart --> {$idproductincart = Tools::getValue('id_product')} {$idproductatrincart = Tools::getValue('id_product_attribute')} {if ($cart->containsProduct({$idproductincart}, {$idproductatrincart}))} <div class="alert alert-info">{l s='Already in cart'}</div> {/if} <!-- / check if you have this product in cart --> in product-list.tpl <!-- check if you have this product in cart --> {if ($cart->containsProduct($product.id_product, $product.id_product_attribute))}<div class="alert alert-info">{l s='Already in cart'}</div>{/if} <!-- / check if you have this product in cart --> 1 Link to comment Share on other sites More sharing options...
koening Posted May 22, 2017 Share Posted May 22, 2017 Hi! I have similar question. How to get info if product is in cart in javascript? Link to comment Share on other sites More sharing options...
koening Posted May 23, 2017 Share Posted May 23, 2017 Anyone can help? Link to comment Share on other sites More sharing options...
ronaldpsilva Posted June 1, 2019 Share Posted June 1, 2019 until version 1.6 I solved the problem in a very simple way.in the product.tpl file in THEMES, around line 311 I say this way: {if !$PS_CATALOG_MODE} {if ($product->is_virtual)==1} <p class="alert alert-warning" align="center">{l s='Virtual product. just add 1 item to Cart.'}</p> {else} <p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}> <label>{l s='Quantity:'}</label> <input type="text" name="qty" id="quantity_wanted" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}" /> <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down"> <span><i class="icon-minus"></i></span> </a> <a href="#" data-field-qty="qty" class="btn btn-default button-plus product_quantity_up "> <span><i class="icon-plus"></i></span> </a> <span class="clearfix"></span> </p> {/if} {/if} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now