【发布时间】:2015-07-07 07:14:29
【问题描述】:
我正在制作一个桥接应用程序。将仓库数据库中的产品数量与 Prestashop 1.6 Multi-Store 购物车同步。
脚本只需要一次更新一个产品数量,我们有产品“ID”和“数量”,但是,我不断返回以下错误:
RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[93]]></code>
<message><![CDATA[parameter "quantity" not writable. Please remove this attribute of this XML]]></message>
</error>
</errors>
</prestashop>
附带: 其他错误 此对 PrestaShop Web 服务的调用失败并返回 HTTP 状态 400。这意味着:错误请求。
XML 错误代码 93 是描述符中不存在该表。我认为这是通过包含 "$opt = array('resource' => 'products');"
网站上还启用了高级库存控制,此脚本不会对其进行调整(应该也包括这个,也许下一个版本)。
我用来获取 XML、更改数量值和更新的代码是:
function test1($id, $quantity){
$id = (int)$id;
$quantity = (int)$quantity;
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products', 'display' => '[id,quantity]');
if (isset($id))
$opt['id'] = $id;
$xml = $webService->get($opt);
$resources = $xml->children()->children();
}
catch (PrestaShopWebserviceException $e)
{
// 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();
}
if (isset($id) && isset($quantity)){
$resources->id = $id;
$resources->quantity = $quantity;
// Call the web service
try
{
$opt = array('resource' => 'products');
$opt['putXml'] = $xml->asXML();
$opt['id'] = $id;
$xml = $webService->edit($opt);
echo "Successfully updated.";
}
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();
}
}
}
我用来更新的初始 XML 是:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product id="45" xlink:href="https://www.WEBSITE.com/api/products/45"/>
</prestashop>
为更新发送的 XML 是:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product id="45" xlink:href="https://www.WEBSITE.com/api/products/45"><id>45</id><quantity>22</quantity></product>
</prestashop>
似乎发送的 XML 或其他东西缺少表引用或其他东西。
我尝试了几种方法,结果都一样。有什么想法吗?
谢谢
【问题讨论】:
-
更新: 我发现 Product->quantity 是写保护的,并且数量需要在其他地方更新,例如 Stock_available->quantity 我可以做。但是,当我直接在数据库中更新这两个值作为测试时,它们不会显示在后台。因此,更新库存并将其显示在后台会更加复杂。任何人都知道究竟要更新什么来改变库存水平,如何更新写保护的产品->数量,以及如何让更新显示在后台?
标签: xml webservice-client prestashop-1.6