lundi 3 mars 2014

Catalogues

Les produits fournis par le flux xml généré par l'API Kelkoo sont soit proposés par un seul marchand, soit par plusieurs marchands, dans ce dernier cas un "Catalogue" est attribué à chaque produit. Un "Catalogue" désigne un flux spécifique à un produit dont un comparatif existe dans la base de données Kelkoo. Si ce catalogue existe pour un produit ceci implique l’existence de la balise "<CatalogId>" dans le résultat utilisant le template "Product Search V3".

Pour récupérer un flux d'un catalogue, il faut utiliser le template "Catalog Listing V3". Dans l'exemple suivant, on réutilisera l'exemple vue dans le chapitre précédent, mais cette fois-ci en testant l'existence de catalogue pour chaque produit. Dans un deuxième temps on va récupérer ce catalogue.

<?php
include('UrlSigner.php');
$url = UrlSigner('http://fr.shoppingapis.kelkoo.com', '/V3/productSearch?query=iphone+5&sort=default_ranking&start=1&results=4&show_products=1&show_subcategories=1&show_refinements=1','Tracking_Id', 'Affiliate_Key');
$xml = simplexml_load_file($url);
echo $xml->Products['totalResultsAvailable'].' r&eacute;sultats chez '.$xml->Products['totalMerchantsAvailable'].' marchands';
echo '<table width="600" border="1">
  <tr>
    <td></td>
    <td>Produit</td>
    <td>Marchand</td>
    <td>Prix(&euro;)</td>
    <td>Lien</td>
  </tr>';
foreach($xml->Products->Product as $product){
 echo '<tr>
    <td><img src="'.$product->Offer->Images->Image->Url.'" /></td>
    <td>'.$product->Offer->Title.'</td>
    <td>'.$product->Offer->Merchant->Name.'</td>
 <td>'.$product->Offer->Price->Price.'</td>';
 if($product->Offer->CatalogId = ""){
     echo '<td><a href="http://clk.tradedoubler.com/click?p=XXXXX&a=XXXXXXX&g=XXXXXXXX&url='.$product->Offer->Url.'" target="_blank">Voir l\'offre</a></td>';
 }
 else {
  echo '<td><a href="catalogue.php?catalog_Id='.$product->Offer->CatalogID.'" target="_parent">Voir les offres</a></td>';
 }
  echo '</tr>';
}
echo '</table>';
?>
Catalogue.php
<?php
include('UrlSigner.php');
$catalog_Id = $_GET['catalog_Id'];
$url = UrlSigner('http://fr.shoppingapis.kelkoo.com', '/V3/catalogListings?catalogId='.$catalog_Id.'','Tracking_Id', 'Affiliate_Key');
$xml = simplexml_load_file($url); echo $xml->Products['totalResultsAvailable'].' r&eacute;sultats chez '.$xml->Products['totalMerchantsAvailable'].' marchands'; echo '<table width="700" border="1"> <tr> <td></td> <td>Produit</td> <td>Marchand</td> <td>Prix(&euro;)</td> <td>Lien</td> </tr>'; foreach($xml->Offer as $product){ echo '<tr> <td><img src="'.$product->Images->Image->Url.'" /></td> <td>'.$product->Title.'</td> <td>'.$product->Merchant->Name.'</td> <td>'.$product->Price->Price.'</td> <td><a href=http://clk.tradedoubler.com/click?p=XXXXX&a=XXXXXXX&g=XXXXXXXX&url='.$product->Offer->Url.'" target="_blank">Voir l\'offre</a></td> </tr>'; } echo '</table>'; ?>