Jump to content

[SOLVED] How to show weight of the order in shopping cart


Recommended Posts

Hi,

I am trying to figure out how to modify presta to show weight of the order in shopping cart.

I have my shipping fees fixed to various weight ranges so I want to enable customers to see what is the weight of the products of their order (besides shipping fee). Weight of each product should be shown in shopping card and sum of all weights of products should be calculated at the end of the cart.

Does anyone know how to make this or have anyone already done somenthing similar? Is there any module to do this?

Thanks for any advices,
Tinechem

Link to comment
Share on other sites

To add a "Total weight" line to the shopping cart page, change lines 442-454 of order.php from:

$smarty->assign(array(
   'token_cart' => $token,
   'productNumber' => $cart->nbProducts(),
   'voucherAllowed' => Configuration::get('PS_VOUCHERS'),
   'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary),
   'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary),
   'shippingCost' => $cart->getOrderTotal(true, 5),
   'shippingCostTaxExc' => $cart->getOrderTotal(false, 5),
   'customizedDatas' => $customizedDatas,
   'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
   'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
   'lastProductAdded' => $cart->getLastProduct()
   ));



to:

$smarty->assign(array(
   'token_cart' => $token,
   'productNumber' => $cart->nbProducts(),
   'voucherAllowed' => Configuration::get('PS_VOUCHERS'),
   'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary),
   'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary),
   'shippingCost' => $cart->getOrderTotal(true, 5),
   'shippingCostTaxExc' => $cart->getOrderTotal(false, 5),
   'customizedDatas' => $customizedDatas,
   'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
   'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
   'lastProductAdded' => $cart->getLastProduct(),
   'weightUnit' => Configuration::get('PS_WEIGHT_UNIT')        
   ));



and then add the following at line 100 of shopping-cart.tpl in your theme's directory (after the {if $shippingCost > 0}):


{l s='Total weight:'}
{$cart->getTotalWeight()} {$weightUnit}

  • Like 1
Link to comment
Share on other sites

In that screenshot, you've replaced the reference column with a weight column. To do that, simply change line 55 of shopping-cart.tpl from:

{l s='Ref.'}



to:

{l s='Weight'}



and line 9 of shopping-cart-product-line.tpl from:

{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if}



to:

