我正在尝试通过 web 服务创建与 prestashop 的 API 连接
我可以成功创建客户、地址、购物车(有关于客户 CRUD 的众所周知的纯文档,它按预期工作)
我无法完成新订单:
有源代码片段
require_once('config.php'); // PS_SHOP_PATH etc.
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=blank'));
$xml->children()->children()->id_address_delivery = 1;
$xml->children()->children()->id_address_invoice = 1;
$xml->children()->children()->id_cart = 25;
$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 = 'Bankwire';
$xml->children()->children()->payment = 'bankwire';
$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();
}
还有一部分。来自 Fiddler 的 webview 日志
XML SENT
xml=<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
<id_address_delivery>1</id_address_delivery>
<id_address_invoice>1</id_address_invoice>
<id_cart>25</id_cart>
<id_currency>1</id_currency>
<id_lang>1</id_lang>
<id_customer>1</id_customer>
<id_carrier>0</id_carrier>
<current_state>1</current_state>
<module>Bankwire</module>
<invoice_number/>
<delivery_number/>
<valid>1</valid>
<id_shop_group/>
<id_shop/>
<secure_key>6bb61e3b7bce0931da574d19d1d82c88</secure_key>
<payment>bankwire</payment>
<recyclable/>
<gift/>
<gift_message/>
<mobile_theme/>
<total_discounts/>
<total_paid>56973</total_paid>
<total_paid_tax_incl>56977</total_paid_tax_incl>
<total_paid_tax_excl>56973</total_paid_tax_excl>
<total_paid_real>56973</total_paid_real>
<total_products>1338</total_products>
<total_products_wt>1337</total_products_wt>
<total_shipping/>
<total_shipping_tax_incl/>
<total_shipping_tax_excl/>
<carrier_tax_rate/>
<total_wrapping/>
<total_wrapping_tax_incl/>
<total_wrapping_tax_excl/>
<shipping_number/>
<conversion_rate>1</conversion_rate>
<reference/>
</order>
</prestashop>
RETURN HTTP BODY 致命错误 其他错误
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, )), )
“其他错误”来自于此:
else echo 'Other error<br />'.$ex->getMessage();
PSWebServiceLibrary 包含
/** @var array compatible versions of PrestaShop Webservice */
const psCompatibleVersionsMin = '1.4.0.17';
const psCompatibleVersionsMax = '1.5.4.1';
PrestaShop 是 1.5.4.0
有什么建议吗?