Como enviar un post con un pedido xml con PrestaShop.
Aquí os dejo un ejemplo que me han dejado en las prácticas, muy útil!
<?php
$service_url = 'http://example.com/api/conversations';
$curl = curl_init($service_url);
$input_xml = ' <Pedido>
<Version> 2.0 </Version>
<Linea>
<Producto>
<Referencia>1245</Referencia>
<Cantidad>2</Cantidad>
</Producto>
<Comentarios>
<Email>email@blogger.es</Email>
</Comentarios>
</Linea>
</Pedido>';
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $input_xml);
$curl_response = curl_exec($curl);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR')
{
die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded->response);
0 comentarios:
Publicar un comentario