You are here:  » New collumn in price comparison table

Support Forum



New collumn in price comparison table

Submitted by steve on Mon, 2008-07-28 23:43 in

Hi David,

It would be great if the following is possible. 100% commission sales generated from my website will be going to charity. To encourage users to use the service and to give users abit of personal feedback I was wondering if I could:

Add a new column to the comparison table entitled `You will donate` and then their will be an £amount next to each product. This amount will be calculated by taking the figure in the price collumn and calculating the amount to be donated. For example if from one merchant I have a 10% commission then (PRICE/100)10 will be calculated and displayed in the `You will donate` collumn.

Is this possible? So I will need to be able to set the percentages (for merchants who give a % commission) or commission fee (for merchants who pay a set referal commission) in the admin section for each merchant.

I guess the work for this mod is mainly in the admin. Having an input field for commission percentage or one off fee next to each merchant feed and then using this data to calculate the amount to be donated in comparison table.

I have a feeling you will say this is beyond what this script is targetted for. Any chance of pointing me in the right direction with this?

Thanks a lot for your help! :-)

Submitted by support on Tue, 2008-07-29 08:10

Hello Steve,

The table part is straight forward as you say. To add the commission info to the database is quite a lot of modification; but you could quite easily do this by maintaining a separate PHP file that contains merchant commission info, either as a percentage (x.x%) or fixed amount (x.xx):

commission.php

<?php
  $commission
["Merchant A"] = "5%";
  
$commission["Merchant B"] = "2.5%";
  
$commission["Merchant C"] = "2.50";
?>

In each case, the merchant name in brackets simply needs to be exactly what the merchant is registered as, including spaces. Create this file in the main Price Tapestry directory.

To use this, data, a bit of modification is required in prices.php; but as it is a small file; here's a fully modified version that should (fingers crossed) in conjunction with commission.php do what you require:

html/prices.php

<?php
  require("commission.php");
