You are here:  » Images in feeds


Images in feeds

Submitted by JasonG on Wed, 2013-05-08 08:19 in

Hi David

Can you think of any reason why some images do not display even though they are in the feed and are visible on the merchant website?

The images are also visible on my product pages, but some don't show on category pages, more broken then not displaying, see product Arden Grange Adult Light 7.5Kg

(Broken image) {link saved}

Image is here {link saved}

The ones saying image comoing soon was added by code provided by you but again would love to stop taht as the image is available and shows on the product page

example: Burns Chicken & Brown Rice Adult 15KG no image on category page but does show on
{link saved}

Thanks
Stuart

Submitted by support on Wed, 2013-05-08 08:54

Hi Stuart,

It looks like the image selected as part of the product page is from a different merchant (Pet Supermarket), whereas the one selected by the search results is from a merchant (Millbury Hill) who's image URLs appear to be broken i'm afraid - they just echo the requested URL as text.

I checked the last html/searchresults.php that I have a copy of and both this and the second part of your question can be fixed by changing the logic to requery for a populated image_url where the image_url field of the result is empty. /images/comingsoon.gif can then be used as a final fallback if there happens to be no image available at all. Before making this change, re-register any feed for which image URLs do not work reliably and don't register the image_url field so that they are all blank for that merchant.

To make the change, in your modified html/searchresults.php, look for the following code beginning at line 4:

  foreach($searchresults["products"] as $k => $product)
  {
    if (!$product["image_url"])
    {
      $searchresults["products"][$k]["image_url"] = "/images/comingsoon.gif";
    }
  }

...and REPLACE with:

  foreach($searchresults["products"] as $k => $product)
  {
    if (!$product["image_url"] && ($product["numMerchants"] > 1))
    {
      $sql = "SELECT image_url FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."' AND image_url <> ''";
      if (database_querySelect($sql,rows))
      {
        $searchresults["products"][$k]["image_url"] = $rows[0]["image_url"];
      }
    }
    if (!$searchresults["products"][$k]["image_url"])
    {
      $searchresults["products"][$k]["image_url"] = "/images/comingsoon.gif";
    }
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Wed, 2013-05-08 09:10

Thanks David

OK question before I do this.

If I register feeds and don't register the image_url field so that they are all blank for that merchant surely all images will be missing, unless PT picks up an image form another feed?

What happens then for products that are not "price compared" and no image has been selected when importing the feed, therefore no other image would be used, or have I misunderstood how PT selects images?

Thanks
Stuart

Submitted by support on Wed, 2013-05-08 09:34

Hello Stuart,

Yes that would be the case for product pages for which there is only one merchant and that merchant's feed does not have an image_url field registered; however a very similar change can be made to your html/product.php so that if an empty image happens to have been selected as the main product image then a similar re-query can be made; and again falling back to your /images/comingsoon.gif image as a last resort. To do this, edit that file and look for the following code at line 2:

  <?php $mainProduct $product["products"][0]; ?>

...and REPLACE with:

  <?php
    $mainProduct = $product["products"][0];
    if (!$mainProduct["image_url"] && (count($product["products"])>1))
    {
      foreach($product["products"] as $p)
      {
        if ($p["image_url"])
        {
          $mainProduct["image_url"] = $p["image_url"];
          break;
        }
      }
    }
    if (!$mainProduct["image_url"])
    {
      $mainProduct["image_url"] = "/images/comingsoon.gif";
    }
  ?>

Unfortunately there is no practical way to identify on the client whether or not a particular image loaded correctly (for example where only some of a merchant's images are bad). There are JavaScript tricks using onerror but I've never really found that to be ideal, so it's really best not to use images at all from feeds where they are not reliable.

All the best,

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Wed, 2013-05-08 09:56

Thanks again, so I guess a better way is upload a many of our own images as posible for every product?

Can images be uploaded for Non Mapped products?

Cheers
Stuart

Submitted by support on Wed, 2013-05-08 10:53

Hi Stuart,

If you upload images as

/images/Product Name.jpg

(where "Product Name" must match exactly the product name as displayed on your site, including spaces), then you can check for these before resorting to comingsoon.gif.

To do this for search results, in place of the following code as described above;

  $searchresults["products"][$k]["image_url"] = "/images/comingsoon.gif";

...use:

  $imageFilename = "images/".$searchresults["products"][$k]["name"].".jpg";
  if (file_exists($imageFilename))
  {
    $searchresults["products"][$k]["image_url"] = "/".$imageFilename;
  }
  else
  {
    $searchresults["products"][$k]["image_url"] = "/images/comingsoon.gif";
  }

And for the product page mod, in place of:

  $mainProduct["image_url"] = "/images/comingsoon.gif";

...use:

  $imageFilename = "images/".$mainProduct["name"].".jpg";
  if (file_exists($imageFilename))
  {
    $mainProduct["image_url"] = "/".$imageFilename;
  }
  else
  {
    $mainProduct["image_url"] = "/images/comingsoon.gif";
  }

Cheers,
David.
--
PriceTapestry.com