Jump to content

Product.tpl (print weight)


Recommended Posts

Change line 331 of product.php (in PrestaShop v1.3) from:

$smarty->display(_PS_THEME_DIR_.'product.tpl');



to:

$smarty->assign('weightUnit', Configuration::get(Configuration::get('PS_WEIGHT_UNIT')));
$smarty->display(_PS_THEME_DIR_.'product.tpl');



then add the following to product.tpl in your theme's directory wherever you want the weight:

{$product->weight}{$weightUnit}

Link to comment
Share on other sites

Thanks for the reply sir.

Since you noted v1.3, will this not work for v1.2.5?

This is slightly off-topic, but is it possible to call on carriers with the weight?
So lets say I have the following: 50g (from the code you previously provided)
and country (which I have figured out).

Is it possible to use these 2 pieces of information to check a certain carrier (maybe by its ID or something) to see the price?


Thanks again.

Link to comment
Share on other sites

It will work in PrestaShop v1.2.5 too. When I say "in PrestaShop v1.3", I mean the line number I am mentioning is from PrestaShop v1.3 and it may be slightly different in other PrestaShop versions.

I'm guessing you want to display the shipping cost of the product for a specific carrier? You can add code like the following to product.php to get the shipping cost of the product:

$carrier = new Carrier(1, intval($cookie->id_lang));
$shippingCost = $carrier->getDeliveryPriceByWeight($product->weight, 2);
$smarty->assign('shippingCost', $shippingCost);



Change 1 to the ID of the carrier and change 2 to the zone that you want to get the shipping cost for.

You can then use the following in product.tpl:

{l s='Shipping cost:'} {convertPrice price=$shippingCost}

Link to comment
Share on other sites

Thanks a lot rocky, this has been highly useful and I will post again if I get into any trouble with it!

Just one last question, if I wanna include it in order.php (Shipping Cart page), do I just add also this to order.php?

$carrier = new Carrier(1, intval($cookie->id_lang));
$shippingCost = $carrier->getDeliveryPriceByWeight($product->weight, 2);
$smarty->assign('shippingCost', $shippingCost); 

Link to comment
Share on other sites

  • 4 weeks later...

Hi, i want to do the same thing, but this does not work for me. The product-page is just blank when i paste the code in product.php
Any idea? Or do i have to activate something in the back office?

I want to show weight at Product listings and at the product side.

Link to comment
Share on other sites

That's weird. It should give you an error message. Did you use straight quotes around 'on' instead of the angle quotes the forum uses? I can't help you without an error message. I just tested the code on my test site and it worked fine.

Link to comment
Share on other sites

This is how it looks

/* Debug only */
@ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', false);



edit: Now i tried with:

/* Debug only */
@ini_set('display_errors', ‘on’);
define('_PS_DEBUG_SQL_', false);



Still a blank page :(

Link to comment
Share on other sites

It worked :)

Parse error: syntax error, unexpected ';' in /hsphere/local/home/foto2972/shop.rcfreak.no/product.php on line 331



product.php

330 );
331 $smarty->assign('weightUnit', Configuration::get(Configuration::get('PS_WEIGHT_UNIT'));
332 $smarty->display(_PS_THEME_DIR_.'product.tpl');



Any idea?

Link to comment
Share on other sites

Nice! Thanks mate :D

But how do i get the weight to show at the product list?
I now just tried do add a new line in product.php, but it did not work :P

$smarty->assign('weightUnit', Configuration::get(Configuration::get('PS_WEIGHT_UNIT')));
$smarty->display(_PS_THEME_DIR_.'product.tpl');
$smarty->display(_PS_THEME_DIR_.'product-list.tpl');



And tried to paste in this in the product-list.tpl

{$product->weight}{$weightUnit}

Link to comment
Share on other sites

You can't call product-list.tpl from product.php like that. It won't work. You need to find everywhere that product-list.tpl is already called including category.php, search.php and best-sales.php. Add the weight unit line before those calls to product-list.tpl, then use the following in product-list.tpl:

{$product.weight}{$weightUnit}

Link to comment
Share on other sites

Thanks for all the help mate!
Will try what you say :)


Edit: Will just inform that just this code in product-list.tpl worked without any other modifications for me.

{$product.weight}{$weightUnit}



Again, thanks for all your help!

Link to comment
Share on other sites

  • 1 year later...

How do you display the sipping price in a newer version of prestashop?...

 

 

$carrier = new Carrier(1, intval($cookie->id_lang));

$shippingCost = $carrier->getDeliveryPriceByWeight($product->weight, 2);

$smarty->assign('shippingCost', $shippingCost);

 

 

 

Change 1 to the ID of the carrier and change 2 to the zone that you want to get the shipping cost for.

 

You can then use the following in product.tpl:

 

 

{l s='Shipping cost:'} {convertPrice price=$shippingCost}

 

 

This does not work in version 1.4.7.0.

What code will work in this newer version og prestashop?

When i use this code it shows "

Shipping cost: DKK 0,00

"

Link to comment
Share on other sites

×
×
  • Create New...