Jump to content

Web Service weird error while setting product features.


Recommended Posts



I'm having a hard time trying to figure out what is happening with this web service.


I'm trying to create a product and afterwards updating its features.


The thing is, when I run the script, the product gets created but fails to update the features. But if I run this 4 times.. Yes exactly 4 times it succeeds.


The error is: This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error.


My code for the update features part is this:

function setProductFeatures ($product_id, $attributes) {
	try {

		$webService = new PrestaShopWebservice(PS_URL, PS_KEY, true);
		$options = [
			'resource' => 'products',
			'id' => $product_id

		$xml = $webService->get($options);
		$res = $xml->children()->children();

		// Remove forbiden properties...

		foreach ($attributes as $key => $value ) {
			$res->associations->product_features->product_feature[$key]->id = $value['id'];
			$res->associations->product_features->product_feature[$key]->id_feature_value = $value['value_id'];

		$save = [
			'resource' => 'products',
			'id' => $product_id
		$save['putXml'] = $xml->asXML();
		$xml = $webService->edit($save);

	} catch (PrestaShopWebserviceException $e) {
		echo 'Error setting product features: ' . $e->getMessage() . '<br>';

If I run this 4 times it works.. but the first 3 times it fails..


Does anyone have a clue why this should be happening?


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...