{if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'}{/if}



If you want to add it as a new column instead of replacing, you should add these lines before the reference line.

Link to comment
Share on other sites

In that screenshot, you've replaced the reference column with a weight column. To do that, simply change line 55 of shopping-cart.tpl from:

{l s='Ref.'}



to:

{l s='Weight'}



and line 9 of shopping-cart-product-line.tpl from:

{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if}



to:

{if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'}{/if}



If you want to add it as a new column instead of replacing, you should add these lines before the reference line.






Rocky I have one fast question for you. How to add weight unit under the weight colum in shopping cart. Now it only shows number... See the attached picture for reference.

Thanks, Tinechem

19518_SmF4VGbEVOX86q7aZqpS_t

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

Your guide is wonderful and it was exactly what i needed, but...
after adding the codes(and it shows up), my weight seems to show more than necessary decimal points.

Each of my products are 0.3kg and 0.5kg..but when i add to the cart..it shows as 0.30000001234kg instead of just 0.3kg.
May I know if is there any way to limit the decimal point or what is the best solution for this?

Thanks alot.

Link to comment
Share on other sites

Thanks!

I've tried it, but after some trial and error changes..haha.
the result:
{if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'|number_format:1} {$weightUnit}{/if}

Thanks again.

*Now going to the next step, trying to get the darn mail function to work. Duh.

Link to comment
Share on other sites

  • 2 months later...

I had a look at the getTotalWeight() function and it appears to be rounding the total weight to 3 decimal places. You'll need to change line 904 of classes/Cart.php (in PrestaShop v1.3):

$this->_totalWeight = round(floatval($result['nb']) + floatval($result2['nb']), 3);



Change 3 to how many decimal places you want the total weight rounded.

Link to comment
Share on other sites

  • 10 months later...
  • 4 weeks later...
  • 1 month later...
I forgot to include it. Try this instead of the last line above:

{if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'} {$weightUnit}{/if}



Hi ... kinda new to this forum ... great place to evolve this platform... thank you all in advance, specially rocky that's been of great help with his tips...

But still i would like to ask for your help... can i ?

Got all weight working, pdf inclusive, but...

on the cart summary all is ok until the customer updates de quantity... the total weight doesnt update...

it only updates the total weight on F5 or CTRL+R (OSX)... any solution for this ?

Thanks.
Link to comment
Share on other sites

  • 4 months later...
  • 3 months later...
  • 10 months later...
  • 2 weeks later...

Here's how you do it for the PS 1.5.x version:

 

Edit ParentOrderController.php and at line 366 add this:

'weightUnit' => Configuration::get('PS_WEIGHT_UNIT')

 

Then in shopping-cart.tpl you will find 3 <tr class="cart_total_price">. At the end of each <tr> add this:

 

<tr class="cart_total_price">
<td colspan="5">{l s='Total weight:'}</td>
<td colspan="2" class="price" id="total_weight">{$cart->getTotalWeight()} {$weightUnit}</td>
</tr>

 

Please confirm if it's working for you. I've tested this in PS 1.5.3.1.

 

EDIT: the total Weight doesn't get updated on changing the quantity via json. I've been up all night trying to figure this out but I failed god dammit!

Rocky if you're out there, please save us!

I've tried adding

$('#total_weight').html(json.totalWeight);

to cart-summary.js but it doesn't do anything. I'm not even getting any error in the web inspector.

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

  • 4 weeks later...

It work excelent for me. I am from Chile and in 1 week I have made my page www.dentalgift.cl with Prestashop and with this forum I have learned a lot. Thank you very much with you dedication. Another question ¿How can I see in the shopping cart the weight of each product?

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...

I tried editing Presto 1.4.5.1 and does not work as it should ...

Appears to me while weight but one that is as the main (2kg). Product Combinations me to accumulate weight with no change to the product page, the weight does not change, still remains 2 kg

Link to comment
Share on other sites

  • 2 months later...

I have 1.5.4.1 version and I did this:

 

shopping-cart.tpl

 

<th class="cart_description item">{l s='Description'}</th>
<th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>

 

shopping-cart-product-line.tpl

<td class="cart_description">
 <div class="narrow-screen">{l s='Description'}</div>
 <div class="floatL">
  <p class="s_title_block"><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></p>
  {if isset($product.attributes) && $product.attributes}<span class="cart_prod_descrip">{$product.attributes|escape:'htmlall':'UTF-8'}</span>{/if}
 </div>
</td>
<td class="cart_ref">
 <div class="narrow-screen">{Configuration::get('PS_WEIGHT_UNIT')}</div>
  {if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'|number_format:1}{/if}
</td>

post-39071-0-09302100-1370531866_thumb.jpg

Link to comment
Share on other sites

  • 2 weeks later...

Hi

I have 1.5.4.1 version and I did this:

 

shopping-cart.tpl

 

<th class="cart_description item">{l s='Description'}</th>
<th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>

 

shopping-cart-product-line.tpl

<td class="cart_description">
 <div class="narrow-screen">{l s='Description'}</div>
 <div class="floatL">
  <p class="s_title_block"><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></p>
  {if isset($product.attributes) && $product.attributes}<span class="cart_prod_descrip">{$product.attributes|escape:'htmlall':'UTF-8'}</span>{/if}
 </div>
</td>
<td class="cart_ref">
 <div class="narrow-screen">{Configuration::get('PS_WEIGHT_UNIT')}</div>
  {if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'|number_format:1}{/if}
</td>

 

Hi Jorge

Any idea how to display the product.condition in the shopping cart?

 

I'm using {$product.condition} but nothing outputs. I can output all the other fields in the product table, but not 'condition' with is a field I've customised and use lots.

 

In shopping-cart-product-line.tpl i have

{$product.condition} | {$product.name|escape:'htmlall':'UTF-8'}

 

Do I need something somewhere else? Pleeeeese help

 

Many Thanks

Link to comment
Share on other sites

  • 3 weeks later...
Thanks for the code, it's working nicely. Would it be possible to get this working with ajax so if the item quantity is increased it updates automatically? Cheers.

+1

yeah i need this too, until then we must refresh the page to update the total weight

Link to comment
Share on other sites

Here's how you do it for the PS 1.5.x version: Edit ParentOrderController.php and at line 366 add this:
'weightUnit' => Configuration::get('PS_WEIGHT_UNIT')

Then in shopping-cart.tpl you will find 3 . At the end of each add this:

 {l s='Total weight:'} {$cart->getTotalWeight()} {$weightUnit} 

Please confirm if it's working for you. I've tested this in PS 1.5.3.1. EDIT: the total Weight doesn't get updated on changing the quantity via json. I've been up all night trying to figure this out but I failed god dammit! Rocky if you're out there, please save us! I've tried adding $('#total_weight').html(json.totalWeight); to cart-summary.js but it doesn't do anything. I'm not even getting any error in the web inspector.

 

I can't get the weight unit in the Total Weight using this method, i only get the number alone like this: 20.00

it should appear this way: 20.00 Kg

 

My prestashop version: 1.5.4.1

Default theme

 

I'm doing wrong? i get confuse at this part:

Edit ParentOrderController.php and at line 366 add this:

'weightUnit' => Configuration::get('PS_WEIGHT_UNIT')

this file is at /controllers/front right? and at line 366 and 374 i get this:

366 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE,
367 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD,
368 'lastProductAdded' => $this->context->cart->getLastProduct(),
369 'displayVouchers' => $available_cart_rules,
370 'currencySign' => $this->context->currency->sign,
371 'currencyRate' => $this->context->currency->conversion_rate,
372 'currencyFormat' => $this->context->currency->format,
373 'currencyBlank' => $this->context->currency->blank,
374 'show_option_allow_separate_package' => $show_option_allow_separate_package,

so i must add this code: 'weightUnit' => Configuration::get('PS_WEIGHT_UNIT') in the line 366?

when i do that in the dreamweaver i get this error: "There is a syntax error on line 367. code hitting may not work until you fix this error."

 

 

and did you find a solution for getting the total Weight updated on changing the quantity?

the only solution i see is refreshing the page after changing the quantity of the product...

but is not practical and the customers will be confused :huh:

i hope some one come with a solution for this :rolleyes:

 

Best regards

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

I have fixed most of the problems and adjust the code to be compatible with prestashop 1.5.4.1

 

So for anyone using prestashop 1.5.4.1 and having problems to add this feature

please follow the updated instructions below:

 

Instructions to display only the Total Weight at "Shopping-cart summary":

 

1 - go to /themes/default and edit the file "shopping-cart.tpl"

2 - you will find 5 <tr class="cart_total_price">. At the end of the 3 firsts <tr> add this:

<tr class="cart_total_price">
<td colspan="5">{l s='Total weight:'}</td>
<td colspan="2" class="price" id="total_weight">{$cart->getTotalWeight()} {Configuration::get('PS_WEIGHT_UNIT')}</td>
</tr>

 

Instructions to display the weight of each product at "Shopping-cart summary table":

 

1 - go to /themes/default and open the file shopping-cart.tpl

2 - find this:

<th class="cart_description item">{l s='Description'}</th>

and add this code after the previous code:

<th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>

 

the result should be like this.

<th class="cart_product first_item">{l s='Product'}</th>
<th class="cart_description item">{l s='Description'}</th>
<th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>
<th class="cart_ref item">{l s='Ref.'}</th>
<th class="cart_unit item">{l s='Unit price'}</th>
<th class="cart_quantity item">{l s='Qty'}</th>
<th class="cart_total item">{l s='Total'}</th>
<th class="cart_delete last_item"> </th>

 

3 - go to /themes/default and open the file shopping-cart.tpl

4 - find this code:

<td class="cart_description">
 <p class="s_title_block"><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></p>
 {if isset($product.attributes) && $product.attributes}<a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.attributes|escape:'htmlall':'UTF-8'}</a>{/if}
</td>

and replace by this one:

<td class="cart_description">
 <div class="floatL">
  <p class="s_title_block"><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></p>
  {if isset($product.attributes) && $product.attributes}<span class="cart_prod_descrip">{$product.attributes|escape:'htmlall':'UTF-8'}</span>{/if}
 </div>
</td>
<td class="cart_ref">
 <div class="price">{if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'|number_format:1} {/if}{Configuration::get('PS_WEIGHT_UNIT')}</td>

 

 

Fixing the Shoping-cart summary tables (columns):

now after adding the previous code lines to display the weight of each product

you will noticed that the Shoping-cart summary tables (columns) are wrong (empty space on the right) we must fill that empty space using the "colspan" attribute

so open the file "shopping-cart.tpl" find and replace all colspan="5" with colspan="6"

 

Fixing the Shoping-cart summary table column Price:

if the price in the summary table column is not correctly aligned at top like the other columns

here is a fix:

find:

<td class="cart_ref">{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if}</td>
<td class="cart_unit"><br />

and remove the "<br />" at the end

 

 

Change the title of the weight unit at Shoping-cart summary top title table:

Instead of weight unit title (KG or LB) you can changed to "Weight" and be translated at your BO

here's how:

find:

<th class="cart_weight item">{Configuration::get('PS_WEIGHT_UNIT')}</th>

and replace with this:

<th class="cart_weight item">{l s='Weight'}</th>

 

i am still finding a way to getting the total Weight updated on changing the quantity

the only solution i see is refreshing the page after changing the quantity of the product...

but is not practical and the customers will be confused

 

Best regards

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

@majority

 

Wanted to try but, I have the same version 1.5.4.1, but was not able to follow the install.

my shopping-cart.tpl is different and I use the original prestashop theme.

 

<td class="cart_description"> does not exist

 

 

I am really getting lost with these versions !!!!

Link to comment
Share on other sites

did you install a fresh installation of prestashop 1.5.4.1 or did you update from an older version?

and the installation was manual or auto from simplescripts?

mine is a fresh prestashop 1.5.4.1 installation and there is no difference in the files

make a new fresh installation to test.

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

  • 2 weeks later...

I have fixed most of the problems and adjust the code to be compatible with prestashop 1.5.4.1

 

So for anyone using prestashop 1.5.4.1 and having problems to add this feature

please follow the updated instructions below:

 

Instructions to display only the Total Weight at "Shopping-cart summary":

 

1 - go to /themes/default and edit the file "shopping-cart.tpl"

2 - you will find 5 <tr class="cart_total_price">. At the end of the 3 firsts <tr> add this:

<tr class="cart_total_price">
<td colspan="5">{l s='Total weight:'}</td>
<td colspan="2" class="price" id="total_weight">{$cart->getTotalWeight()} {Configuration::get('PS_WEIGHT_UNIT')}</td>
</tr>

 

Instructions to display the weight of each product at "Shopping-cart summary table":

 

1 - go to /themes/default and open the file shopping-cart.tpl

2 - find this:

<th class="cart_description item">{l s='Description'}</th>

and add this code after the previous code:

<th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>

 

the result should be like this.

<th class="cart_product first_item">{l s='Product'}</th>
<th class="cart_description item">{l s='Description'}</th>
<th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>
<th class="cart_ref item">{l s='Ref.'}</th>
<th class="cart_unit item">{l s='Unit price'}</th>
<th class="cart_quantity item">{l s='Qty'}</th>
<th class="cart_total item">{l s='Total'}</th>
<th class="cart_delete last_item"> </th>

 

3 - go to /themes/default and open the file shopping-cart.tpl

4 - find this code:

<td class="cart_description">
 <p class="s_title_block"><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></p>
 {if isset($product.attributes) && $product.attributes}<a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.attributes|escape:'htmlall':'UTF-8'}</a>{/if}
</td>

and replace by this one:

<td class="cart_description">
 <div class="floatL">
  <p class="s_title_block"><a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></p>
  {if isset($product.attributes) && $product.attributes}<span class="cart_prod_descrip">{$product.attributes|escape:'htmlall':'UTF-8'}</span>{/if}
 </div>
</td>
<td class="cart_ref">
 <div class="price">{if $product.weight}{$product.weight|escape:'htmlall':'UTF-8'|number_format:1} {/if}{Configuration::get('PS_WEIGHT_UNIT')}</td>

 

 

Fixing the Shoping-cart summary tables (columns):

now after adding the previous code lines to display the weight of each product

you will noticed that the Shoping-cart summary tables (columns) are wrong (empty space on the right) we must fill that empty space using the "colspan" attribute

so open the file "shopping-cart.tpl" find and replace all colspan="5" with colspan="6"

 

Fixing the Shoping-cart summary table column Price:

if the price in the summary table column is not correctly aligned at top like the other columns

here is a fix:

find:

<td class="cart_ref">{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if}</td>
<td class="cart_unit"><br />

and remove the "<br />" at the end

 

 

Change the title of the weight unit at Shoping-cart summary top title table:

Instead of weight unit title (KG or LB) you can changed to "Weight" and be translated at your BO

here's how:

find:

<th class="cart_weight item">{Configuration::get('PS_WEIGHT_UNIT')}</th>

and replace with this:

<th class="cart_weight item">{l s='Weight'}</th>

 

i am still finding a way to getting the total Weight updated on changing the quantity

the only solution i see is refreshing the page after changing the quantity of the product...

but is not practical and the customers will be confused

 

Best regards

 

Point 3 must be "shopping-cart-product-line.tpl"

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
  • 3 months later...
  • 1 month later...

does no one have the wrong view of columns in checkout tpl.

Everything function right, but if the Client go to checkout on the last view (payment) the colums are wrong formated.

I think there must be added the right colspan

 

have Fix it:

 

like before by shopping-cart

 

  1. go to /themes/yourThemes and open ORDER-PAYMENT.TPL
  2. find this:
    <th class="cart_description item">{l s='Description'}</th>
    

    and add this code after the previous code:

    <th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>
    

    the result should be like this

    ....
    <th class="cart_description item">{l s='Description'}</th>
    <th class="cart_ref item">{Configuration::get('PS_WEIGHT_UNIT')}</th>
    <th class="cart_ref item">{l s='Ref.'}</th>
    ....
    
  3. Then you will find 3 <tr class="cart_total_price">. At the end of each <tr> add this:
    <tr class="cart_total_price">
    <td colspan="5">{l s='Total weight:'}</td>
    <td colspan="2" class="price" id="total_weight">{$cart->getTotalWeight()} {$weightUnit}</td>
    </tr>
    

    the result should be like this (6 x <tr class="cart_total_price">)

     

    <tr class="cart_total_price">
    .... Old
    </tr>
    
    <tr class="cart_total_price">
    .... added
    </tr>
    
    <tr class="cart_total_price">
    .... Old
    </tr>
    
    <tr class="cart_total_price">
    .... added
    </tr>
    
    <tr class="cart_total_price">
    .... old
    </tr>
    
    <tr class="cart_total_price">
    .... added
    </tr>
    

     

  4. Than find and replace all colspan="5" with colspan="6"

My Checkout page Show now everything fine and well formated.

Prestashop 1.5.6.1

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

this is a great guide.. and will use it if i can get some help with adding the weight to shopping cart without removing the reference column as we use that for different suppliers that sell the same product.

 

so can anyone tell me the code i need to add, the files i need to edit and the lines to retain the reference column but add the weight column.?

 

Thanks in advance.

Link to comment
Share on other sites

this is a great guide.. and will use it if i can get some help with adding the weight to shopping cart without removing the reference column as we use that for different suppliers that sell the same product.

 

so can anyone tell me the code i need to add, the files i need to edit and the lines to retain the reference column but add the weight column.?

 

Thanks in advance.

 

ehhhhh, what about reading from page #1 ??

Link to comment
Share on other sites

Thank you for this nice Support.

Tested on Prestashop 1.5.6.1

 

Work very nice.

 

Ofcourse to get the total Weight updated on changing the quantity, will be PERFECT :wub:

Have some one found a solution ?

I guess I found a solution to solve your problem. Here is what I did:

in "Modules -> Blockcart -> blockcart-json.tpl" at line 109 change

"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}",

to

'totalWeight': '{$total_weight|html_entity_decode:2:'UTF-8'}',

In "Modules -> Blockcart -> Ajax-cart.js" at line 650 change

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);

to

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);$('.ajax_block_cart_weight').text(jsonData.totalWeight);

That solved it for me in total shipping weight and in product weight.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 2 months later...
  • 2 weeks later...

engineerHopf kindly shared a code for 1.6 on how to add a total weight of the order in the shopping cart (NO SOLUTION HAS YET BEEN FOUND ON HOW TO MAKE THE WEIGHT TO AUTO UPDATE WHEN YOU CHANGE QUANTITIES ORDERED IN THE CART, YOU HAVE TO REFRESH PAGE MANUALLY)

 

in /themes/yourtheme/shopping-cart.tpl

 

above </ tfoot>


insert the following code: 

<tr class="cart_total_delivery"><td colspan="5" class="text-right">{l s='Total Weight:'}</td><td colspan="2" class="price">{$cart->getTotalWeight()} &nbsp{Configuration::get('PS_WEIGHT_UNIT')} </td></tr>
Link to comment
Share on other sites

  • 1 month later...
Hello PS community!

This is my first post here.

 

Somehow I got it working (at least for me:)) - the total weight in shopping cart summary, and auto update on quantity change. 

Maybe someone else can make use of it. 

 

My PrestaShop version 1.6.0.9

 

We need to change following files:

 

shopping-cart.tpl in catalogue /themes/yourshop/

We need to add following code:



<tr class="cart_total_price">
<td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Total weight'}</span></td>
<td colspan="2" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3} {Configuration::get('PS_WEIGHT_UNIT')}</span></td>
</tr>


you can add this right above the code:



</tfoot>


 

blockcart-json.tpl in catalogue /themes/yourshop/modules/blockcart

add line:



"totalWeight": {$total_weight|json_encode},


you can place it right below the:



"shippingCost": {$shipping_cost|json_encode},


 

blockcart.php in catalogue /modules/blockcart

add following line:



$totalWeight = $params['cart']->getTotalWeight().' '.Configuration::get('PS_WEIGHT_UNIT');


you can add this line below following:



$totalToPay = $params['cart']->getOrderTotal($useTax);


and in the same file

 

add line 

'total_weight' => $totalWeight


you can add this below the following code:



'free_shipping' => $total_free_shipping,


 

ajax-cart.js in catalogue: /themes/yourshop/js/modules/blockcart/

 

add following line:



$('.ajax_block_cart_weight').text(jsonData.totalWeight);


you can add it below:



$('.ajax_total_price_wt').text(jsonData.total_price_wt);


 

I'm a PS newbie so if I made mistakes, please correct. 

Everyone please pay attention to folders paths as it's crucial to get it working.

 

There are also some issues with rows/columns appearance in shopping cart (due to shopping-cart.tpl modifications),

and basically what I did to keep them on place is (as I remember correctly) I changed in same file everywhere following

<td rowspan="{3+


to



<td rowspan="{4+


and it worked for me.

 

Cheers

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

  • 3 weeks later...

Wow, that actually worked! I tried on my both development test site, it worked.

Then I applied to my main site - it worked!

 

Issue solved, just follow steps in previous post. Tested for PrestaShop version: 1.6.0.5

 

Amazing work oksar86, thank you very-very much!

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
  • 1 month later...
  • 4 weeks later...
  • 1 month later...

Hello all, I am using 1.6.0.6,and the above solution are not working with my version, anybody can help?

 

Pay more attention in configuration paths.

 

moreover maybe you should have to modify (like in my case) at blockcart-json.tpl the script after the pipe.

What I mean:

Literally you should place

 

"totalWeight": {$total_weight | json_encode},    (maybe you should need to replace)

right below

"shippingCost": {$shipping_cost | json_encode},
as oscar86 instructs.
 
but you should check what is the statement after the pipe mark at YOURS shipping cost variable and replace the json_encode in total weight variable to match exactly.

 

 

I did wrong at the first attempt and had all the e-shop to crash.

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

  • 4 weeks later...

I guess I found a solution to solve your problem. Here is what I did:

in "Modules -> Blockcart -> blockcart-json.tpl" at line 109 change

"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}",

to

'totalWeight': '{$total_weight|html_entity_decode:2:'UTF-8'}',

In "Modules -> Blockcart -> Ajax-cart.js" at line 650 change

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);

