2016-03-17 72 views
2

我已经经历了很多文档,可以解决我需要更新订单的订单状态的问题。我使用PrestaShopWebservice.php调用webservice api现在im面临的是,如果我直接调用订单api并尝试编辑并上载xml它显示错误 “CDATA [XML错误:字符串不能被解析为XML“甚至当 order_histories相同的事情发生任何帮助将不胜感激。我已经尝试了很多东西,无法到达任何地方。 在此先感谢prestashop api 1.6 webservice更新订单状态

回答

1

我刚做了这个问题,并最终找到了解决办法。

  1. 查看该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; 
    
    1. 创建请求并将其发送到您的Web服务。
    $opt = [ 
        'resource' => 'order_histories', 
        'postXml' => $xml->asXML() 
    ]; 
    Prestashop::add($opt); 
    

    在我的例子, “的Prestashop” 对于Prestashop Webservice Library

    一个门面
    0

    试试这个更新

    <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 [email protected] 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 <[email protected]> 
    * @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>