prestashop获得订单的产品

时间:2016-03-02 19:58:14

标签: prestashop prestashop-1.6

我从收货地址获得了我想要的所有数据:

public function getOrderShippingCost($params, $shipping_cost)
    {
        global $smarty;
$url = Tools::getHttpHost(true).__PS_BASE_URI__;
$address = new Address($this->context->cart->id_address_delivery);
        $state = new State ($address->id_state);
        $country = new Country ($address->id_country);

echo $address->postcode;

        echo $address->country;

        echo $address->address1;

        echo $address->address2;

        echo $state->name;

        echo $country->iso_code;

结果很好,但现在我怎样才能获得订单的产品?

我试试这段代码:

$products = $params['cart']->getProducts(true);

但结果是Fatal error: Cannot use object of type Cart as array in

如果我尝试这样的事情:

$order = new Order($this->context->order->id_order);

结果是两个错误:

Notice: Undefined property: Context::$order in /var/www/prestashop/modules/mycarrier/mycarrier.php on line 325

Notice: Trying to get property of non-object in /var/www/prestashop/modules/mycarrier/mycarrier.php on line 325

如何获得产品?

2 个答案:

答案 0 :(得分:4)

您已经使用:

new Address($this->context->cart->id_address_delivery);

所以我认为你可以使用:

$products = $this->context->cart->getProducts(true);

答案 1 :(得分:1)

您需要加载订单明细对象,以便在prestashop中获取特定订单ID的产品。

$ProductDetailObject = new OrderDetail;
$product_detail = $ProductDetailObject->getList($order_id);