to

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);$('.ajax_block_cart_weight').text(jsonData.totalWeight);

That solved it for me in total shipping weight and in product weight.

Hi RudiFD. I tried this code but it didn't work. Have you got any other idea?

 

Thanks for your help.

Link to comment
Share on other sites

  • 4 months later...

 

Hello PS community!
This is my first post here.
 
Somehow I got it working (at least for me:)) - the total weight in shopping cart summary, and auto update on quantity change. 
Maybe someone else can make use of it. 
 
My PrestaShop version 1.6.0.9...
 

 

 

As at 1.6.1 this method works. Thanks for this!!

 

A note to PS core devs, this feature is absolutely needed to be built in, rather than having to modify files every time there is an update.

Link to comment
Share on other sites

@jetx

 

As at 1.6.1 this method works. Thanks for this!!

 

A note to PS core devs, this feature is absolutely needed to be built in, rather than having to modify files every time there is an update.

 

Is your shop's version 1.6.1.1 ? Does Weight of each item and Total weight show correctly in the cart? does it auto update each time changing the carts contents?

Link to comment
Share on other sites

  • 1 month later...

Is this just wishful thinking or did I see an option to display the total weight in the checkout page and product page?

Would it not seem like an obvious display feature to have for your products? rather than editing code to show weight

