You are here:  » Include Reviews in SearchExternal.php

Support Forum



Include Reviews in SearchExternal.php

Submitted by npaitken on Mon, 2009-04-27 13:01 in

Hi David,

Following on from the great scripts you provided in Showing search and price comparison tables on other sites

I was wondering if it would be possible to include Reviews somehow when using these scripts?

So the embedded code displayed something like this:

TITLE
IMAGE
***** 3 Reviews
from PRICE
COMPARE PRICES LINK

Is this possible?

Thanks,
Neil

Submitted by support on Mon, 2009-04-27 13:15

Hi Neil,

As it stands, searchExternal.php just shows the normally formatted search results - however the example you give in your post describes the Featured Products layout... did you want to move to this kind of layout in searchExternal.php?

Cheers,
David.

Submitted by npaitken on Mon, 2009-05-04 11:31

Hi David,

Apologies for the confusion. My site uses a template (from PTT Dave) where the search results are formatted like the default featured products layout!

I think it would be great if reviews (***** Reviews) could be incorporated in this layout.

Are we talking major 'code' surgery?

Submitted by support on Tue, 2009-05-05 08:56

Hi Neil,

It's not too much work - as it stands search.php doesn't create the review link so first of all, look for the following block of code beginning at line 164:

      if ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
      }

...and REPLACE this with:

      if ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];
        $searchresults["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
        if ($rewrite) $searchresults["products"][$k]["reviewHREF"] = "../../".$searchresults["products"][$k]["reviewHREF"];
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
        $searchresults["products"][$k]["reviewHREF"] = "reviewss.php?q=".urlencode($product["name"]);
      }

With that in place, the exact same code as used in the featured products HTML module can be used in html/searchresults.php, as follows:

            <small>
            <?php if ($product["reviews"]): ?>
              <?php print tapestry_stars($product["rating"],"s"); ?>&nbsp;
              <a href='<?php print $product["reviewHREF"]; ?>'><?php print $product["reviews"]." ".translate("Reviews"); ?></a>
            <?php else: ?>
              <a href='<?php print $product["reviewHREF"]; ?>'><?php print translate("Review This Product"); ?></a>
            <?php endif; ?>
            </small>

...so all you'd need to do is insert the above within the main foreach() loop in your searchresults.php at the appropriate position depending on where you want the stars and review link to appear...

Cheers,
David.

Submitted by npaitken on Tue, 2009-05-05 11:34

Excellent,

Works perfectly :-)

Just one small snag. When I use the above code in my searchresults_external.php and use the following code in my Wordpress posts

<?php
  $common_baseHREF = "http://www.mysite.co.uk/shopping/";
  $common_path = "/kunden/homepages/2/~~~~~~~~/htdocs/shopping/";
  $_GET["q"] = "product name goes here";
  require($common_path."searchExternal.php");
?>

it shows the ***** Reviews but unlike with search results in PT, the ***** Reviews link points to the URL of the Wordpress post NOT the actual reviews of the product!

Any idea why? Do I need to modify searchExternal too?

Submitted by support on Tue, 2009-05-05 11:44

Hi Neil,

Yes - a similar mod would be required in searchExternal.php. The equivalent block begins at line 218 as follows:

      if ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode($product["name"]);
      }

...REPLACE this with:

      if ($config_useRewrite)
      {
        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
        $searchresults["products"][$k]["reviewHREF"] = $config_baseHREF."review/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode($product["name"]);
        $searchresults["products"][$k]["reviewHREF"] = $config_baseHREF."reviews.php?q=".urlencode($product["name"]);
      }

Cheers,
David.

Submitted by npaitken on Tue, 2009-05-05 12:06

Hi David,

Perfect. That's exactly what I wanted.

Very happy,
Neil