You are here:  » Price comparison on search results page.


Price comparison on search results page.

Submitted by allanch on Tue, 2014-12-09 17:46 in

Hi David,

It's been a while since I posted on here, I hope you've been well. Can you tell me if it's possible to have a price comparison table for each product in searchresults.php. By doing this I'm removing the need for a link to product.php for each product. Can you think of any disadvantages to this? I'm using PT for Wrodpress as well. Thanks.

Allan

Submitted by support on Wed, 2014-12-10 10:32

Hello Allan,

No problem!

In pto_search.php, look for the following code at line 557:

  $each = str_replace("%PRODUCT_URL%",pto_common_productHREF($row),$each);

...and REPLACE with:

  $each = str_replace("%PRODUCT_URL%",pto_common_productHREF($row),$each);
  global $pto_config_databaseTablePrefix;
  global $pto_productResults;
  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE name = '".$wpdb->escape($row->name)."' ORDER BY price";
  $wpdb->query($sql)
  $pto_productResults = $wpdb->last_result;
  $each = str_replace("%PRICES%",pto_product_prices(),$each);

And then in your Search Results / Each template, use the place holder %PRICES% at the point at which you wish the price comparison table to be inserted. It will appear exactly as it does on the product pages, using the Prices Before / Each / After templates.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by allanch on Wed, 2014-12-10 13:35

Thanks David,

I'll give it a try this evening. Loving your work as always!

Submitted by allanch on Thu, 2014-12-11 07:56

Morning David,

I gave the code a go and I get this error msg:

Fatal error: Cannot use object of type stdClass as array in /public_html/wp-content/plugins/pto/pto_search.php on line 562

Do you know what could be causing it? Thanks

Submitted by support on Thu, 2014-12-11 09:23

Sorry Allan, all corrected above had used array rather than object style access of the $row variable, but also missed out the call to $wpdb->query()...

Cheers,
David.
--
PriceTapestry.com

Submitted by allanch on Thu, 2014-12-11 18:51

Thanks David, works a treat now!