My worst nightmare is when I update ps, my previous edits will be gone, maybe I need to do edits in custom css files?

Or maybe they could just add this feature as default, but then again, some people make a few bucks off this feature.

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

  • 1 month later...

 

Hello PS community!
This is my first post here.
 
Somehow I got it working (at least for me:)) - the total weight in shopping cart summary, and auto update on quantity change. 
Maybe someone else can make use of it. 
 
My PrestaShop version 1.6.0.9
 
We need to change following files:
 
shopping-cart.tpl in catalogue /themes/yourshop/
We need to add following code:
<tr class="cart_total_price">
<td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Total weight'}</span></td>
<td colspan="2" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3} {Configuration::get('PS_WEIGHT_UNIT')}</span></td>
</tr>
[...]

 

That's great, work also for me! Very thanks!

Somebody know if is possible write this weight data also in drop-down cart?

Link to comment
Share on other sites

  • 8 months later...

 

Hello PS community!
This is my first post here.
 
Somehow I got it working (at least for me:)) - the total weight in shopping cart summary, and auto update on quantity change. 
Maybe someone else can make use of it. 
 
My PrestaShop version 1.6.0.9
 
We need to change following files:
 
shopping-cart.tpl in catalogue /themes/yourshop/
We need to add following code:
<tr class="cart_total_price">
<td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Total weight'}</span></td>
<td colspan="2" class="price"><span class="ajax_block_cart_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3} {Configuration::get('PS_WEIGHT_UNIT')}</span></td>
</tr>
you can add this right above the code:
</tfoot>
 