?>
<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'><?php print translate("You Will Donate"); ?></th>
      <th align='left'>&nbsp;</th>
    </tr>
    <?php foreach($prices["products"] 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>
<?php
if ($commission[$product["merchant"]])
{
  if (strpos($commission[$product["merchant"]],"%"))
  {
    // percentage
    $percent = str_replace("%","",$commission[$product["merchant"]]);
    $donation = sprintf("%.2f",(($product["price"]/100) * $percent));
  }
  else
  {
    // referral fee
    $donation = sprintf("%.2f",$commission[$product["merchant"]]);
  }
  print "<td>".$config_currencyHTML.$donation."</td>";
}
else
{
  // no commission data
  print "<td>&nbsp;</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>

Hope this helps!

Cheers,
David.

Submitted by steve on Tue, 2008-07-29 11:57

Your a star David, it works a treat! Thank you!

Submitted by steve on Tue, 2008-07-29 12:24

Hi again David.

Submitted by support on Tue, 2008-07-29 18:38

Hi Steven,

You can simply add the amount of "1 school" into commission.php - but don't use quotes so that it is a numeric value, and as it is hardly any more coding; i'll describe a way that will enable you to specify different items and show the user what percentage of each item the donation will contribute to:

<?php
  $contributions
["School"] = 5.00;
  
$contributions["Water Well"] = 1.00;
?>

(just add or delete items as required)

Then to use this as you describe (calculating whole + percentages of "schools"), try changing the following line from the modification to html/prices.php

  print "<td>".$config_currencyHTML.$donation."</td>";

as follows:

  print "<td>"
  foreach($contributions as $item => $cost)
  {
    $percentage = sprintf("%.2f",(($cost / 100) * $donation));
    print $percentage."% of a ".$item."<br />";
  }
  print "</td>";

I'm assuming that the order of magnitude will mean that no single commission will pay for more than 1 of an item, but if this is the case it would be nice to modify this so you don't get, for example; "23.5% of a Pencil"!

Cheers,
David.

Submitted by steve on Wed, 2008-07-30 09:50

Thanks very much for this, I really do appreciate it! It is working great and I can modify the calculations to suit now I know how the codings done.

Cheers for taking the time to do that. Steven

Submitted by steve on Sun, 2008-08-17 23:16

Hi David,

I would like to add this mod above into the browse merchants section.

The difference is that there will be no product to do the calculations, which is fine for when commissions are fixed, but not for percentages as it is trying to calculate from the product price.

So instead of calculating from the price of the product I have just replaced this with 10. So I can now say "you will donate X amount for every £10 spent".

changed

$donation = sprintf("%.2f",(($product["price"]/100) * $percent));

to

$donation = sprintf("%.2f",((10/100) * $percent));

However,nothing appears to the collumn table.

Could you help me out on this?

Cheers.

Steven

Submitted by support on Tue, 2008-08-19 09:04

Hi Steven,

Mathematically it looks fine. Could you post the section of code where you are actually trying to output $donation on the page and I'll take a look at that...

Cheers,
David.

Submitted by steve on Mon, 2008-08-25 13:19

Hi David,

Yep I have tried to place this in the /html/merchantatoz.php. This is the changed atoz.php file so it has a similar layout to search results.

Heres the file:

<?php
  require("commission.php");
?>
<?php $currentLetter ""?>
<div class='searchresults'>
  <table width='900px'>
    <?php foreach($atoz["items"] as $item): ?>
      <?php
        $firstLetter = strtoupper(substr($item["name"],0,1));
        if ($firstLetter <> $currentLetter)
        {
          print "<tr>";
          print "<td colspan='4'>";
          print "<h4>".$firstLetter."</h4>";
          print "</td>";
          print "</tr>";
          $currentLetter = $firstLetter;
        }
      ?>
      <tr>
        <td>
        <?php
        if (file_exists("logos/".$item["name"]))
        {
          print "<p><a href='".$item["href"]."'><img border='0' src='".$config_baseHREF."logos/".$item["name"]."' /></a></p>";
        }
        ?>
        </td>
        <td valign='middle'>
        <?php
        print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";
        if (file_exists("descriptions/".$item["name"]))
        {
          print "<p>";
          require("descriptions/".$item["name"]);
          print "</p>";
        }
        ?>
        </td>
<?php
if ($commission[$product["merchant"]])
{
  if (strpos($commission[$product["merchant"]],"%"))
  {
    // percentage
    $percent = str_replace("%","",$commission[$product["merchant"]]);
    $donation = sprintf("%.2f",(($product["price"]/100) * $percent));
  }
  else
  {
    // referral fee
    $donation = sprintf("%.2f",$commission[$product["merchant"]]);
  }
  print "<td>";
  foreach($contributions as $item => $cost)
  {
    $percentage = sprintf("%.2f",(($donation / $cost) ));
    print "<strong>" .$percentage." ".$item."</strong> to charity<br />";
  }
  print "</td>";
  }
else
{
  // no commission data
  print "<td>&nbsp;</td>";
}
?>
        <td valign='middle' align='center'>
        <?php
          print "<a href='".$item["href"]."'>Browse Products</a>";
        ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </table>
</div>

The column where I am trying to add the amount to be donate, which is calcuates from the commission.php doesn't show.

</td>
<?php
if ($commission[$product["merchant"]])
{
  if (strpos($commission[$product["merchant"]],"%"))
  {
    // percentage
    $percent = str_replace("%","",$commission[$product["merchant"]]);
    $donation = sprintf("%.2f",(($product["price"]/100) * $percent));
  }
  else
  {
    // referral fee
    $donation = sprintf("%.2f",$commission[$product["merchant"]]);
  }
  print "<td>";
  foreach($contributions as $item => $cost)
  {
    $percentage = sprintf("%.2f",(($donation / $cost) ));
    print "<strong>" .$percentage." ".$item."</strong> to charity<br />";
  }

Where have I gone wrong? Cheers David.

Submitted by steve on Mon, 2008-08-25 15:55

Just been playing about with this for a while and I changed:

$product["merchant"]

to

$feed["merchant"]

and it seem to be working! Which is excellent. But just thought I would check with you to see if this would cause problems elswhere?

Thanks

The whole merchantatoz.php file now looks like this:

<?php
  require("commission.php");
?>
<?php $currentLetter ""?>
<div class='searchresults'>
  <table width='900px'>
    <?php foreach($atoz["items"] as $item): ?>
      <?php
        $firstLetter = strtoupper(substr($item["name"],0,1));
        if ($firstLetter <> $currentLetter)
        {
          print "<tr>";
          print "<td colspan='4'>";
          print "<h4>".$firstLetter."</h4>";
          print "</td>";
          print "</tr>";
          $currentLetter = $firstLetter;
        }
      ?>
      <tr>
        <td>
        <?php
        if (file_exists("logos/".$item["name"]))
        {
          print "<p><a href='".$item["href"]."'><img border='0' src='".$config_baseHREF."logos/".$item["name"]."' /></a></p>";
        }
        ?>
        </td>
        <td valign='middle'>
        <?php
        print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";
        if (file_exists("descriptions/".$item["name"]))
        {
          print "<p>";
          require("descriptions/".$item["name"]);
          print "</p>";
        }
        ?>
        </td>
<?php
if ($commission[$feed["merchant"]])
{
  if (strpos($commission[$feed["merchant"]],"%"))
  {
    // percentage
    $percent = str_replace("%","",$commission[$feed["merchant"]]);
    $donation = sprintf("%.2f",((10/100) * $percent));
  }
  else
  {
    // referral fee
    $donation = sprintf("%.2f",$commission[$feed["merchant"]]);
  }
  print " <td valign='middle' align='center'>";
  foreach($contributions as $item => $cost)
  {
    $percentage = sprintf("%.2f",(($donation / $cost) ));
    print "<strong>" .$percentage." ".$item."</strong> to charity<br />";
  }
  print "</td>";
  }
else
{
  // no commission data
  print " <td valign='middle' align='center'>maybe</td>";
}
?>
        <td valign='middle' align='center'>
        <?php
          print "<a href='".$item["href"]."'>Browse Products</a>";
        ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </table>
</div>

Submitted by steve on Mon, 2008-08-25 16:07

Just noticed that since I made that change above,

this code

          print "<a href='".$item["href"]."'>Browse Products</a>";

take me to the url:

http://www.compare2offset.com/merchant/T

instead of:

http://www.compare2offset.com/merchant/Jessops/

Funny thing is as you can see from my new merchantatoz.php file in the previous post, the code <a href='".$item["href"]."'> is used a number of times. But these links work fine.

Any idea what the problem is?

Cheers,

Steven.

Submitted by support on Tue, 2008-08-26 07:32

Hi Steve,

What's happened is that the $item variable has been overwritten by this code slightly higher up:

  foreach($contributions as $item => $cost)
  {
    $percentage = sprintf("%.2f",(($donation / $cost) ));
    print "<strong>" .$percentage." ".$item."</strong> to charity<br />";
  }

All you need to do is use an alternative to $item; for example:

  foreach($contributions as $project => $cost)
  {
    $percentage = sprintf("%.2f",(($donation / $cost) ));
    print "<strong>" .$percentage." ".$project."</strong> to charity<br />";
  }

That should be all it is!

Cheers,
David.

Submitted by steve on Wed, 2008-08-27 10:34

Working great now, cheers David.