2017-03-27 3 views
0

webservice経由で私のprestashopデータベースに新しい顧客を追加しようとしていますが、外観はすべて正常です。返信されるコードは200ですが、xml本文は空です。 。prestashop webservice経由で顧客を追加するとHttp bodyが空になる

私はGETとPUTのcrudメソッド用にWebサービスを有効にし、APIキーを生成しました。顧客添加用

コードは次のものである:

require_once('../../../lib/PSWebServiceLibrary.php'); 

$id_customer = 0; 
$id_address  = 0; 
$id_cart  = 0; 
$date_now  = date("Y-m-d H:i:s"); 
try { 

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); 

foreach ($pedidos->orders as $ord) { 

    if (!$id_customer) { 
     // Getting the empty XML document to send back completed 
     $xml = $webService->get(array('url' => PS_SHOP_PATH . 'api/customers?schema=blank')); 

     // Adding dinamic values 
     // Required 
     $xml->customer->passwd = Tools::encrypt($password = 'mypassword'); 
     $xml->customer->lastname = $ord->customer->lastname; 
     $xml->customer->firstname = $ord->customer->firstname; 
     $xml->customer->email = $ord->customer->customer_id.'@example.com'; 
     // Others 
     $xml->customer->id_lang = 1;//$id_lang; 
     $xml->customer->id_shop = 1; 
     $xml->customer->id_shop_group = 1; 
     $xml->customer->id_default_group = 3;//$id_group; // Customers 
     $xml->customer->active = 1; 
     $xml->customer->newsletter = 0; 
     $xml->customer->newsletter_date_add = $date_now; 
     $xml->customer->last_passwd_gen = $date_now; 
     $xml->customer->date_add = $date_now; 
     $xml->customer->date_upd = $date_now; 
     $xml->customer->id_gender = 0; 
     $xml->customer->associations->groups->group[0]->id = 3; // customers 

     // Adding the new customer 
     $opt = array('resource' => 'customers'); 
     $opt['postXml'] = $xml->asXML(); 
     $xml = $webService->add($opt); 
     $id_customer = $xml->customer->id; 
    } 
} 

}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(); 
} 

実行されると、これはコード200を返すが、応答本体が完全に空です。

<?xml version="1.0" encoding="UTF-8"?> 
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
<customer> 
    <id></id> 
    <id_default_group></id_default_group> 
    <id_lang></id_lang> 
    <newsletter_date_add></newsletter_date_add> 
    <ip_registration_newsletter></ip_registration_newsletter> 
    <last_passwd_gen></last_passwd_gen> 
    <secure_key></secure_key> 
    <deleted></deleted> 
    <passwd></passwd> 
    <lastname></lastname> 
    <firstname></firstname> 
    <email></email> 
    <id_gender></id_gender> 
    <birthday></birthday> 
    <newsletter></newsletter> 
    <optin></optin> 
    <website></website> 
    <company></company> 
    <siret></siret> 
    <ape></ape> 
    <outstanding_allow_amount></outstanding_allow_amount> 
    <show_public_prices></show_public_prices> 
    <id_risk></id_risk> 
    <max_payment_days></max_payment_days> 
    <active></active> 
    <note></note> 
    <is_guest></is_guest> 
    <id_shop></id_shop> 
    <id_shop_group></id_shop_group> 
    <date_add></date_add> 
    <date_upd></date_upd> 
<associations> 
<groups> 
    <group> 
     <id></id> 
    </group> 
</groups> 
</associations> 
</customer> 
</prestashop> 

なぜこのようなことが起こっているのですか?御時間ありがとうございます。

答えて

0

質問します。上に説明した私のケースでは、私は注文ごとに1つのウェブサービスが必要です:

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); 

この行はforeach iteraction内になければなりません。

関連する問題