blockcart-json.tpl in catalogue /themes/yourshop/modules/blockcart
add line:
"totalWeight": {$total_weight|json_encode},
you can place it right below the:
"shippingCost": {$shipping_cost|json_encode},
 
blockcart.php in catalogue /modules/blockcart
add following line:
$totalWeight = $params['cart']->getTotalWeight().' '.Configuration::get('PS_WEIGHT_UNIT');
you can add this line below following:
$totalToPay = $params['cart']->getOrderTotal($useTax);
and in the same file
 
add line 
'total_weight' => $totalWeight
you can add this below the following code:
'free_shipping' => $total_free_shipping,
 

 

 

 

In "Modules -> Blockcart -> Ajax-cart.js" at line 650 change

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);

to

$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);$('.ajax_block_cart_weight').text(jsonData.totalWeight);

That solved it for me in total shipping weight and in product weight.

 

tested perfectly by this steps on 1.6.1.3...:)), thanks all...

Link to comment
Share on other sites

  • 2 months later...

Hi Guys,

 

I've tried to follow all the instruction by oskar86 actually it is working but the auto update of total weight is not working, if I add quantity there is no changes in total weight I must I have to refresh the page to make it change.

 

I'm using PS 1.6.0.9

 

Thanks! :D

Link to comment
Share on other sites

