问题
I try to add a product via web service and I receive bellow error code:
RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>
I am searching 2 days but nothing. Please can anyone help me? My Code is below.
define('DEBUG', true);
define('_PS_DEBUG_SQL_', true);
define('PS_SHOP_PATH', 'http://mywebsiteinlocalhost.gr/dev...shop/trunk/src/');
define('PS_WS_AUTH_KEY', 'CBYB5G5UVRA7FCN7JK2WZ625DFWG8SK3');
require_once ('./PSWebServiceLibrary.php');
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products');
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/products?schema=synopsis'));
$resources = $xml->children()->children();
unset($resources->position_in_category);
unset($resources->manufacturer_name);
$resources->price = '1000';
$resources->active = '1';
$resources->quantity = '50';
$resources->link_rewrite = 'blabla';
$resources->name->language[0][0] = 'blabla';
$resources->description->language[0][0] = '<p>blabla</p>';
$resources->description_short->language[0][0] = 'blabla';
$resources->associations = '';
$opt = array('resource' => 'products');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
回答1:
The resource Product is kind of very important for Prestashop. I have checked quickly the schema 'synopsis' (.../api/products/?schema=synopsis). There are 12 fields marked as required true! In you example, the default parent category is missing for example! That is one of the reason why it didn't work!
回答2:
In PrestaShop 1.5
Open defines.inc.php
from config folder
find
define('_PS_MODE_DEV_', false);
change false -> true it will start showing exact error.
This error is occurring due to
$resources->quantity = '50';
You can not modify quantity from xml. Just comment this line. I hope it will work for you.
回答3:
check the weather you have given the correct PS_SHOP_PATH and PS_WS_AUTH_KEY.
and also check for the permission from your prestashop backend.
回答4:
To see real webservice error message please activate PHP error display in config/config.inc.php
@ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);
来源:https://stackoverflow.com/questions/19929719/add-product-to-prestashop-1-5-via-web-service