2016-03-17 71 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>