You are here:  » Riche snippet : lowPrice >0 highPrice offerCount $variable


Riche snippet : lowPrice >0 highPrice offerCount $variable

Submitted by Greg on Fri, 2012-12-28 21:22 in

Hello David ,

could you help me with the riche snippet i want use ?

I'm writting the info in html/product.php

div itemscope itemtype="http://schema.org/Product">
<img itemprop="image" src="<?php print $mainProduct["image_url"]; ?>" />
<span itemprop="name"><?php print $mainProduct["search_name"]; ?></span>
<div itemprop="offers" itemscope itemtype="http://schema.org/AggregateOffer">
<span itemprop="lowPrice"><?php print $config_currencyHTML.$mainProduct["price"]; ?></span>
to <span itemprop="highPrice">???????????????????????</span>
from <span itemprop="offerCount">?????????????????????</span> sellers

1) <?php print $config_currencyHTML.$mainProduct["price"]; ?> I Would like show first lowPrice > 0 and not = 0

2) I would like know what variable use for <span itemprop="highPrice">$.....</span>

3) I would like know what variable use for <span itemprop="offerCount">$.....</span>

Thx a lot.

Submitted by support on Sat, 2012-12-29 11:01

Hi Greg,

Re: 1/
For for lowest non-zero price, in place of:

<?php print $config_currencyHTML.$mainProduct["price"]; ?>

Use:

<?php
$lowest = 0.00;
foreach($product["products"] as $p)
{
  if ($p["price"] > $lowest)
  {
    $lowest = $p["price"];
    break;
  }
}
<?php print $config_currencyHTML.$lowest?>

And for 2/ and 3/, have a go with:

<?php $count = count($product["products"]);
<span itemprop="highPrice"><?php print $config_currencyHTML.$product["products"][($count-1)]["price"]; ?></span>
<span itemprop="offerCount"><?php print $count?></span>

Cheers,
David.
--
PriceTapestry.com

Submitted by Greg on Sat, 2012-12-29 22:00

Thx David it work fine ! :)

Last question

<?php
 
print $count
?>
count all the prices, how could i exclude prices = 0 in that total.

Sorry for my newbie questions :X Hope it help some other newbies.

Cheers,
Greg.

Submitted by support on Sun, 2012-12-30 09:46

Hi Greg,

You'd need to loop through the $product["products"] array - have a go with:

<?php
  $count 
0;
  foreach(
$product["products"] as $p)
  {
    if (
$p["price"]>0.00$count++;
  }
  print 
$count;
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Mon, 2014-10-20 22:29

Hello David

how i can display lowest and highest price for search results, and cateogies ?

Submitted by support on Tue, 2014-10-21 07:43

Hi George,

If you first add the following code at the very top of your html/searchresults.php file:

<?php
  $sql 
"SELECT MIN(price) AS searchMinPrice,MAX(price) AS searchMaxPrice FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere;
  
database_querySelect($sql,$rows);
  
$searchMinPrice $rows[0]["searchMinPrice"];
  
$searchMaxPrice $rows[0]["searchMaxPrice"];
?>

You'll then have the $searchMinPrice and $searchMaxPrice variables to use to display as required, for example, anywhere after that point:

<?php
  
print "<p>We have found prices from ".$config_currencyHTML.$searchMinPrice." to ".$config_currencyHTML.$searchMaxPrice."</p>";
?>

This will apply to all search results pages (category results are generated by search.php in the same way as brand / merchant results) but if you need to limit to only certain queries that would be no problem - just let me know...

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-21 10:21

nice!

and also how i can use this for pricetapestry with worpdress?

thanks again

Submitted by support on Tue, 2014-10-21 11:28

Hi George,

To add the Search Results / Banner section, edit the plugin file pto_search.php and look for the following code at line 483:

  return $html;

(this is where the HTML generated from the Search Results / Banner template is returned) and REPLACE with:

  global $wpdb;
  global $pto_searchWhere;
  global $pto_config_databaseTablePrefix;
  $sql = "SELECT MIN(price) AS searchMinPrice,MAX(price) AS searchMaxPrice FROM `".$pto_config_databaseTablePrefix."products` WHERE ".$pto_searchWhere;
  $wpdb->query($sql);
  $html = str_replace("%SEARCHMINPRICE%",$wpdb->last_result[0]->searchMinPrice,$html);
  $html = str_replace("%SEARCHMAXPRICE%",$wpdb->last_result[0]->searchMaxPrice,$html);
  return $html;

With that in place, you'll then be able to use placeholders %SEARCHMINPRICE% and %SEARCHMAXPRICE% as required within your Search Results / Banner template (wp-admin > Settings > PriceTapestry.org)

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-21 14:46

i try the code but doesn't work

Submitted by support on Tue, 2014-10-21 15:36

Hello George,

My apologies - the call to $wpdb->query was missing in the copy; corrected above.

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Tue, 2014-10-21 15:37

works great!

thanks!!!