Jump to content
sm3004

[SOLVED] Display "Sold Out" on items that have 0 quantity

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

You are right. Try the following code instead:

{if $product->quantity == 0 AND $quantity == 0} 

{l s='SOLD OUT!'}
{/if}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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}

Share this post


Link to post
Share on other sites

Works great! Been trying to fix that bug for days, it's haunting my dreams.

Hooray for Rocky!!

Share this post


Link to post
Share on other sites

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}

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Hiya - You just need to do the same in the category listing template ... if you mean something similar to this ? www.loopcase.com

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 :(
  • Like 1

Share this post


Link to post
Share on other sites
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 Rocky

This does not appear to work for the latest version 1.3

Any work around for it please?

It would be good for me re a previous post of mine 'Coming Soon'

Many thanks

Share this post


Link to post
Share on other sites

There are many posts but would anybody say what should be at last as the final step including all changes that should be done?

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

my solution, based on other contributions and my ideas :P

 

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}
 
  • Like 4

Share this post


Link to post
Share on other sites

nice one, in what version you tested it? you mentioned that it is for 1.4, can you share exact version please?

Share this post


Link to post
Share on other sites

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 :)

  • Like 1

Share this post


Link to post
Share on other sites

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 by shubbing (see edit history)

Share this post


Link to post
Share on other sites


{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! :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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??

 

Share this post


Link to post
Share on other sites

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 by Mustafa Iqbal (see edit history)

Share this post


Link to post
Share on other sites

any news about ps 1.7.5?

I Need to insert the flag sold out could you tell me which code should I use?

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
Posted (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

 

ejemplo.png

Edited by magyck (see edit history)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More