sickshot Posted April 13, 2013 Share Posted April 13, 2013 (edited) hello, can anyone help me to show product weight on product page? im running PrestaShop™ 1.5.3.1 . thank you Edited April 13, 2013 by sickshot (see edit history) 1 Link to comment Share on other sites More sharing options...
PascalVG Posted April 13, 2013 Share Posted April 13, 2013 (edited) 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)}  {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 April 13, 2013 by PascalVG (see edit history) 2 Link to comment Share on other sites More sharing options...
sickshot Posted April 13, 2013 Author Share Posted April 13, 2013 (edited) 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)}  {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 April 13, 2013 by sickshot (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted April 13, 2013 Share Posted April 13, 2013 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. 1 Link to comment Share on other sites More sharing options...
sickshot Posted April 13, 2013 Author Share Posted April 13, 2013 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)}  {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 More sharing options...
Paulito Posted April 13, 2013 Share Posted April 13, 2013 Good morning Pascal, I was looking for this, it works perfectly Paul PS 1.5.1.3 Link to comment Share on other sites More sharing options...
PascalVG Posted April 13, 2013 Share Posted April 13, 2013 Hi both, Glad it works for you :-) Please mark the question as solved. (See my footer text how) Pascal 2 Link to comment Share on other sites More sharing options...
Pichayutm Posted July 26, 2013 Share Posted July 26, 2013 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 More sharing options...
vekia Posted July 26, 2013 Share Posted July 26, 2013 in this case is necessary to retrieve the information about weight from ajax call and of course it will be necessary to change some product page scripts to put new height to the correct DOM element Link to comment Share on other sites More sharing options...
jahyax Posted August 1, 2013 Share Posted August 1, 2013 this topic talks about showing weight on front page.. does anyone knows how to edit or add a product weight from back office of prestashop. I'm using 1.5.4 Link to comment Share on other sites More sharing options...
PascalVG Posted August 1, 2013 Share Posted August 1, 2013 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 More sharing options...
Vanger Posted December 14, 2013 Share Posted December 14, 2013 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)}  {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 More sharing options...
slappedsilly Posted February 3, 2014 Share Posted February 3, 2014 (edited) QUICK TIP for late comers to thread who copy the OP's code vebatim use sprintf not printf Edited February 3, 2014 by slappedsilly (see edit history) 1 Link to comment Share on other sites More sharing options...
allofdi Posted March 28, 2014 Share Posted March 28, 2014 Hello, i have a problem with my xml file, i don't have the Shipping weight . Link to comment Share on other sites More sharing options...
Shido Posted April 24, 2014 Share Posted April 24, 2014 Thanks for the tips, perfectly works on Ps 1.5.6.2 Link to comment Share on other sites More sharing options...
monkata Posted November 28, 2014 Share Posted November 28, 2014 Hi, thank's for the share. Works, but not at 100% What I mean. I give 11 kg weight for the product, after that I see on product page 11.04 kg How to solve? Link to comment Share on other sites More sharing options...
monkata Posted November 28, 2014 Share Posted November 28, 2014 Fix it! Just put "s" before print How to make the same font like my theme?? Link to comment Share on other sites More sharing options...
hstpctech Posted December 6, 2016 Share Posted December 6, 2016 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)}  {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 More sharing options...
Fehmi135 Posted March 31, 2017 Share Posted March 31, 2017 Y Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now