如何从购物车prestashop获得总重量

时间:2016-03-08 00:14:24

标签: prestashop

我知道如何从订单中获得总重量,就像那样:

$orderWeight = sprintf("%.2f ".Configuration::get('PS_WEIGHT_UNIT'), (float)$order->getTotalWeight());

但我尝试更改$order $cart,但结果是错误,那么如何从购物车中获得总重量?

我有这个:

$products = $this->context->cart->getProducts(true);
        $orderWeight = sprintf("%.2f ".Configuration::get('PS_WEIGHT_UNIT'), (float)$products->getTotalWeight());
        echo $orderWeight;

致命错误:在非对象

上调用成员函数getTotalWeight()

1 个答案:

答案 0 :(得分:1)

Cart类包含方法getTotalWeight()

您应该能够使用以下代码获得购物车重量:

$cartWeight = sprintf("%.2f ".Configuration::get('PS_WEIGHT_UNIT'), $this->context->cart->getTotalWeight());