sm3004 Posted February 5, 2010 Share Posted February 5, 2010 I am trying to have a text display sold out on the products that have 0 items left. I sell items with different attributes and I want it to say Sold Out underneath the add to cart button when all the attributes of that items has sold out.I tried using this code on the product.tpl page underneath the add to cart button: {if $product->quantity == 0} {l s='SOLD OUT!'} {/if} but it is not working. It is still saying sold out on items that have stock available.Anybody know how to do this properly? Link to comment Share on other sites More sharing options...
sm3004 Posted February 5, 2010 Author Share Posted February 5, 2010 Instead of the code above, I used: {if !$id_attribute } {l s='SOLD OUT!'} {/if} But this only works when the items are stocked using combinations (attributes)...We also sell belts, where we enter stock in the "1. Info" tab in the back office, and on these items, the code displays SOLD OUT! even though there are items in stock... Link to comment Share on other sites More sharing options...
sm3004 Posted February 5, 2010 Author Share Posted February 5, 2010 Does anybody know why {if $product->quantity == 0} {/if} isn't working at all on the products page? how do i display the sold out button to work on items with attributes and without if the quantity is ZERO??Please help! Link to comment Share on other sites More sharing options...
rocky Posted February 6, 2010 Share Posted February 6, 2010 That's odd. I just tried reducing the quantity of the iPod Shuffle on my test site from 100 to 90, but $product->quantity still has the value 100. I guess it isn't being updated for some reason. Here's some code you can put in product.tpl to manually count the attribute quantity: {assign var='quantity' value='0'} {foreach from=$combinations key=idCombination item=combination} {assign var='quantity value=$quantity+$combination.quantity} {/foreach} Then you can use the following code: {if $quantity == 0} {l s='SOLD OUT!'} {/if} Link to comment Share on other sites More sharing options...
sm3004 Posted February 6, 2010 Author Share Posted February 6, 2010 How do I count the quantity of products that don't use attributes (combinations)??I tried the code you posted above this comment, but it still displays Sold Out on items that have stock entered via the "1. Info" tab. Link to comment Share on other sites More sharing options...
rocky Posted February 6, 2010 Share Posted February 6, 2010 You are right. Try the following code instead: {if $product->quantity == 0 AND $quantity == 0} {l s='SOLD OUT!'} {/if} Link to comment Share on other sites More sharing options...
sm3004 Posted February 6, 2010 Author Share Posted February 6, 2010 Sorry to report that one doesn't work either, it doesn't display any items as being sold out even though I have one item that it definitely should apply to. Thanks for trying. Link to comment Share on other sites More sharing options...
rocky Posted February 6, 2010 Share Posted February 6, 2010 That's odd. It should work, unless Prestashop is reporting the quantity as more than 0 when all the attributes actually do add up to 0. Try the following: {if (isset($groups) AND $quantity == 0) OR (!isset($groups) AND $product->quantity == 0)} {l s='SOLD OUT!'} {/if} Link to comment Share on other sites More sharing options...
sm3004 Posted February 6, 2010 Author Share Posted February 6, 2010 Works great! Been trying to fix that bug for days, it's haunting my dreams.Hooray for Rocky!! Link to comment Share on other sites More sharing options...
rocky Posted February 6, 2010 Share Posted February 6, 2010 I'm glad I could help. Link to comment Share on other sites More sharing options...
netmechanics Posted February 22, 2010 Share Posted February 22, 2010 Hiya - I am trying to do a similar thing in homefeatured.tpl in the homefeatured module - should this work there to? (it doesn't :-) ... yet). {if ($product->quantity == 0)} {l s='SOLD OUT!'} {/if} Link to comment Share on other sites More sharing options...
netmechanics Posted February 22, 2010 Share Posted February 22, 2010 Solved - this works...{if ($product.quantity == 0)} {l s='SOLD OUT!'} {/if}Duh ... $product.quantity of course :-) Link to comment Share on other sites More sharing options...
persephonevintage Posted March 25, 2010 Share Posted March 25, 2010 i hope someone on this list can help me! i'm trying to do something similar. i have a store where there is only one of each item and i would like to display a “sold out” in place of the price in the product category list. i’ve already done this for the individual product listings using the instructions here. any help is appreciated. thanks! Link to comment Share on other sites More sharing options...
netmechanics Posted March 26, 2010 Share Posted March 26, 2010 Hiya - You just need to do the same in the category listing template ... if you mean something similar to this ? www.loopcase.com Link to comment Share on other sites More sharing options...
persephonevintage Posted March 26, 2010 Share Posted March 26, 2010 yes, just like that! which code do i put where? thanks in advance! Link to comment Share on other sites More sharing options...
persephonevintage Posted March 27, 2010 Share Posted March 27, 2010 i tried putting this code{if ($product.quantity == 0)}{l s=‘SOLD OUT!’}{/if}in product-list.tpl but a blank page just results. i think i am putting it in the right place. does anyone know what the right code is? help is much appreciated. Link to comment Share on other sites More sharing options...
EarlMax Posted March 28, 2010 Share Posted March 28, 2010 when using this <!--- sold out -->{if (isset($groups) AND $quantity == 0) OR (!isset($groups) AND $product->quantity == 0)} {l s='SOLD OUT!'} {/if} on my shop i get a constant sold out 1 Link to comment Share on other sites More sharing options...
bighenry Posted July 25, 2010 Share Posted July 25, 2010 That's odd. It should work, unless Prestashop is reporting the quantity as more than 0 when all the attributes actually do add up to 0. Try the following: {if (isset($groups) AND $quantity == 0) OR (!isset($groups) AND $product->quantity == 0)} {l s='SOLD OUT!'} {/if} Hi RockyThis does not appear to work for the latest version 1.3Any work around for it please?It would be good for me re a previous post of mine 'Coming Soon'Many thanks Link to comment Share on other sites More sharing options...
mecollectibles Posted May 6, 2011 Share Posted May 6, 2011 There are many posts but would anybody say what should be at last as the final step including all changes that should be done? Link to comment Share on other sites More sharing options...
cast Posted August 10, 2011 Share Posted August 10, 2011 Hi Rocky, I'm having a trouble when put this code inside product-list.tpl: {if $product.allow_oosp OR $product.quantity > 0} <p class="price"> {if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if} </p> {else} <p class="price">SOLD OUT</p> {/if} This code showing 2 kinds of errors : 1. Many products showing "Sold Out" even it doesn't have any attributes and the quantity is still enough to order. 2. For the products with attributes, if the main attributes' qty is 0, then it shows "Sold Out" in product-list.tpl, so I have to select another attributes to be primary one, and the problem's solved for this part. But it doesn't have to be done manually, right? The question is (probably gonna solve the problems)... Is it possible to change the $product.quantity to SELECT data from product id in "product" table that still has a quantity > 0, because I think this code somehow selecting the quantity from "product_attribute" table. Please help me solve this problem asap, or anybody has any advices? Thank you! Link to comment Share on other sites More sharing options...
devein Posted November 12, 2013 Share Posted November 12, 2013 my solution, based on other contributions and my ideas prestashop 1.4. for categories display: product-list.tpl inside of this loop: {foreach from=$products item=product name=products} put this: {if (!isset($product.quantity_all_versions) AND $product.quantity == 0) OR (isset($product.quantity_all_versions) AND $product.quantity_all_versions == 0)} sold out! {/if} for single item display: product.tpl below </script> insert counter: {assign var='quantity' value='0'} {foreach from=$combinations key=idCombination item=combination} {assign var='quantity' value=$quantity+$combination.quantity} {/foreach} and for example after: <span class="our_price_display"> {if (isset($groups) AND $quantity == 0) OR (!isset($groups) AND $product->quantity == 0)} sold out! {/if} 4 Link to comment Share on other sites More sharing options...
vekia Posted November 12, 2013 Share Posted November 12, 2013 nice one, in what version you tested it? you mentioned that it is for 1.4, can you share exact version please? Link to comment Share on other sites More sharing options...
devein Posted November 12, 2013 Share Posted November 12, 2013 nice one, in what version you tested it? you mentioned that it is for 1.4, can you share exact version please? thanks! I have 1.4.11 1 Link to comment Share on other sites More sharing options...
shubbing Posted May 1, 2014 Share Posted May 1, 2014 (edited) nice one, in what version you tested it? you mentioned that it is for 1.4, can you share exact version please? Just wanted to say Ive used this in 1.5.6.2 and it works fine too! Thanks! Edited May 1, 2014 by shubbing (see edit history) Link to comment Share on other sites More sharing options...
hideaki Posted July 17, 2014 Share Posted July 17, 2014 Working fine in 1.6.0.6 too! Thanks for it! Link to comment Share on other sites More sharing options...
PrestaShark Posted July 31, 2017 Share Posted July 31, 2017 {if (!isset($product.quantity_all_versions) AND $product.quantity == 0) OR (isset($product.quantity_all_versions) AND $product.quantity_all_versions == 0)} Sold out! {/if} This should be added to official template very long time ago! Thanks! Link to comment Share on other sites More sharing options...
Mick Posted February 2, 2018 Share Posted February 2, 2018 Hi folks, I would like this in prestashop 1.7, does this solution still work? Can somegive a pointer on which .tpl files need changing and where in the file this code would go? Many thanks Link to comment Share on other sites More sharing options...
Mustafa Iqbal Posted December 25, 2018 Share Posted December 25, 2018 Hello, I am using 1.7, please tell me [ in product-list.tpl ] file in which block i add code? Also I saw multiple codes which code do u prefer for 1.7?? Link to comment Share on other sites More sharing options...
Mustafa Iqbal Posted December 25, 2018 Share Posted December 25, 2018 (edited) Please Check my ( product-list.tpl ) code block; look like this: (and please tell me where can I insert this code for shoing my product "Sold OuT" ) {extends file=$layout} {block name='content'} <section id="main"> {block name='product_list_header'} <h2 class="h2">{$listing.label}</h2> {/block} <section id="products"> {if $listing.products|count} <div id=""> {block name='product_list_top'} {include file='catalog/_partials/products-top.tpl' listing=$listing} {/block} </div> {block name='product_list_active_filters'} <div id="" class="hidden-sm-down"> {$listing.rendered_active_filters nofilter} </div> {/block} <div id=""> {block name='product_list'} {include file='catalog/_partials/products.tpl' listing=$listing} {/block} </div> <div id="js-product-list-bottom"> {block name='product_list_bottom'} {include file='catalog/_partials/products-bottom.tpl' listing=$listing} {/block} </div> {else} {include file='errors/not-found.tpl'} {/if} </section> </section> {/block} Edited December 25, 2018 by Mustafa Iqbal (see edit history) Link to comment Share on other sites More sharing options...
morgana Posted March 29, 2019 Share Posted March 29, 2019 any news about ps 1.7.5? I Need to insert the flag sold out could you tell me which code should I use? Link to comment Share on other sites More sharing options...
Vuini Posted April 20, 2019 Share Posted April 20, 2019 Hey guys! I'm also looking for a solution for PS 1.7(.2.4). I've been trying some if conditions in the product-variants.tpl but I'm no able to find the right one for the quantity. All of my variants are always getting labeled with "(out of stock)". Are the attribute names still the same in 1.7? Thank you very much! Link to comment Share on other sites More sharing options...
magyck Posted July 30, 2019 Share Posted July 30, 2019 (edited) Mi solución para 1.7 a mi manera es la siguiente: <form action = "{$ urls.pages.cart}" method = "post" id = "add-to-cart-or-refresh"> <input type = "hidden" name = "token" value = "{$ static_token} "> <input type =" hidden "name =" id_product "value =" {$ product.id} "id =" product_page_product_id "> <input type =" hidden "name =" id_customization "value =" {$ product .id_customization} "id =" product_customization_id "> {if $ product.quantity <1} <button class =" btn btn-danger add-to-cart "data-button-action =" add-to-cart "type =" enviar "> <i class =" material-icons ">error_outline </i> {ls = 'Agotado' d = 'Shop.Theme.Actions'} </button> {else} <button class = "btn btn-primary add-to-cart" data-button-action = "add-to-cart" type = "enviar"> <i class = "material-icons shopping-cart"> & # xE547 ; </i> {ls = 'Añadir' d = 'Shop.Theme.Actions'} </button> {/ if} </button> </form> De esta manera obtendremos el resultado que esperaba, muestra 'Añadir' en el caso de que haya stock y 'Agotado' en el caso de que no quede stock. Espero que os sirva de ayuda. Podéis ver el resultado en http://www.mundoraspberry.com Edited July 30, 2019 by magyck (see edit history) 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