Jump to content

Show weight impact selected attribute on product page


Recommended Posts

Is it possible to show the weight impact of the selected attribute on the product page?
I already got the normal weight displayed on the product page, but also want to display the weight impact.

 

Using Prestashop 1.6.11

 

Thanks

Link to comment
Share on other sites

I didn't test it, but it's worth trying with {$group_attribute.weight} in the product.tpl file, within one of these foreach statements:

{foreach from=$group.attributes key=id_attribute item=group_attribute}

 

Although as far as I know the impact depends on combination, so it might as well be worth checking product.js, findCombination() method, where you might be able to access the weight property of each combo

Link to comment
Share on other sites

Although as far as I know the impact depends on combination, so it might as well be worth checking product.js, findCombination() method, where you might be able to access the weight property of each combo

 

Thanks for pointing me in the right direction.

For me (custom theme) this didn't work out: {$group_attribute.weight}

 

I modified product.js with these lines:

function addCombination(...... , weight)

    combination['weight'] = weight;

 

function findCombination()

    selectedCombination['weight'] = combinations[combination]['weight'];

 

Used this in the product.tpl

    {$combination.weight}

    {$selectedCombination.weight} -> does not work returns 0 or nothing

 

Well the weight impact is displayed, but shows it random (with: $combination.weight).

 

 

Link to comment
Share on other sites

Weight: undefined (as it also says in my debug console)

 

So $combintaion.weight is defined, but selectedCombination['weight']  is not...
Changed a couple of rules in product.js file.

Now selectedCombination['weight'] is defined but is is always 0.

 

Shouldn't i Change somethin in controllers/front/productcontroller.php or classes/product.php?

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

Now yes, if that's 0, I guess you can try inspeting productcontroller.php

 

look for this method:assignAttributesCombinations

 

inside it, after this line

$attributes_combinations = Product::getAttributesInformationsByProduct($this->product->id);

 

Add

 

var_dump($attributes_combinations);

 

See if the weight is added there

Link to comment
Share on other sites

  • 1 year later...

You was on the right way. I made it this way.

In product.tpl

<div class="aeuc_weight_label"><span id="product_weight" data-weight="{$product->weight|escape:'htmlall':'UTF-8'|number_format:0}">{$product->weight|escape:'htmlall':'UTF-8'|number_format:0} </span><span>{Configuration::get('PS_WEIGHT_UNIT')}</span></div>

 

and the js in product.js

new function updateWeight

 

function updateWeight()
{
    // Get combination weight
    var combID = $('#idCombination').val();
    var productWeight = $('#product_weight').data("weight");
    var combination = combinationsFromController[combID];
    if (typeof combination == 'undefined')
        return;
    newProductweight = productWeight+combination['weight'];
    $('#product_weight').text(newProductweight);
}

and call it in the function updateDisplay()

f.e.

.....

    // If we have combinations, update price section: amounts, currency, discount amounts,...
    if (productHasAttributes)
        updatePrice();
        updateWeight();
}

.....

Link to comment
Share on other sites

  • 1 year later...
  • 10 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...