Jump to content

[1.7.2] Show total weight on cart


yeye412

Recommended Posts

  • 1 month later...

Hi

I dont understand, 1st sentence shopping cart 2nd sentence itsproduct page. In product page where do you want the weight? Then on cart you want on the right side like weight all products: and then the weight of all products combined?


 

Quote

 

and i want to show to buyer total price of his cart.


 

What do you mean? You mean you want to show total price of his cart + shipping cost in cart?

Becaulse prestashop already shows total price in cart.

 

:) Daan

Link to comment
Share on other sites

Got the answer.

Go to file src\Adapter\Cart\CartPresenter.php

on line 299. paste code  

$totalWeight = $cart->getTotalWeight();

 

And on line 435 paster code

'total_weight' => $totalWeight,

 

DONE.. in php.

Now go to themes/yourtheme/templates/checkout/_partial/cart-detailerd-totals.tpl

On line 48 add code

   <div class="cart-summary-line" id="cart-subtotal-shipping">
      <span class="label">Total Berat</span>
      <span class="value">{$cart.total_weight|string_format:"%.2f"}{Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
  </div>

 

Finish display check these screen shoot

 

Q-slHF7iSR_ygYzRQYNF0g.png

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

  • 5 months later...
On 2017/11/10 at 4:25 AM, ABANGWEB said:

Got the answer.

Go to file src\Adapter\Cart\CartPresenter.php

on line 299. paste code  

$totalWeight = $cart->getTotalWeight();

 

And on line 435 paster code

'total_weight' => $totalWeight,

 

DONE.. in php.

Now go to themes/yourtheme/templates/checkout/_partial/cart-detailerd-totals.tpl

On line 48 add code

   <div class="cart-summary-line" id="cart-subtotal-shipping">
      <span class="label">Total Berat</span>
      <span class="value">{$cart.total_weight|string_format:"%.2f"}{Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
  </div>

 

Finish display check these screen shoot

 

Q-slHF7iSR_ygYzRQYNF0g.png

 

Hello 

I have followed your step, and I get this error, every time I have modify the quantity of the product, the total amount will be duplicated on another line, pls see the picture I have attached.  any solution?

 

 

1.png

Link to comment
Share on other sites

On 2017/11/10 at 4:25 AM, ABANGWEB said:

Got the answer.

Go to file src\Adapter\Cart\CartPresenter.php

on line 299. paste code  

$totalWeight = $cart->getTotalWeight();

 

And on line 435 paster code

'total_weight' => $totalWeight,

 

DONE.. in php.

Now go to themes/yourtheme/templates/checkout/_partial/cart-detailerd-totals.tpl

On line 48 add code

   <div class="cart-summary-line" id="cart-subtotal-shipping">
      <span class="label">Total Berat</span>
      <span class="value">{$cart.total_weight|string_format:"%.2f"}{Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
  </div>

 

Finish display check these screen shoot

 

Q-slHF7iSR_ygYzRQYNF0g.png

 

and i'm wondering how to get the product weight in the product details like your screenshot???

 

 

2.png

Link to comment
Share on other sites

  • 3 months later...

I am using 1.7.3.2

I just made some changes on Cart page like below:

https://www.prestashop.com/forums/topic/627417-172-show-total-weight-on-cart/

I think it's because of this...

Showing error like this on Debug-Mode.

 

ContextErrorException in Cart.php line 3601:

Notice: Undefined index:

  1. in Cart.php line 3601
  2. at ErrorHandler->handleError('8', 'Undefined index: ', '/classes/Cart.php', '3601', array('products' => null)) in Cart.php line 3601
  3. at CartCore->getTotalWeight() in CartPresenter.php line 290
  4. at CartPresenter->present(object(Cart)) in FrontController.php line 500
  5. at FrontControllerCore->assignGeneralPurposeVariables() in FrontController.php line 549
  6. at FrontControllerCore->initContent() in OrderConfirmationController.php line 93
  7. at OrderConfirmationControllerCore->initContent() in Controller.php line 253
  8. at ControllerCore->run() in Dispatcher.php line 428
  9. at DispatcherCore->dispatch() in index.php line 28

 

What can I do??

Link to comment
Share on other sites

  • 4 months later...

Hi, It works perfect . 

I'm wondering if $width , $length , $height can be called likewise . I had tried that but it is resulting into the internal error 500 .  I need this to calculate the CBM of the product . 

It seems these variables $totalwidth etc needs to be defined somewhere . Please help

Link to comment
Share on other sites

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

First, big thanks ABANGWEB for the code !
It works like a charm !

If this can help someone, here's what I just did for setting it up successfully on version 1.7.5.1, locations are little different from 1.7.2 :

1 - Edit the file ../src/Adapter/Presenter/Cart/CartPresenter.php
Add a new line after line 326 (after ... Cart::ONLY_PRODUCTS); ): 

$totalWeight = $cart->getTotalWeight();

Add a new line after line 461 (or 462 if you have add the previous line - after 'discounts' => $discounts, ): 

'total_weight' => $totalWeight,


2 - Edit the file ../themes/<YourTheme>/templates/checkout/_partials/cart-detailed-totals.tpl
Add a new line after line 45 ( right after {/foreach} ) and add :

   <div class="cart-summary-line" id="cart-subtotal-shipping">
      <span class="label">Total Weight</span>
      <span class="value">{$cart.total_weight|string_format:"%.2f"} {Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
  </div>

You're done !
:D

  • Thanks 3
Link to comment
Share on other sites

  • 8 months later...
  • 2 months later...
  • 1 month later...
  • 1 month later...

Hi,

In Prestashop 1.7.6.4 works almost perfect. Just needed to move following code

   <div class="cart-summary-line" id="cart-subtotal-shipping">
      <span class="label">Total Weight</span>
      <span class="value">{$cart.total_weight|string_format:"%.2f"} {Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
  </div>

after

  {block name='cart_summary_totals'}
    {include file='checkout/_partials/cart-summary-totals.tpl' cart=$cart}
  {/block}

because it was duplicating cart total everytime I changed items quantity.

Any idea how to display total weight in order-confirmation.tpl? Above solution displays value 0.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
On 5/2/2019 at 6:17 PM, LionelR said:

First, big thanks ABANGWEB for the code !
It works like a charm !

If this can help someone, here's what I just did for setting it up successfully on version 1.7.5.1, locations are little different from 1.7.2 :

1 - Edit the file ../src/Adapter/Presenter/Cart/CartPresenter.php
Add a new line after line 326 (after ... Cart::ONLY_PRODUCTS); ): 


$totalWeight = $cart->getTotalWeight();

Add a new line after line 461 (or 462 if you have add the previous line - after 'discounts' => $discounts, ): 


'total_weight' => $totalWeight,


2 - Edit the file ../themes/<YourTheme>/templates/checkout/_partials/cart-detailed-totals.tpl
Add a new line after line 45 ( right after {/foreach} ) and add :


   <div class="cart-summary-line" id="cart-subtotal-shipping">
      <span class="label">Total Weight</span>
      <span class="value">{$cart.total_weight|string_format:"%.2f"} {Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
  </div>

You're done !
:D

Work like a charm at 1.7.5.2 ! Thank you

Link to comment
Share on other sites

  • 2 months later...
On 11/10/2017 at 10:25 AM, ABANGWEB said:

Got the answer.

Go to file src\Adapter\Cart\CartPresenter.php

on line 299. paste code  

$totalWeight = $cart->getTotalWeight();

 

And on line 435 paster code

'total_weight' => $totalWeight,

src\Adapter\Cart\CartPresenter.php is deprecated since 1.7.4.0

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

  • 7 months later...
On 1/21/2021 at 1:33 PM, Alexander Firsov said:

Please make sure that you have entered the product weight in the Catalog -> Products section of Back Office

Add Line after: $productsTotalExcludingTax = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);

$totalWeight = $cart -> getTotalWeight ();

Add Line after 'discounts' => $discounts,

'total_weight' => $totalWeight,

Working 1.7.7.6

Link to comment
Share on other sites

  • 1 year later...
On 8/21/2021 at 10:51 PM, Galomen said:

Add Line after: $productsTotalExcludingTax = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);

$totalWeight = $cart -> getTotalWeight ();

Add Line after 'discounts' => $discounts,

'total_weight' => $totalWeight,

Working 1.7.7.6

Hello I am a newbie is this solution working also for version 1.7.8.8? Need to see the total weight on the invoice and on display. Best

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