prestashop api 1.6 webservice 更新订单状态
prestashop api 1.6 webservice Update order status
我查阅了大量文档,可以解决我需要更新订单状态的问题。我正在使用 PrestaShopWebservice.php 调用网络服务 api 现在我面临的是,如果我直接调用订单 api 并尝试编辑和上传 xml 它会显示错误那
"CDATA[XML error : String could not be parsed as XML"
甚至当
order_histories
同样的事情发生任何帮助将不胜感激。
试试这个来更新
<html><head><title>CRUD Tutorial - Update example</title></head><body>
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* PrestaShop Webservice Library
* @package PrestaShopWebservice
*/
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'XX'); // XX= your website url
define('PS_WS_AUTH_KEY', 'xx'); // xx= Your Webservice Key
require_once('PSWebServiceLibrary.php');
// First : We always get the customer's list or a specific one
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'orders');
if (isset($_GET['id']))
$opt['id'] = $_GET['id'];
$xml = $webService->get($opt);
// Here we get the elements from children of customer markup which is children of prestashop root markup
$resources = $xml->children()->children();
}
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();
}
// Second : We update the data and send it to the web service
if (isset($_GET['id']) && isset($_POST['id'])) // Here we check id cause in every resource there's an id
{
// Here we have XML before update, lets update XML with new values
foreach ($resources as $nodeKey => $node)
{
$resources->$nodeKey = $_POST[$nodeKey];
}
// And call the web service
try
{
$opt = array('resource' => 'orders');
$opt['putXml'] = $xml->asXML();
$opt['id'] = $_GET['id'];
$xml = $webService->edit($opt);
// if WebService don't throw an exception the action worked well and we don't show the following message
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();
}
}
// UI
// We set the Title
echo '<h1>Customer\'s ';
if (isset($_GET['id'])) echo 'Update';
else echo 'List';
echo '</h1>';
// We set a link to go back to list if we are in customer's details
if (isset($_GET['id']))
echo '<a href="?">Return to the list</a>';
if (isset($_GET['id']))
echo '<form method="POST" action="?id='.$_GET['id'].'">';
echo '<table border="5">';
if (isset($resources))
{
echo '<tr>';
if (!isset($_GET['id']))
{
//Show list of customers
echo '<th>Id</th><th>More</th></tr>';
foreach ($resources as $resource)
{
echo '<td>'.$resource->attributes().'</td><td>'.
'<a href="?id='.$resource->attributes().'">Update</a> '.
'</td></tr>';
}
}
else
{
//Show customer form
echo '</tr>';
foreach ($resources as $key => $resource)
{
echo '<tr><th>'.$key.'</th><td>';
echo '<input type="text" name="'.$key.'" value="'.$resource.'"/>';
echo '</td></tr>';
}
}
}
echo '</table><br/>';
if (isset($_GET['id']))
echo '<input type="submit" value="Update"></form>';
?>
</body></html>
我刚遇到问题,终于找到了解决方案。
- 获取
order_histories
的空白架构
$opt = [
'resource' => 'order_histories?schema=blank'
];
$xml = Prestashop::get($opt);
$resources = $xml->children()->children();
- 指定资源上的订单 ID、员工 ID 和订单状态 ID
$resources->id_order = 1;
$resources->id_employee = 1;
$resources->id_order_state = 6;
- 创建请求并将其发送到您的网络服务。
$opt = [
'resource' => 'order_histories',
'postXml' => $xml->asXML()
];
Prestashop::add($opt);
在我的示例中,"Prestashop" 是 Prestashop Webservice Library
的外观
我查阅了大量文档,可以解决我需要更新订单状态的问题。我正在使用 PrestaShopWebservice.php 调用网络服务 api 现在我面临的是,如果我直接调用订单 api 并尝试编辑和上传 xml 它会显示错误那
"CDATA[XML error : String could not be parsed as XML"
甚至当
order_histories
同样的事情发生任何帮助将不胜感激。
试试这个来更新
<html><head><title>CRUD Tutorial - Update example</title></head><body>
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* PrestaShop Webservice Library
* @package PrestaShopWebservice
*/
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'XX'); // XX= your website url
define('PS_WS_AUTH_KEY', 'xx'); // xx= Your Webservice Key
require_once('PSWebServiceLibrary.php');
// First : We always get the customer's list or a specific one
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'orders');
if (isset($_GET['id']))
$opt['id'] = $_GET['id'];
$xml = $webService->get($opt);
// Here we get the elements from children of customer markup which is children of prestashop root markup
$resources = $xml->children()->children();
}
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();
}
// Second : We update the data and send it to the web service
if (isset($_GET['id']) && isset($_POST['id'])) // Here we check id cause in every resource there's an id
{
// Here we have XML before update, lets update XML with new values
foreach ($resources as $nodeKey => $node)
{
$resources->$nodeKey = $_POST[$nodeKey];
}
// And call the web service
try
{
$opt = array('resource' => 'orders');
$opt['putXml'] = $xml->asXML();
$opt['id'] = $_GET['id'];
$xml = $webService->edit($opt);
// if WebService don't throw an exception the action worked well and we don't show the following message
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();
}
}
// UI
// We set the Title
echo '<h1>Customer\'s ';
if (isset($_GET['id'])) echo 'Update';
else echo 'List';
echo '</h1>';
// We set a link to go back to list if we are in customer's details
if (isset($_GET['id']))
echo '<a href="?">Return to the list</a>';
if (isset($_GET['id']))
echo '<form method="POST" action="?id='.$_GET['id'].'">';
echo '<table border="5">';
if (isset($resources))
{
echo '<tr>';
if (!isset($_GET['id']))
{
//Show list of customers
echo '<th>Id</th><th>More</th></tr>';
foreach ($resources as $resource)
{
echo '<td>'.$resource->attributes().'</td><td>'.
'<a href="?id='.$resource->attributes().'">Update</a> '.
'</td></tr>';
}
}
else
{
//Show customer form
echo '</tr>';
foreach ($resources as $key => $resource)
{
echo '<tr><th>'.$key.'</th><td>';
echo '<input type="text" name="'.$key.'" value="'.$resource.'"/>';
echo '</td></tr>';
}
}
}
echo '</table><br/>';
if (isset($_GET['id']))
echo '<input type="submit" value="Update"></form>';
?>
</body></html>
我刚遇到问题,终于找到了解决方案。
- 获取
order_histories
的空白架构
$opt = [
'resource' => 'order_histories?schema=blank'
];
$xml = Prestashop::get($opt);
$resources = $xml->children()->children();
- 指定资源上的订单 ID、员工 ID 和订单状态 ID
$resources->id_order = 1;
$resources->id_employee = 1;
$resources->id_order_state = 6;
- 创建请求并将其发送到您的网络服务。
$opt = [
'resource' => 'order_histories',
'postXml' => $xml->asXML()
];
Prestashop::add($opt);
在我的示例中,"Prestashop" 是 Prestashop Webservice Library
的外观