API Lomadee, Buscape

0

I'm having trouble integrating with the Lomadee platform API.

When I get Json containing the partner products I want to display, many images are not available!

Here is the page I'm developing: Lomadee

Unfortunately, I can not remove the images that do not appear via code because the API provides a link that does not have an image. Does anyone know how to solve this?

Follow the code:

                $requestURL = 'http://sandbox-api.lomadee.com/v2/{API-KEY}/product/_search?sourceId={SOURCE-ID}&size=9'.$q .'&page=' . $page;                  
                $json = file_get_contents( $requestURL ); 
                $product = json_decode( $json, true );
                $paginas = $product['pagination']['totalPage'];            
                foreach ($product['products'] as $productItem)
                { echo $productItem['thumbnail']['url'] ;   }
    
asked by anonymous 08.11.2017 / 12:06

1 answer

0

I do not know if you have already solved the code for the image. But you can use this:

//função de verificação
function url_exists($url) {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_exec($ch);
  $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  return ($code == 200); // verifica se recebe "status OK"
}

//Verifica se a imagem está quebrada
$url = $productItem['thumbnail']['url'];
if (url_exists($url)){
    echo " encontrei :)";
}
else{
    echo " não encontrei :(";
}

So you can easily treat it, if it does not find the product image you can put a default image of your site.

    
16.01.2018 / 03:05