Jump to content

[RESOLU] Ajouter d'un magasin par webService


Recommended Posts

Bonjour,
 
Je rencontre un problème pour ajouter un magasin par webservice.
 
Je récupère bien un objet store que je remplis avec mes informations mais au moment de l'ajouter je rencontre une erreur 400

This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request.

Voici le code que j'utilise

// Ajout de la boutique dans PrestaShop
try {
	$webService = new PrestaShopWebservice($urlPrestashop, $apiKey, $debugMode);

	$opt['resource'] = 'countries';
	$opt['filter']['iso_code'] = $countryDO->getAlpha2();
	$xml = $webService->get($opt);
	$pays = $xml->children()->children()->attributes();
	$paysId = $pays['id'];

	$opt['url'] = $urlPrestashop.'api/stores?schema=synopsis';
	$xml = $webService->get($opt);
	$resources = $xml->children()->children();
	unset($xml->store->id);
	$resources->id_country = $paysId;
	unset($xml->store->id_state);
	unset($xml->store->hours);
	$resources->name = util::lang($do->getName());
	$resources->address1 = $do->getAddress1();
	$resources->address2 = $do->getAddress2();
	$resources->postcode = $do->getCp();
	$resources->city = $do->getCity();
	$resources->latitude = $do->getLat();
	$resources->longitude = $do->getLng();
	$resources->phone = $do->getTel();
	$resources->fax = $do->getFax();
	$resources->note = util::lang($do->getDescription());
	$resources->email = $do->getEmail();
	$resources->active = $do->getVisible();
	unset($xml->store->date_add);
	unset($xml->store->date_upd);

	$opt = array('resource' => 'stores');
	$opt['postXml'] = $xml->asXML();
	echo "<pre>";var_dump($opt);echo "</pre>";
	$xml = $webService->add($opt);

} catch (PrestaShopWebserviceException $e) {
	echo 'Erreur: <br />'.$e->getMessage();
}

Et voici le résultat de mon dump


<pre>array(2) {
  ["resource"]=>
  string(6) "stores"
  ["postXml"]=>
  string(943) "<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<store>
	<id_country required="true" format="isUnsignedId">8</id_country>
	
	
	<name required="true" maxSize="128" format="isGenericName">Test</name>
	<address1 required="true" maxSize="128" format="isAddress"></address1>
	<address2 maxSize="128" format="isAddress"></address2>
	<postcode maxSize="12">56000</postcode>
	<city required="true" maxSize="64" format="isCityName">Vannes</city>
	<latitude maxSize="13" format="isCoordinate">47.658236</latitude>
	<longitude maxSize="13" format="isCoordinate">-2.7608470000000125</longitude>
	<phone maxSize="16" format="isPhoneNumber">0123456789</phone>
	<fax maxSize="16" format="isPhoneNumber">0123456789</fax>
	<note maxSize="65000" format="isCleanHtml"></note>
	<email maxSize="128" format="isEmail">[email protected]</email>
	<active required="true" format="isBool">1</active>
	
	
</store>
</prestashop>
"
}
</pre>

Auriez-vous une idée pour résoudre mon problème ?

 

Merci

Thomas

Edited by tom56 (see edit history)
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...