You are here:  » Product mapping and image/description

Support Forum



Product mapping and image/description

Submitted by hockey on Mon, 2008-08-11 08:21 in

So, when products are mapped, it appears the feed with the lowest price is the feed used to pull the image and description.

Where is the code that designates this?

I have one merchant that has better product images and descriptions than any other and I would like all mapped products that include this one merchant to use its images and descriptions.

Is there way to basically tweak this code so if "Favorite Merchant" is included in a product's page, use its image and description... Then if not, go ahead as normal and use the cheapest price merchant?

Thanks in advance!
Jason

Submitted by support on Mon, 2008-08-11 09:36

Hi Jason,

The merchant from which the image and description is taken is not actually prescribed as such, it's just a side-effect of the way MySQL selects the non-summary fields in an otherwise summary query. Whilst in most cases they are selected from the cheapest merchant, it may not be under certain circumstances.

The only way to do this would be to use an additional query per search result to select the image and description from the preferred merchant. It's easy to do, but may have performance implications. If you could email me your existing search.php and products.php i'll add this mod for you and you can give it a go...

Cheers,
David.

Submitted by hockey on Tue, 2008-08-12 04:27

Thanks a lot. I just e-mailed you.

Submitted by Matt Allan on Tue, 2008-09-02 21:03

David,

Is there any chance you could put this modification on the forum, I would like to do the same with my site.

Submitted by support on Wed, 2008-09-03 08:06

Hi Matt,

Sure - for the product page, look for the following code in products.php (line 18):

    if ($numRows)
    {

...and replace this with:

    if ($numRows)
    {
      $imageMerchant = "Merchant Name";
      if ($rows[0]["merchant"] <> $imageMerchant)
      {
        $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' AND merchant='".database_safe($imageMerchant)."' LIMIT 1";
        if (database_querySelect($sql,$result))
        {
          $rows[0]["image_url"] = $result[0]["image_url"];
          $rows[0]["description"] = $result[0]["description"];
        }
      }

...changing "Merchant Name" to the name of the merchant that has the best images and description.

To do a similar thing in search.php, although performance may be more of an issue here, search fro the following code on line 164:

    foreach($searchresults["products"] as $k => $product)
    {

...and replace this with:

    foreach($searchresults["products"] as $k => $product)
    {
      $imageMerchant = "Merchant Name";
      if ($product["merchant"] <> $imageMerchant)
      {
        $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($product["name"])."' AND merchant='".database_safe($imageMerchant)."' LIMIT 1";
        if (database_querySelect($sql,$result))
        {
          $searchresults["products"][$k]["image_url"] = $result[0]["image_url"];
          $searchresults["products"][$k]["description"] = $result[0]["description"];
        }
      }

Cheers,
David.

Submitted by Matt Allan on Wed, 2008-09-03 17:43

Thats great, thank you.

Submitted by steveb on Wed, 2009-04-01 15:28

This is very interesting

I assume it would be possible to use this method to insert your own set of images and descriptions for products.php?

If I created my own feed file with product name, description, image URL etc. how do I get the system to ignore the price field and merchant link for my own feed?

Thanks

Steve

Submitted by support on Wed, 2009-04-01 16:55

Hi Steve,

You are correct, a similar method can be used but I would recommend an alternative approach to creating your own feed. Instead, as several users have done, they use directories containing images or description text to override the one selected from the database on the products page.

To do this, I would recommend setting up the following folders (taking into account that Price Tapestry already has a folder called "images"):

or_image
or_description

("or" standing for "override")

For simplicity, it's best to pick a standard format for your override images, for example .jpg, so in the or_images folder, create your image files as:

Product Name.jpg

(where Product Name is the exact product name that you want the image to be used for)

Similarly, within the or_description folder, create files called:

Product Name.txt

(the .txt extension will make it easier to edit your files in your usual text editor)

Then, within products.php, you will find the following code beginning at line 18:

    if ($numRows)
    {

REPLACE this with:

    if ($numRows)
    {
      $or_image_filename = "or_image/".$rows[0]["name"].".jpg";
      $or_description_filename = "or_description/".$rows[0]["name"].".txt";
      if (file_exists($or_image_filename))
      {
        $rows[0]["image_url"] = $config_baseHREF.$or_image_filename;
      }
      if (file_exists($or_description_filename))
      {
        $rows[0]["description"] = file_get_contents($or_description_filename);
      }

Hope this helps!

Cheers,
David.