Prestashop Webservice 添加简单的产品
Prestashop Webservice to add simple product
我正在编写一个脚本,它将通过网络服务添加产品。
我有几个小时的困难,所以我寻求帮助。
这就是我现在拥有的。
require_once("config.php");
require_once("PSWebServiceLibrary.php");
try {
$webService = new PrestaShopWebservice(SITE_URL, WEBSERVICE_AUTH_KEY, DEBUG_MODE);
$xml = $webService->get(array('url' => SITE_URL.'/api/products?schema=synopsis'));
$product = $xml->children()->children();
$product->price = 99;
$product->wholesale_price = 89;
$product->active = '1';
$product->on_sale = 0;
$product->show_price = 1;
$product->available_for_order = 1;
$product->name->language[0][0] = "Produit webservice";
$product->name->language[0][0]['id'] = 1;
$product->name->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->description->language[0][0] = "Description produit webservice";
$product->description->language[0][0]['id'] = 1;
$product->description->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->description_short->language[0][0] = "Descr. courte";
$product->description_short->language[0][0]['id'] = 1;
$product->description_short->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->reference = "ref_product_webservice";
$product->depends_on_stock = 0;
$category_id = 3;
$product->associations->categories->addChild('category')->addChild('id', $category_id);
$product->id_category_default = $category_id;
//
$opt = array('resource' => 'products');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
catch (PrestaShopWebserviceException $ex) {
echo "Error:<br>";
echo $ex->getMessage();
exit(1);
}
我已经设置好我的网络服务,但我一直收到这个错误:
This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error.
请告诉我哪里做错了。
在您的 Prestashop 中启用调试模式。您将准确收到您设置错误的字段以及原因。
祝你好运。
将架构更改为空白,现在可以正常使用了。
最初的错误是:
Attribute "href" bound to namespace
我正在编写一个脚本,它将通过网络服务添加产品。 我有几个小时的困难,所以我寻求帮助。 这就是我现在拥有的。
require_once("config.php");
require_once("PSWebServiceLibrary.php");
try {
$webService = new PrestaShopWebservice(SITE_URL, WEBSERVICE_AUTH_KEY, DEBUG_MODE);
$xml = $webService->get(array('url' => SITE_URL.'/api/products?schema=synopsis'));
$product = $xml->children()->children();
$product->price = 99;
$product->wholesale_price = 89;
$product->active = '1';
$product->on_sale = 0;
$product->show_price = 1;
$product->available_for_order = 1;
$product->name->language[0][0] = "Produit webservice";
$product->name->language[0][0]['id'] = 1;
$product->name->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->description->language[0][0] = "Description produit webservice";
$product->description->language[0][0]['id'] = 1;
$product->description->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->description_short->language[0][0] = "Descr. courte";
$product->description_short->language[0][0]['id'] = 1;
$product->description_short->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->reference = "ref_product_webservice";
$product->depends_on_stock = 0;
$category_id = 3;
$product->associations->categories->addChild('category')->addChild('id', $category_id);
$product->id_category_default = $category_id;
//
$opt = array('resource' => 'products');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
catch (PrestaShopWebserviceException $ex) {
echo "Error:<br>";
echo $ex->getMessage();
exit(1);
}
我已经设置好我的网络服务,但我一直收到这个错误:
This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error.
请告诉我哪里做错了。
在您的 Prestashop 中启用调试模式。您将准确收到您设置错误的字段以及原因。
祝你好运。
将架构更改为空白,现在可以正常使用了。 最初的错误是:
Attribute "href" bound to namespace