Hi Guys,

 

I've tried to follow all the instruction by oskar86 actually it is working but the auto update of total weight is not working, if I add quantity there is no changes in total weight I must I have to refresh the page to make it change.

 

I'm using PS 1.6.0.9

 

Thanks! :D

Hello, there is no direct solution unfortunately. I Think the only way is add a refresh command every time user change quantity in the cart.

Link to comment
Share on other sites

  • 1 month later...
Somehow I got it working (at least for me:)) - the total weight in shopping cart summary, and auto update on quantity change. 

 


 

 

 

Confirmed works great on 1.6.0.14 but with manual refresh, any suggestions?

 

So can anyone confirm the auto update works or not, im confused

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

  • 6 months later...

Great!! Thanks a lot oskar86!! I just did it all and it totally works!! By the way, I did it on PS v1.6.1.10 and everything works great, even the auto-update, but as oskar86 said, you gotta be really carefull with locations.

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
On 10/5/2014 at 11:15 PM, oskar86 said:

"totalWeight": {$total_weight|json_encode},

 

About the auto update to work, it seems that this line of code must be placed in the following blockcart-json.tpl

/modules/blockcart_mod/views/templates/hook/blockcart-json.tpl

Link to comment
Share on other sites

  • 1 year later...

Hi, I have achieved it in 1.6.1.20 PS instance by following modifications (with autoupdate):

