2016-03-02 34 views
0

我從送貨地址,我想所有的數據與此產品:的Prestashop得到一個訂單

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

您已經使用:

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

所以我認爲你可以使用:

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

您需要加載順序明細對象獲得的Prestashop的特定順序編號的產品。

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