Jump to content

Add in-stock quantity to product list of default theme?


Recommended Posts

I am using the default Prestashop theme at http://www.rotmgvault.com . I would like to add the in-stock quantity (number of items available for purchase) to the product lists. For example: I want the user to be able to see how many of the items are in stock on this page http://www.rotmgvault.com/6-potions . Right now, you can only see the number of items in-stock if you click on each individual product. That is very annoying considering the nature of our products and that they are usually in limited quantities.

 

I tried looking at the tpl files to see if I could figure it out myself, but am not able to get it to show up. Can someone help me with this? I just need to know the code to add and where to add it.

 

Thanks!

Link to comment
Share on other sites

I tried adding this to product-list.tpl in the SPAN that contains the "availability" code. Nothing shows up.

 

<!-- number of item in stock -->
  {if ($display_qties == 1 && !$PS_CATALOG_MODE && $product->available_for_order)}
  <p id="pQuantityAvailable"{if $product->quantity <= 0} style="display: none;"{/if}>
   <span id="quantityAvailable">{$product->quantity|intval}</span>
   <span {if $product->quantity > 1} style="display: none;"{/if} id="quantityAvailableTxt">{l s='item in stock'}</span>
   <span {if $product->quantity == 1} style="display: none;"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'}</span>
  </p>
  {/if}
 <!-- end number of item in stock -->

 

However, if I remove the first IF condition and the paragraph tag, then I get "0 item in stock" on every product in the list. So it is not loading the actual in-stock number for each product. I must be missing something. Any ideas?

Link to comment
Share on other sites

  • 2 weeks later...

OK here is the solution after playing for some time I figured this out it's far more simple then you would think.

 

Simply add this - {$product.quantity}{l s=' items in stock'} after the closing {/if} statement of <div class="right_block"> section.

Just below will be the section for {if ($product.id_product_attribute.

 

will look like this.

 

 

{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)} (more code here)

</div>

{/if}

 

{$product.quantity}{l s=' items in stock'}

 

{if ($product.id_product_attribute == 0 || (more code here)

 

Note: I had to turn on force compile and turn off cache for this to take effect.

 

This was a funny one I wanted to add the pageination buttons on top of page just as they are on bottom played and played and in the end it was to simple.

 

Just Add {include file="$tpl_dir./pagination.tpl"} after the <!-- Products list --> statement.

Link to comment
Share on other sites

tdr170: Thanks so much! :D That works perfectly! I was starting to think no one would help!

 

I was also trying to apply this to the category-tree-branch.tpl in the blackcategories module so that the number of items will show up next to each category. I made a post for it, but no one is answering me. Any chance you might now how to make this work there?

 

http://www.prestashop.com/forums/topic/25955-how-to-show-product-count-in-category-section/page__p__776046#entry776046

Link to comment
Share on other sites

  • 11 months later...
  • 2 weeks later...

Here is the code I added on Prestashop 1.5x at the same place

 

{*Added quantity in stock*}

<!-- availability -->

<p id="availability_statut"{if ($product.quantity <= 0 && !$product.available_later && $allow_oosp) OR ($product.quantity > 0 && !$product.available_now) OR !$product.available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>

<span id="availability_label">{l s='Availability:'}</span>

<span id="availability_value"{if $product.quantity <= 0} class="warning_inline"{/if}>

{if $product.quantity <= 0}{if $allow_oosp}{$product.available_later}{else}{l s='This product is no longer in stock'}{/if}{else}{$product.available_now}{/if}

</span>

</p>

 

<!-- number of item in stock -->

{*if ($display_qties == 1 && !$PS_CATALOG_MODE && $product.available_for_order) *}

<p id="pQuantityAvailable"{if $product.quantity <= 0} style="display: none;"{/if}>

<span id="quantityAvailable">{$product.quantity|intval}</span>

<span {if $product.quantity > 1} style="display: none;"{/if} id="quantityAvailableTxt">{l s='item in stock'}</span>

<span {if $product.quantity == 1} style="display: none;"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'}</span>

</p>

{*/if*}

 

<!-- Out of stock hook -->

<p id="oosHook"{if $product.quantity > 0} style="display: none;"{/if}>

{$HOOK_PRODUCT_OOS}

</p>

 

<p class="warning_inline" id="last_quantities"{if ($product.quantity > $last_qties OR $product.quantity <= 0) OR $allow_oosp OR !$product.available_for_order OR $PS_CATALOG_MODE} style="display: none"{/if} >{l s='Warning: Last items in stock!'}</p>

{*End Added quantity in stock*}

  • Like 2
Link to comment
Share on other sites

Great thread, very helpful thanks!

 

I edited the code to look like this:

 

 

<!-- qqq number in stock edit -->

<div style="margin:0 0 5px;">

{*if ($display_qties == 1 && !$PS_CATALOG_MODE && $product.available_for_order) *}

<div id="pQuantityAvailable"{if $product.quantity <= 0} style="display: none;"{/if}>

<span style="color:green;">{$product.quantity|intval} i lager</span>

</div>{*/if*}

<div id="oosHook"{if $product.quantity > 0} style="display: none;"{/if}>

<span style="color:red;">0 i lager</span>

</div>

</div>

 

 

I am a php noob and hardly know the basics so I could not get the translation to work ({l s='item in stock'}) for "item/items in stock" so I just wrote the text by itself.

I also took the oos hook thingy and added "0 i lager" (Swedish for - 0 items in stock), and made them green and red. It looks very nice on the webshop. Green text for when items are in stock and red for when it's 0 items. I also removed the "available" tag. In the shop I have made the owner want all products to be available for back-order, but at the same time show amount of stock on the product list.

 

(I usually add a <!-- qqq --> when I edit stuff so that I can easy search for it later ;)

Edited by Bodie (see edit history)
Link to comment
Share on other sites

  • 3 months later...

I used the first code from Patrice Vigier, and it works except that, as Bodie stated, the translations don't work.

I would type it manually, if I wouldn't have a multilingual website. Any idea how I can get the translations to work?

The references in the code are exactly the same as in my product.tpl.

Link to comment
Share on other sites

  • 2 months later...

I had a problem with the translation, but I can't remember how I fixed it.

 

This is the code I use, which works for a multilingual shop.

<!-- availability -->					
					{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
						<span class="availability">
						{if ($product.quantity < 1)}
							{if ($product.allow_oosp)}
								{l s='Product available with different options'}
							{else}
								{l s='Out of stock'}
							{/if}
						{else}
							{l s='Available'}
						{/if}
						</span>
					{/if}

Let me know if it works.

  • Like 1
Link to comment
Share on other sites

Hi Christiaan and thanks a lot of the reply. Regrettably your code does not work. It simply does not show the quantity. I can say the code from PatriceVigier (some posts above) show the quantity but only in english.

 

Prestashop 1.5.5 here. 

 

Any help will be really appreciatted.

Link to comment
Share on other sites

  • 3 years later...

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