File: \classes\Cart.php (but you should use override here) -> added following lines:

3167:	$total_weight = $this->getTotalWeight();
3256:	'total_weight' => $total_weight,

File: \themes\yourtheme\js\cart-summary.js -> added following line:

958:   $('#total_weight').html(json.total_weight);

File: \themes\yourtheme\shopping-cart.tpl -> added following lines in proper place of your template shopping-cart.tpl file:

<tr class="cart_total_weight">
	<td colspan="{$col_span_subtotal}" class="text-right">{l s='Total weight'}</td>
	<td colspan="4" class="price"><span id="total_weight">{$cart->getTotalWeight()}</span> {Configuration::get('PS_WEIGHT_UNIT')}</td>
</tr>

 

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

  • 2 months later...
On 11/28/2017 at 1:10 AM, johnt said:

Thank you oskar86!

The instructions work on 1.6.1.17.

But there is no auto update of weight when changing quantities.

 

Anyone found a fix for this ??

edit /themes/default-bootstrap/js/cart-summary.js
no Ajax-cart.js and else

here is my develop notes, may help you, use posts in this thred to obtain it, combine oskar86 and karcharoth  post

worikg well here PS1.6.0.9

<?
//themes/default-bootstrap/modules/blockcart/blockcart-json.tpl
"totalWeight": {$total_weight|json_encode},{* tcl 2019-04-02 *}

