Add product to PrestaShop 1.5 via Web Service

2019-04-15 03:53发布

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

4条回答
不美不萌又怎样
2楼-- · 2019-04-15 04:06

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!

查看更多
疯言疯语
3楼-- · 2019-04-15 04:19

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

查看更多
Emotional °昔
4楼-- · 2019-04-15 04:20

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.

查看更多
Juvenile、少年°
5楼-- · 2019-04-15 04:24

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.

查看更多
登录 后发表回答