How to get total weight of products in checkout / shipping page / method.
Solved! Go to Solution.
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 !
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 !