2016-12-06 53 views
1

的Prestashop 1.6.1.7 你好, 我有一個功能,如多張照片,產品名稱,產品價格,接觸我的網站訪問者部分,他們可以表達自己的產品(二手)賣家,描述,關鍵字(可選)他們。 我經歷的Prestashop web服務的形式提交,並在二手產品種類記錄, 分類ID是994 後,我寫了這個代碼:的Prestashop 1.6新增產品與web服務

<?php 
 
$shop_url = 'http://subdomain.test.com'; 
 
$secret_key = '9CQEDRKAD5IF8C9FFPP59T7AJSCPIW2Q'; 
 
$debug = true; 
 
    
 
require_once('./PSWebServiceLibrary.php'); 
 
    
 
\t try { 
 
\t \t $webService = new PrestaShopWebservice($shop_url, $secret_key, $debug); 
 
\t \t $xml = $webService->get(array('url' => $shop_url.'/api/products?schema=blank')); 
 
\t \t $resources = $xml->children()->children(); 
 
\t \t 
 
\t \t if (!isset($_POST['btn_submit'])) 
 
\t \t { 
 
\t \t \t $html = '<form action="" method="POST"><table border=1>'; 
 
\t \t \t foreach ($resources as $key => $resource) 
 
\t \t \t { 
 
\t \t \t \t $html .= '<tr><th>'.$key.'</th><td>'; 
 
\t \t \t \t $html .= '<input type="text" name="form['.$key.']" value=""/>'; 
 
\t \t \t \t $html .= '</td></tr>'; 
 
\t \t \t } 
 
\t \t \t $html .= '<td colspan=2><input type="submit" name="btn_submit" value="btn_submit" /></td>'; 
 
\t \t \t $html .= '</table></form>'; 
 
\t \t \t echo $html; 
 
\t \t } 
 
\t \t else 
 
\t \t { 
 
\t \t \t foreach ($resources as $nodeKey => $node) 
 
\t \t \t { 
 
\t \t \t \t $resources->$nodeKey = $_POST['form'][$nodeKey]; 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t try { \t \t 
 
\t \t \t \t $opt = array('resource' => 'products'); 
 
\t \t \t \t $opt['postXml'] = $xml->asXML(); 
 
\t \t \t \t $xml = $webService->add($opt); 
 
\t \t \t \t echo "Successfully added."; \t \t \t 
 
\t \t \t } 
 
\t \t \t catch(PrestaShopWebserviceException $ex) { 
 
\t \t \t \t echo 'Other error: <br />' . $ex->getMessage(); 
 
\t \t \t } 
 
\t \t } 
 
\t } 
 
\t catch (PrestaShopWebserviceException $ex) { 
 
\t \t echo 'Other error: <br />' . $ex->getMessage(); 
 
\t } 
 
?>

這是add_product .php在prestashop根文件夾中。Prestashop根文件夾中的PSWebServiceLibrary.php。

爲什麼不能正常工作,我怎樣才能總結產品名稱,產品說明,產品價格等形式。

screentshot附。

enter image description here

回答

0

必須激活的Prestashop調試模式Activate Prestashop Debug Mode。通過這種方式,Prestashop會告訴你什麼是產品XML的確切問題。應該是某個字段沒有通過產品驗證過程,因爲格式不正確或不允許。

祝你好運。