cancel
Showing results for 
Search instead for 
Did you mean: 

Products Weight in Checkout

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Products Weight in Checkout

How to get total weight of products in checkout / shipping page / method.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Products Weight in Checkout

Hi @ari_salt 

 

I understand the requirement which you are trying to achieve !

 

Below is the code which helps you to get the weight from cart page to checkout page/shipping method :

 

protected $_cart;

public function __construct(
    ...
    \Magento\Checkout\Model\Cart $cartModel,
    ...
) {
    ...
    $this->_cart = $cartModel;
    ...
}

public function getTotalWeight()
{
    $items = $this->_cart->getQuote()->getAllItems();

    $weight = 0;
    foreach($items as $item) {
        $weight += ($item->getWeight() * $item->getQty()) ;        
    }

    return $weight;
}

Fore more details refer this link - https://magento.stackexchange.com/questions/160257/magento-2-get-total-weight-of-cart-products

 

Hope it helps !

if issue solved,Click Kudos & Accept as Solution

View solution in original post

1 REPLY 1

Re: Products Weight in Checkout

Hi @ari_salt 

 

I understand the requirement which you are trying to achieve !

 

Below is the code which helps you to get the weight from cart page to checkout page/shipping method :

 

protected $_cart;

public function __construct(
    ...
    \Magento\Checkout\Model\Cart $cartModel,
    ...
) {
    ...
    $this->_cart = $cartModel;
    ...
}

public function getTotalWeight()
{
    $items = $this->_cart->getQuote()->getAllItems();

    $weight = 0;
    foreach($items as $item) {
        $weight += ($item->getWeight() * $item->getQty()) ;        
    }

    return $weight;
}

Fore more details refer this link - https://magento.stackexchange.com/questions/160257/magento-2-get-total-weight-of-cart-products

 

Hope it helps !

if issue solved,Click Kudos & Accept as Solution