Search code examples
phpprestashopprestashop-1.6

Prestashop:How to show a default label either if the product is in stock that out of stock (allowed to order)?


I'm on prestashop 1.6 and I need to show a label, near the quantity avaiable, that tells to the user that the product is avaiable, or when quantity is set to 0, ready to be ordered.

Prestashop does this already only if you set these two message, one by one, for each product in your store. I just need a default message for all the products.

I've located on product.tpl this code:

    <!-- availability or doesntExist -->
    <p {if !$PS_STOCK_MANAGEMENT || ($product->quantity <= 0 && !$product->available_later && $allow_oosp) || ($product->quantity > 0 && !$product->available_now) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
        {*<span id="availability_label">{l s='Availability:'}</span>*}
        <span id="availability_value" class="label{if $product->quantity <= 0 && !$allow_oosp} label-danger{elseif $product->quantity <= 0} label-warning{else} label-success{/if}">{if $product->quantity <= 0}{if $PS_STOCK_MANAGEMENT && $allow_oosp}{$product->available_later}{else}{l s='FANCULO'}{/if}{elseif $PS_STOCK_MANAGEMENT}{$product->available_now}{/if}</span>
    </p>

That I think do the job, but I really don't understand how to edit this to show a default value for each case, maybe taking advantage of the class label

thank you in advance


Solution

  • Try this code :

    <!-- availability or doesntExist -->
    <p id="availability_statut"{if !$PS_STOCK_MANAGEMENT || ($product->quantity <= 0 && !$product->available_later && $allow_oosp) || ($product->quantity > 0 && !$product->available_now) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
                    <span id="availability_value" class="label{if $product->quantity <= 0 && !$allow_oosp} label-danger{elseif $product->quantity <= 0} label-warning{else} label-success{/if}">
                        {if $product->quantity <= 0}
                            {if $PS_STOCK_MANAGEMENT && $allow_oosp}
                                {l s='product available later'}
                            {else}
                                {l s='This product is no longer in stock'}
                            {/if}
                        {elseif $PS_STOCK_MANAGEMENT}
                            {l s='available for order'}
                        {/if}
                    </span>
                </p>
    

    Cheers :)