简体   繁体   English

prestashop api 1.6 webservice更新订单状态

[英]prestashop api 1.6 webservice Update order status

I have gone through a lot of documentation and could solve the problem I need to update order status of an order. 我已经阅读了大量文档,可以解决更新订单订单状态所需的问题。 I am using PrestaShopWebservice.php for calling the webservice api now what im facing is that if i directly call the orders api and try to edit and upload the xml it shows the error that 我正在使用PrestaShopWebservice.php来调用webservice api现在我面临的是如果我直接调用命令api并尝试编辑并上传xml它会显示错误

"CDATA[XML error : String could not be parsed as XML" “CDATA [XML错误:字符串无法解析为XML”

even also when order_histories same thing happens any help will be appreciated. 甚至当order_histories同样的事情发生时,任何帮助将不胜感激。

I just had the issue and finally found a solution. 我刚刚遇到问题,最后找到了解决方案。

  1. Get the blank schema for the order_histories 获取order_histories的空白模式
$opt = [
    'resource' => 'order_histories?schema=blank'
];
$xml = Prestashop::get($opt);
$resources = $xml->children()->children();
  1. Specify the order id, employee id and order state id on the resource 在资源上指定订单ID,员工ID和订单状态ID
$resources->id_order = 1;
$resources->id_employee = 1;
$resources->id_order_state = 6;
  1. Create the request and send it to your webservice. 创建请求并将其发送到您的Web服务。
$opt = [
    'resource' => 'order_histories',
    'postXml' => $xml->asXML()
];
Prestashop::add($opt);

In my example, "Prestashop" is a facade for the Prestashop Webservice Library 在我的示例中,“Prestashop”是Prestashop Webservice Library的外观

Try this one to update 试试这个更新

<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>&nbsp;'.
        '</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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM