You are here:  » Re-order price results

Support Forum



Re-order price results

Submitted by ANDREWCX on Fri, 2007-08-17 13:06 in

Hi David,

I was wondering if it is possible to change the way PT lists 'prices' for a 'product'. What I would like to do is convert a listing like this

http://rewardsdb.com/product/Barnes-and-Noble.html

So that all the merchants with "CASHBACK" in there name appear together as do the "Points" and "Miles" ones - what would be great would be if there was a way to break up the results into several tables that could be listed on the same page with each table having just one of these groups.

Any suggestions?

Thanks,

Andrew

Submitted by support on Fri, 2007-08-17 13:42

Hi Andrew,

It's tricky to test this without having your dataset available, but try the following as a replacement for html/prices.php:

<?php
  $newPrices["POINTS"] = array();
  $newPrices["MILES"] = array();
  $newPrices["CASHBACK"] = array();
  foreach($newPrices as $k => $v)
  {
    foreach($prices["products"] as $l => $product)
    {
      if (strpos($product["merchant"],$k)!==false)
      {
        $newPrices[$k][] = $product;
        unset($prices["products"][$l]);
      }
    }
  }
  if (is_array())
  {
    $prices["products"];
    $newPrices["OTHERS"] = $prices["products"];
  }
  foreach($newPrices as $k => $prices)
  {
?>
<div class='prices'>
  <table width='100%' cellpadding='4'>
    <tr bgcolor='#eeeeee'>
      <th width='200' align='left'><?php print translate("Stockist"); ?></th>
      <th align='left'><?php print translate("Catalogue Product Name"); ?></th>
      <th align='left'><?php print translate("Price"); ?></th>
      <th align='left'>&nbsp;</th>
    </tr>
    <?php foreach($prices as $product): ?>
    <tr bgcolor='#ffffcc'>
      <td><a href='<?php print $product["merchantHREF"]; ?>'><?php print $product["merchant"]; ?></a></td>
      <td><?php print $product["name"]; ?></td>
      <td><strong><?php print $config_currencyHTML.$product["price"]; ?></strong></td>
      <td align='center'><a href='<?php print tapestry_buyURL($product); ?>' <?php print javascript_statusBar("go to ".$product["merchant"]); ?>><?php print translate("Visit Store"); ?></a></td>
    </tr>
    <?php endforeach; ?>
  </table>
</div>
<?php
  }
?>

Hope this helps get you started...!
Cheers,
David.

Submitted by ANDREWCX on Wed, 2007-09-19 00:23

Hi David,

I finally got around to implementing this - works well. 2 follow on questions:

1) How can I hid the table when its empty (eg - the merchant has miles and cashback offers but not points)
2) How can I re-order the tables so that the highest 'price' is at the top - ie 5% cashback shows before 1%? I still want html/product to populate from the lowest 'priced' offer (ie the 0 Support link) but the tables should show high first.

Thanks,

Andrew

Submitted by support on Thu, 2007-09-20 12:14

Hi Andrew,

To reverse the table, where you have the following line (in html/prices.php:

    <?php foreach($prices as $product): ?>

...change this as follows:

    <?php $prices array_reverse($prices);foreach($prices as $product): ?>

In your dataset, how do you identify that the table should be "empty"? Are all price fields 0?

Cheers,
David.

Submitted by ANDREWCX on Thu, 2007-09-20 12:38

See http://rewardsdb.com/product/Amazon.html as an example - basically with the not every merchant has partners in the 3 categories of rewards (points, miles, cashback) - no its not that the price fields are 0 (that's what "Support RewardsDB" shows) but rather that there just aren't any rows.

As a followup question. How can I re-name the header rows of the idividual tables with the filter? (ie "Cashback Reward Programs", "Points Reward Programs", Frequent Flyer Miles Reward Programs").

Thanks,

A

Submitted by support on Thu, 2007-09-20 12:50

Hi Andrew,

That should be straight forward. Basically, this just involves counting the members of the array before creating the table, and if it is zero skip that table. Without seeing your code i'm not sure what variables you have used, but it would be something like:

  <?php if (count($prices)): ?>

...before the block, and ending with:

<?php endif; ?>

If you're not sure where to insert the above, drop me an email with your html/prices.php as an attachment and i'll take a look for you...

Cheers,
David.