Add order web service

穿精又带淫゛_ 提交于 2019-12-12 00:23:33

问题


I developed a Prestashop web service for a mobile application.

I can connect a user, create user accounts, create cart but I do not manage to create orders.

I have the following error:

HTTP XML response is not parsable: array ( 0 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 9, 'column' => 64, 'message' => 'Input is not proper UTF-8, indicate encoding ! Bytes: 0x95 0x08 0x77 0xE2 ', 'file' => '', 'line' => 778, )), 1 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 9, 'column' => 65, 'message' => 'PCDATA invalid Char value 8 ', 'file' => '', 'line' => 778, )), 2 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 9, 'column' => 77, 'message' => 'PCDATA invalid Char value 12 ', 'file' => '', 'line' => 778, )), 3 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 9, 'column' => 78, 'message' => 'PCDATA invalid Char value 14 ', 'file' => '', 'line' => 778, )), 4 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 51, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 14954, )), 5 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 51, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 17864, )), 6 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 51, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 20773, )), 7 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column' => 33, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 21368, )), )

I tried to change the encoding of the page in UTF-8 but nothing can be done.

Here is my PHP:

<?php

// Here's how you create a webservice call:
define('PS_SHOP_PATH', 'localhost:8888/MON_SITE');
define('PS_WS_AUTH_KEY', 'MA_CLEF');
define('DEBUG', true);

require_once('PSWebServiceLibrary.php');

try {

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'orders');
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=synopsis'));

$xml->children()->children()->id_address_delivery = 6; 
$xml->children()->children()->id_address_invoice =  6; 
$xml->children()->children()->id_cart = 136; 
$xml->children()->children()->id_currency = 1;
$xml->children()->children()->current_state = 1;
$xml->children()->children()->id_lang = 1;
$xml->children()->children()->id_customer = 1; 
$xml->children()->children()->id_carrier = 0;
$xml->children()->children()->total_paid = '56973';
$xml->children()->children()->total_paid_real = '56973';
$xml->children()->children()->total_paid_tax_excl = '56973';
$xml->children()->children()->total_paid_tax_incl = '56977';
$xml->children()->children()->total_products = 1338;
$xml->children()->children()->total_products_wt = 1337;
$xml->children()->children()->conversion_rate = '1';
$xml->children()->children()->secure_key = md5('-1');
$xml->children()->children()->valid = 1;
$xml->children()->children()->module = 'Cheque';
$xml->children()->children()->payment = 'cheque';
$xml->children()->children()->current_state = 1;

unset($xml->children()->children()->id);
unset($xml->children()->children()->date_add);
unset($xml->children()->children()->date_upd);
unset($xml->children()->children()->associations);
unset($xml->children()->children()->delivery_date);
unset($xml->children()->children()->invoice_date);
unset($xml->children()->children()->total_discounts_tax_incl);
unset($xml->children()->children()->total_discounts_tax_excl);

$xml = $webService->add(array('resource' => 'orders',
'postXml' => $xml->asXML()
));

$resources = $xml->children()->children();
echo "Successfully added order.".$resources->id;

}
catch (PrestaShopWebserviceException $ex)
{
    // Here we are dealing with errors
    $trace = $ex->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 />'.$ex->getMessage();
}
?>

回答1:


Dear try this code where you get xml response.

$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object");
print_r($xml);

Check this out XML Parsing PHP



来源:https://stackoverflow.com/questions/32483638/add-order-web-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!