How can We achieve this?
We get total weight of products of cart in Magento 2 by MagentoCheckoutModelCart class
With objectManager
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$cart = $objectManager->get('MagentoCheckoutModelCart');
$items = $cart->getQuote()->getAllItems();
$weight = 0;
foreach($items as $item) {
$weight += ($item->getWeight() * $item->getQty()) ;
}
echo $weight;
With Factory Method
protected $_cart;
public function __construct(
...
MagentoCheckoutModelCart $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;
}