PrestaShop:无法使用 Web 服务创建订单

PrestaShop: Can't create order with web service

我正在尝试使用我拥有的另一个网页上的网络服务创建订单。我是 运行 PrestaShop 1.7 的最新版本。这真的很基本,只需输入产品 ID 和数量。这是我的第一个严肃任务,我正在努力完成这项工作,但它仍然没有。我即将展示的代码可以创建购物车,但由于某种原因无法创建订单。

代码:

try {
/*
 Creating new cart
 */

$xml = $webService->get( array( 'url' => PS_SHOP_PATH .'/api/carts?schema=blank' ) );


// Required
$xml->cart->id_currency         = 1;
$xml->cart->id_lang             = 1;

foreach($_SESSION['vezimas'] as $i => $vezimas) {
    $xml->cart->associations->cart_rows->cart_row[$i]->id_product = $vezimas['product_id'];
    $xml->cart->associations->cart_rows->cart_row[$i]->quantity = $vezimas['qty'];
}

// Adding the new cart
$opt = array( 'resource' => 'carts' );
$opt['postXml'] = $xml->asXML();
$xml = $webService->add( $opt );
$id_cart = $xml->cart->id;

/*
Creating Order
*/

// Getting the structure of an order
$xml = $webService->get(array('url' => PS_SHOP_PATH .'/api/orders/?schema=blank'));

// Required
$xml->order->id_address_delivery    = 6; // Customer address
$xml->order->id_address_invoice     = 6;
$xml->order->id_cart                = $id_cart;
$xml->order->id_currency            = 1;
$xml->order->id_lang                = 1;
$xml->order->id_customer            = 2;
$xml->order->id_carrier             = 1;
$xml->order->module                 = 'ps_checkpayment';
$xml->order->payment                = 'Payments by check';
$xml->order->total_paid             = 0;
$xml->order->total_paid_real        = 0;
$xml->order->total_products         = $_SESSION['prekesNum'];
$xml->order->total_products_wt      = 0;
$xml->order->conversion_rate        = 1;

// Others
$xml->order->valid                      = 1;

// Order Row. Required
foreach($_SESSION['vezimas'] as $i => $vezimas) {
    $xml->order->associations->order_rows->order_row[0]->product_id = $vezimas['product_id'];
    $xml->order->associations->order_rows->order_row[0]->product_quantity = $vezimas['qty'];
}

// Creating the order
$opt = array( 'resource' => 'orders' );
$opt['postXml'] = $xml->asXML();
$xml = $webService->add( $opt );
$id_order = $xml->order->id;
}  catch (PrestaShopWebserviceException $e) {

// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$e->getMessage();
}

我在调试中遇到致命错误,页面上是这样的:

Other error
HTTP XML response is not parsable: array ( 0 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 4, 'column' => 1, 'message' => 'Start tag expected, \'<\' not found ', 'file' => '', 'line' => 1, )), )

在我的购物车代码中添加了更多字段和安全密钥,然后一切正常。