如何在prestashop的订单确认页面获取产品详细信息?

时间:2015-09-04 09:33:51

标签: prestashop

我已创建自定义模块以发送curl请求。在此我获得当前用户的送货地址,但我想在订单确认页面中获取产品详细信息。我怎么能这样做?

这是我的代码:

  public function hookOrderConfirmation($params)
  {
    **Here i want to print product details**
    echo $this->context->customer->firstname ."<br/>";
    echo $this->context->customer->lastname ."<br/>";
    echo $this->context->customer->email ."<br/>";
    die("GET ALL DETAILS.");

    //set POST variables
    $url = 'http://localhost/wrd-folder/web-service/';
    $fields = array(
                'first_name' => urlencode("Testing1"),
                'last_name' => urlencode("Testing2"),
                'username' => urlencode("Testing1"),
                'email' => urlencode("testing@gmail.com"),
                'membership_id' => urlencode("676"),
                'password' => urlencode("12345678"),
                'password2' => urlencode("12345678")
            );

    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');

    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

    //execute post
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);

    //Lets display our template file.
    return $this->display(__FILE__, 'sentcurl.tpl');

  } // End of hookOrderConfirmation

2 个答案:

答案 0 :(得分:1)

您可以通过几行来完成此任务。您有两个选择:

  1. 获取产品数组及其价格

    $order = $params['objOrder'];
    // array with products with price, quantity (with taxes and without)
    $products = $order->getProducts();
    
  2. 获取更详细的产品数组:

    $order = $params['objOrder'];
    $products_with_details = $order->getProductsDetail();
    

答案 1 :(得分:0)

您将得到:

$order          =   new Order($id_order);
$products       =   $order->getProducts();

foreach($products as $product):
..

$ product具有您所需的每个参数。