//themes/default-bootstrap/product.tpl			
			            <p >{* tcl 2019-04-02 *}
				<label>{l s='Hmotnost:'} </label>
				<span class="editable">{round($product->weight,2)} kg</span> 
			</p>{* konec tcl 2019-04-02 *}
			
//themes/default-bootstrap/shopping-cart.tpl
                <tr class="cart_total_weight">{* tcl 2019-04-02 *}
                <td colspan="{$col_span_subtotal}" class="text-right"><span>{l s='Celková hmotnost'}</span></td>
                <td colspan="2" class="price"><span id="total_weight">{$cart->getTotalWeight()|escape:'htmlall':'UTF-8'|number_format:3} {Configuration::get('PS_WEIGHT_UNIT')}</span></td>{* konec tcl 2019-04-02 *}
                </tr>	

                <td rowspan="{3+$total_discounts_num+$use_show_taxes+$total_wrapping_taxes_num+1} " colspan="2" id="cart_voucher"class="cart_voucher">	
                
                <td rowspan="{3+$total_discounts_num+$use_show_taxes+$total_wrapping_taxes_num+1} {* tcl 2019-04-02 *}" colspan="2" id="cart_voucher" class="cart_voucher">							

//classes/Cart.php
	$total_weight = $this->getTotalWeight();
	'total_weight' => $total_weight.' '.Configuration::get('PS_WEIGHT_UNIT') /*tcl*/
	
//themes/default-bootstrap/js/cart-summary.js	
	    $('#total_weight').html(json.total_weight);  /*tcl*/

 

Edited by tcladin
code correction (see edit history)
Link to comment
Share on other sites

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