Jump to content

[SOLVED] show product weight on product page


sickshot

Recommended Posts

Try something like this:

in themes/<your theme folder>/product.tpl you find this piece of code.

Add the 4 lines almost at the end...

 


<!-- left infos-->
<div id="pb-left-column">
<h1>{$product->name|escape:'htmlall':'UTF-8'}</h1>

{if $product->description_short OR $packItems|@count > 0}
<div id="short_description_block">
{if $product->description_short}
<div id="short_description_content" class="rte align_justify">{$product->description_short}</div>
{/if}
{if $product->description}
<p class="buttons_bottom_block"><a href="javascript:{ldelim}{rdelim}" class="button">{l s='More details'}</a></p>
{/if}
{if $packItems|@count > 0}
<div class="short_description_pack">
<h3>{l s='Pack content'}</h3>
{foreach from=$packItems item=packItem}
<div class="pack_content">
{$packItem.pack_quantity} x <a href="{$link->getProductLink($packItem.id_product, $packItem.link_rewrite, $packItem.category)}">{$packItem.name|escape:'htmlall':'UTF-8'}</a>
<p>{$packItem.description_short}</p>
</div>
{/foreach}
</div>
{/if}
</div>
{/if}

<div class="product_weight">			 // add these 4 lines
{l s='Product weight: ' js=1}{printf("%.3f",$product->weight)}
&nbsp{Configuration::get('PS_WEIGHT_UNIT')}
</div>							 // that's it...

{*{if isset($colors) && $colors}
<!-- colors -->
<div id="color_picker">

The printf is added to limit the decimals. That's further up to you.

It puts the weight under the short description.

 

Hope this helps,

Pascal

Edited by PascalVG (see edit history)
  • Like 2
Link to comment
Share on other sites

Works Like charm Pascal. thank you so much. but as usual i got another question and I hope you could help me once again :) ...

 


<!-- left infos-->
<div id="pb-left-column">
<h1>{$product->name|escape:'htmlall':'UTF-8'}</h1>

{if $product->description_short OR $packItems|@count > 0}
<div id="short_description_block">
{if $product->description_short}
<div id="short_description_content" class="rte align_justify">{$product->description_short}</div>
{/if}
{if $product->description}
<p class="buttons_bottom_block"><a href="javascript:{ldelim}{rdelim}" class="button">{l s='More details'}</a></p>
{/if}
{if $packItems|@count > 0}
<div class="short_description_pack">
<h3>{l s='Pack content'}</h3>
{foreach from=$packItems item=packItem}
<div class="pack_content">
{$packItem.pack_quantity} x <a href="{$link->getProductLink($packItem.id_product, $packItem.link_rewrite, $packItem.category)}">{$packItem.name|escape:'htmlall':'UTF-8'}</a>
<p>{$packItem.description_short}</p>
</div>
{/foreach}
</div>
{/if}
</div>
{/if}

<div class="product_weight">			 // add these 4 lines
{l s='Product weight: ' js=1}{printf("%.3f",$product->weight)}
&nbsp{Configuration::get('PS_WEIGHT_UNIT')}
</div>							 // that's it...

{*{if isset($colors) && $colors}
<!-- colors -->
<div id="color_picker">

The printf is added to limit the decimals. That's further up to you.

It puts the weight under the short description.

 

i didnt understand how this thing works

js=1}{printf("%.1f",$product->weight)}

i need to show only Kilograms without decimals. for example if the weight is 3.00000kg, i want to show just 3 kg....

 

i have this same problem with block layered navigation module.

i have opened another topic, but unfortunately cant achieve anything yet....

http://www.prestasho...43#entry1169243

 

maybe it is possible to disable decimals totally for the whole system and have just rounded KGs ?

 

thanks in advance...

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

Hi,

As you probably could read in my answer there at your other question, you can limit the decimals with the"%.1f".

If no decimals are needed, just make it "%.0f" . The number here defines the number of decimals (.0f = zero, .1f = 1 decimal etc.)

 

 

For more detailed info on printf, see here:

http://php.net/manual/en/function.printf.php

 

Pascal.

  • Like 1
Link to comment
Share on other sites

yes I managed to do this and got rid off decimals, this is what i changed:

<div class="product_weight"> {l s='Rooms: ' js=1}{sprintf("%1\$u",$product->weight)} &nbsp{Configuration::get('PS_WEIGHT_UNIT')} </div>

Thanks to you Pascal this topic is solved :) now I'll try to do the same for layered navigation filter...

Link to comment
Share on other sites

  • 3 months later...

Hello PascalVG,

 

Your suggestion about product weight works great. Yet, I do have one further problem.

 

What if I have product's attributes which the weight also different for each one others? I did test your solution but the weight just stick to the default attribute. Unlike product references, the number changes when attributes are altered.

 

Thank you,

 

PS 1.5.2

Link to comment
Share on other sites

Hi Jahyax,

Do you mean you just want to add a weight to a product?

 

If so, Go to (Catalog->Products)

and edit the product you want to add a weight to.

Go to the tab shipping. There you see a field weight.

 

If not, please elaborate a little what you need exactly.

pascal

Link to comment
Share on other sites

  • 4 months later...
and if the product is given weight 0 kg

but its attributes:

1 attribute - 1 kg

2 attribute - 2 kg

in this case the weight of the product display page?

 



<div class="product_weight"> {l s='Rooms: ' js=1}{sprintf("%1\$u",$product->weight)} &nbsp{Configuration::get('PS_WEIGHT_UNIT')} </div>


This code shows only the specified attributes of the goods without West

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 4 weeks later...
  • 7 months later...
  • 2 years later...

Try something like this:

in themes/<your theme folder>/product.tpl you find this piece of code.

Add the 4 lines almost at the end...

 


<!-- left infos-->
<div id="pb-left-column">
<h1>{$product->name|escape:'htmlall':'UTF-8'}</h1>

{if $product->description_short OR $packItems|@count > 0}
<div id="short_description_block">
{if $product->description_short}
<div id="short_description_content" class="rte align_justify">{$product->description_short}</div>
{/if}
{if $product->description}
<p class="buttons_bottom_block"><a href="javascript:{ldelim}{rdelim}" class="button">{l s='More details'}</a></p>
{/if}
{if $packItems|@count > 0}
<div class="short_description_pack">
<h3>{l s='Pack content'}</h3>
{foreach from=$packItems item=packItem}
<div class="pack_content">
{$packItem.pack_quantity} x <a href="{$link->getProductLink($packItem.id_product, $packItem.link_rewrite, $packItem.category)}">{$packItem.name|escape:'htmlall':'UTF-8'}</a>
<p>{$packItem.description_short}</p>
</div>
{/foreach}
</div>
{/if}
</div>
{/if}

<div class="product_weight">			 // add these 4 lines
{l s='Product weight: ' js=1}{printf("%.3f",$product->weight)}
&nbsp{Configuration::get('PS_WEIGHT_UNIT')}
</div>							 // that's it...

{*{if isset($colors) && $colors}
<!-- colors -->
<div id="color_picker">

The printf is added to limit the decimals. That's further up to you.

It puts the weight under the short description.

 

Hope this helps,

Pascal

 

 

Hello Pascal,

 

I followed this code snippet but I ended with extra 0.04 kg displayed on my every product. Where is that coming from?

 

sincerely,

Andy

Link to comment
Share on other sites

  • 3 months 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...