Jump to content

webservice api adding a product issue


xonath

Recommended Posts

HI,

 

I have wrote a small script to add a product and it works as long as the descriptions dont contain html.

 

However if i want to put html in the description and short description it fails. If i add html such as <b></b> prestashop api gives a 500 error.

 

When debug is on. it shows what is sent is not wrapped in cdata. where is should be. What am i doing wrong? Hes a snippet

 

 

$n_desc = '<b>Some text for description</b>';

 

...

 

$node = dom_import_simplexml($resources -> description -> language[0][0]);
	$no = $node -> ownerDocument;
	$node -> appendChild($no -> createCDATASection($n_desc));
	$resources -> description -> language[0][0] = $n_desc;
	$resources -> description -> language[0][0]['id'] = $n_l_id;
	$resources -> description -> language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;

 

 

 

and debug shows sent in the xml...

<description><language id="1" xlink:href="http://led.smithie-online.co.uk/public/api/languages/1"><b>Some text for description</b></language></description>

as you can see no <!CDATA[ ]]>

 

 

and the error....

 

 

 

[b]	RETURN HTTP BODY[/b]

<?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>
<error>
<message><![CDATA[internal error. To see this error please display the PHP errors.]]></message>
</error>
<error>
<message><![CDATA[internal error. To see this error please display the PHP errors.]]></message>
</error>
<error>
....



Edited by xonath (see edit history)
Link to comment
Share on other sites

  • 6 months later...

I have solved the same issue by adding an encoding right after the class send the xml:

find this line on PSWebServiceLibrary.php : 

 

 

around line 222:

$request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => 'xml='.$xml));

and change like this:

$request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => 'xml='.urlencode($xml)));
after this, I can send descriptions with html inside, but use a CDATA node for it:
 
$node = dom_import_simplexml($resources -> description -> language[0][0]);
$no = $node -> ownerDocument;
$node -> appendChild($no -> createCDATASection($n_desc));
$resources -> description -> language[0][0] = $n_desc;
$resources -> description -> language[0][0]['id'] = $n_l_id;
$resources -> description -> language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;

i've merged various code and solutions founded here and on stackoverflow. it seams working.

  • 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...