我从收货地址获得了我想要的所有数据:
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
如何获得产品?
答案 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);