Jump to content

[Solved] Show product combination weight


Sekka

Recommended Posts

Hello everyone,

I'm working on prestashop 1.7.5.0 and I want to show the product weight on the product page.

I found that {$product->weight} was available and its working fine.

When it comes to combinations, its not the same though. {$combination->weight} isnt working nor does {$product_attribute.weight}. Is there any way or a smarty variable to show the combination weight on the product page ? 

Thank you :)

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

Well if a combination as a different weight, I want to show it on the product page (ie. if the XL size of a product weights 1kg and the L size weights 0.5kg I want to show it on the product page). If the weight isn't dynamic at first its ok, I'd just like to be able to show it.

Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...
On 8/6/2020 at 9:10 AM, Sekka said:

As the combination weight is determined by "weight difference" from the original weight you'd have to go with something like that :


{$product->weight+$combinations[$product.id_product_attribute]["weight"]}

 

Thanks, this works fine also for me but it doesn't refresh when I change the combination... How can I refresh the value?

Link to comment
Share on other sites

  • 2 months later...
On 8/6/2020 at 9:10 AM, Sekka said:

As the combination weight is determined by "weight difference" from the original weight you'd have to go with something like that :


{$product->weight+$combinations[$product.id_product_attribute]["weight"]}

 

This works great, but as others have mentioned it's not refreshing when you change attribute.

If refreshing is out in this case, maybe if there is a way to pool all attributes weights at once, that would also be very useful.

 

Thanks for the first solution! 

Link to comment
Share on other sites

  • 3 months later...
On 1/14/2021 at 2:24 PM,  CC  said:

This works great, but as others have mentioned it's not refreshing when you change attribute.

...

 

I can't agree to that, as this is working perfectly fine upon choosing another combination(attribute) on the product page.

Mechanics behind that is covered by PrestaShop Core in Product Controller , method displayAjaxRefresh: (https://github.com/PrestaShop/PrestaShop/blob/4edececed3066f483a472d2ac9f611a7e800ad60/controllers/front/ProductController.php#L400

The method does re-rendering some product _partials templates(price, pictures, EAN, Index, and Weight too if you place it in proper _partials template in your theme), which is then processed by JS.

This is all built-in,

 

EDIT:

Sir, maybe you have pasted this line of code

{$product->weight+$combinations[$product.id_product_attribute]["weight"]}

outside of re-rendered _partials templates

I think you can choose one of those files(from above github link method):

'product_prices' => $this->render('catalog/_partials/product-prices'),
'product_cover_thumbnails' => $this->render('catalog/_partials/product-cover-thumbnails'),
'product_customization' => $this->render(
    'catalog/_partials/product-customization',
    //...
),
'product_details' => $this->render('catalog/_partials/product-details'),
'product_variants' => $this->render('catalog/_partials/product-variants'),
'product_discounts' => $this->render('catalog/_partials/product-discounts'),
'product_add_to_cart' => $this->render('catalog/_partials/product-add-to-cart'),
'product_additional_info' => $this->render('catalog/_partials/product-additional-info'),
'product_images_modal' => $this->render('catalog/_partials/product-images-modal'),

 

  • Like 1
Link to comment
Share on other sites

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