You are here:  » Price range + num merchants on searchresults.php


Price range + num merchants on searchresults.php

Submitted by Vince on Sat, 2011-01-08 15:14 in

Hi David,

I'm trying to add something to my script, but not succesfully yet.

I want show the price range and price difference (highest - lowest). I know it is possible by using numMerchants, minPrice, maxPrice. But this only matches with the normalised_name, not with EAN code system i'm using.

Its like the same question as asked here: http://www.pricetapestry.com/node/2738

I already have this in my script, but made it in a dumb way. I put this between the

<?php
 
foreach($searchresults["products"] as $product): 
?>
tag on searchresults.php
$result = mysql_query("SELECT * , MIN( price ) AS min, MAX( price ) AS max, COUNT( id ) AS numMerchants FROM `pt_products` WHERE ean = '".$ean."' OR normalised_name = '".$product['normalised_name']."'");

15 results -> 15 query's for just selecting the price and difference.

Can you help me with a modification for search.php just like you did in the topic above. By combining this with the current query's, for taking less load.

Thanks alot,

Cheers,
Vince.

Submitted by support on Mon, 2011-01-10 09:36

Hi Vince,

As minPrice and maxPrice are already fields in each $product within the loop in html/searchresults.php it can be done using the existing variables - and it's nice to include a check to make sure that they are different before displaying the range. In html/searchresults.php, look for the following code at line 25:

          <?php if ($product["numMerchants"] > 1): ?>
            <em><?php print translate("from"); ?></em>&nbsp;<strong><?php print $config_currencyHTML.$product["minPrice"]; ?></strong><br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("Compare Prices"); ?></a></span>
          <?php else: ?>

...and REPLACE with:

          <?php if ($product["minPrice"] < $product["maxPrice"]): ?>
            <strong>
            <?php print $config_currencyHTML.$product["minPrice"];?>
            -
            <?php print $config_currencyHTML.$product["maxPrice"]; ?>
            </strong>
            <br />
            <span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("Compare Prices"); ?></a></span>
          <?php else: ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by Vince on Mon, 2011-01-10 15:38

Hi David,

I don't think this will do.

This loop is only checking for same normalised_name's when selecting the prices and counting merchants. Not by EAN code too.

Cheers,
Vince.

Submitted by support on Mon, 2011-01-10 16:15

Hello Vince,

Ah - I understand. Whilst a re-query per result will give you an expanded minPrice / maxPrice per product name, it may not be all-inclusive. This is because the search results are generated using a "summary" query; which means that the product table row from which most of the fields are returned (specifically EAN in this instance) is undefined; so it would be possible that a search result row does not contain an EAN value, even though another product row for the same name does have one.

The ultimate solution that I have helped other users with in this situation is to run a process after each import to globally populate EAN across all product records. This can be done by querying distinct EANs, then distinct product names for each EAN, and then updating all products with those names with a single common name and EAN...

If that sounds feasible drop me an email with your config.advanced.php attached and I'll work out the required post-import script for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by dth133 on Fri, 2011-11-11 10:59

Hi ,
I am having the same problem with my site . $nummerchants is not correct because I group by keyword and search match by (name,keyword) . my keyword is UPC . empty upc is md5($importRecord["name"]);

when I search by keyword the $nummerchants under search result is correct.
when I search by name the $nummerchants under search result is incorrect.

please let me know how I can fix this thank.

Submitted by support on Fri, 2011-11-11 11:36

Hi dth133.

If you'd like to try the ultimate solution which is to match up upc's throughout the database could you drop me an email with your includes/admin.php and I'll forward the script for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by smartprice24 on Wed, 2017-11-08 17:17

Hi David.

For PT last version how to insert min price and max price for each products in searchresults.php?

Is possible?

<?php if (tapestry_price($product["minPrice"]) < tapestry_price($product["maxPrice"])): ?>
<?php print tapestry_price($product["minPrice"]); ?>
<?php print tapestry_price($product["maxPrice"]); ?>
<?php else: ?>
<div><?php print ""?></div>
<?php endif; ?>

This code not work.

Thanks for support.

Giuseppe

Submitted by support on Thu, 2017-11-09 09:26

Hello Giuseppe,

Use your text editor's Search and Replace function to search:

MIN(price) as minPrice

...and REPLACE:

MIN(price) as minPrice,MAX(price) as maxPrice

In;

search.php (7 instances)
products.php (1 instance)

(changes to products.php required if using Related Products as they are displayed by the same html file as search results...)

Cheers,
David.
--
PriceTapestry.com

Submitted by smartprice24 on Fri, 2017-11-10 09:27

Hi David.

Good!

Many Thanks!
Giuseppe