Jump to content

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

Link to comment
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...

Link to comment
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}

Link to comment
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}

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

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

  • 3 months later...
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
Link to comment
Share on other sites

  • 9 months later...
  • 3 months later...

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

  • 2 years later...

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

  • 5 months later...
  • 2 months later...
  • 3 years later...
  • 6 months later...
  • 10 months later...

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)
Link to comment
Share on other sites

  • 3 months later...
  • 4 weeks later...

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

  • 3 months later...

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)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...