You are here:  » If price field = various

Support Forum



If price field = various

Submitted by steve on Fri, 2008-08-29 18:52 in

Hi David,

Im using some single product feeds to display merchants who don't have product feeds but I still want them to appear on the website. Because these merchants will have many products of different prices I would like to display "various" or "from £10" in the price field.

Could we use an IF statement, so if the word "none" is put in the price field in the product feed then "various" will be displayed on the product page?

Thanks

Steven

Submitted by support on Sat, 2008-08-30 10:12

Hi Steven,

As the price field is of type DECIMAL, without lots of modification the price would have to be imported as a number; so would it be an option if for your manual feeds you were to use 0 (zero) as the price?

Firstly, to make this work a check needs to be removed from the import record handler. In includes/admin.php you will find the following code on line 156:

if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]]) return;

...replace this with:

if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]]) return;

This will allow products with a zero price into the database. Next, an IF statement can be used wherever the price is displayed in order to display your alternative text if the price is zero. There are 2 files in which the price is displayed on the product page. Firstly, in html/product.php by this code on (part of) line 23:

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

Replace this with:

<?php print $config_currencyHTML.($mainProduct["price"]>0?$mainProduct["price"]:"Various"); ?>

...and in html/prices.php, line 13 contains:

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

Replace this with:

<?php print $config_currencyHTML.($product["price"]>0?$product["price"]:"Various"); ?>

Hope this helps!

Cheers,
David.

Submitted by steve on Sat, 2008-08-30 19:07

Brilliant thanks very much :-)

Submitted by steve on Sun, 2008-08-31 20:39

Hey, just wondering if you could help me out as this mod above conflicts with another mod.

My price table has an extra collumn in it labelled "you willd onate".

The about that willb e donated to charity is displayed in this collumn and the commission fee or percentage to calculate this is held in the commission.php file.

The code for the collumn is:


<?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 valign='middle' align='center'>";
foreach(
$contributions as $project => $cost)
{
$percentage sprintf("%.2f",(($donation $cost) ));
if (
strpos($commission[$product["merchant"]],"%"))
print 
"<strong>" .$percentage." ".$project."</strong> items to charity for every &pound;10 spent.";
else
print 
"<strong>" .$percentage." ".$project."</strong> items to charity on any purchase.<br />";
}
print 
"</td>";
}
else
{
// no commission data
print " <td valign='middle' align='center'>We were unable to calculate how many items will be donate to charity.</td>";
}
?>

So if the commission is a percentage this is displayed:
"" .$percentage." ".$project." items to charity forevery £10 spent.";

and if the commission is a fixed fee this is displayed:
"" .$percentage." ".$project." items to charity on any purchase.";

As I am now using single product feeds with 0 as the price field this causes a problem with percentage commissions.

So if the price is 0 I need the same code as above but instead of:

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

I need:

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

So when prices are 0 and commission is a percentage, it will display:

"" .$percentage." ".$project." items to charity for every £10 spent.";

I was thinking an elseif statement like:

elseif
$product["price"]>0

then the same code as the collumn code above but of course
$donation = sprintf("%.2f",((10/100) * $percent));

instead of

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

Thanks again, almost finished with these mods now :-)

Steven

but I get errors, still learning basics of php.

Cheers,

Steven

Submitted by support on Mon, 2008-09-01 07:42

Hi Steve

A single IF statement should do the trick, replacing this line:

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

...with:

if ($product["price"] > 0)
{
  $donation = sprintf("%.2f",(($product["price"]/100) * $percent));
}
else
{
  $donation = sprintf("%.2f",((10/100) * $percent));
}

Cheers,
David.

Submitted by steve on Sat, 2008-09-27 01:55

Hey David,

I have this bit of code in an extra column to display how much my users will donate to charity, calculated from the commission received.


<?php
if ($commission[$product["merchant"]])
{
  if (
strpos($commission[$product["merchant"]],"%"))
  {
    
// percentage
    
$percent str_replace("%","",$commission[$product["merchant"]]);
if (
$product["price"] > 0)
{
  
$donation sprintf("%.2f",(($product["price"]/100) * $percent));
}
else
{
  
$donation sprintf("%.2f",((10/100) * $percent));
}  }
  else
  {
    
// referral fee
    
$donation sprintf("%.2f",$commission[$product["merchant"]]);
  }
  print 
" <td valign='middle' align='center'>";
  foreach(
$contributions as $project => $cost)
  {
    
$percentage sprintf("%.2f",(($donation $cost) ));
    if (
strpos($commission[$product["merchant"]],"%"))
print 
"You will donate<strong>" .$percentage." ".$project."</strong> to charity for <strong>every &pound;10 spent</strong>.";
else
print 
"You will donate<strong>" .$percentage." ".$project."</strong> to charity on <strong>any purchase</strong>.<br />";
  }
  print 
"</td>";
  }
else
{
  
// no commission data
  
print " <td valign='middle' align='center'>We were unable to calculate how much you will donate to charity.</td>";
}
?>

The code calculates the amount donated in 3 ways depending whether the commission is a set fee or a percentage and whether the price is > 0 or not. These 3 ways are:

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

But the code only prints two statements:

No. 1 above displays "you will donate X amount for every £10 spent"
No. 2 above displays "you will donate X amount for every £10 spent"
No. 3 above displays you will donate X amount on any purchase"

So I need no.1 to display "you will donate X amount" as it is calculating for a specific product.

What would I need to do around this part of the code


if (strpos($commission[$product["merchant"]],"%"))
print "You will donate" .$percentage." ".$project." to charity for every £10 spent.";
else
print "You will donate" .$percentage." ".$project." to charity on any purchase.";

I tried:


if (strpos($commission[$product["merchant"]],"%")) && ($product["price"] > 0)
print "message";
else if (strpos($commission[$product["merchant"]],"%"))
print "message";
else
print "message";

Am I going along the right lines?

Cheers for your help, Steve.

Submitted by support on Sat, 2008-09-27 08:08

Hi Steve,

I would use the same IF structure as the code doing the calculation.... For example:

if ($commission[$product["merchant"]])
{
  if (strpos($commission[$product["merchant"]],"%"))
  {
    if ($product["price"] > 0)
    {
      print "you will donate ".$donation;
    }
    else
    {
      print "you will donate ".$donation." for every &pound;10 spent";
    }
  }
  else
  {
    print "you will donate ".$donation." amount on any purchase";
  }

Cheers,
David.

Submitted by steve on Sat, 2008-09-27 12:27

Hi David,

That doesn't seem to work for some reason. The page goes blank from the header down, but has no errors. When I was trying various ways of doing it yesterday it was doing the same.


print " ";
foreach($contributions as $project => $cost)
{
$percentage = sprintf("%.2f",(($donation / $cost) ));
if (strpos($commission[$product["merchant"]],"%"))
print "You will donate " .$percentage." ".$project." donate to charity for every £10 spent.";
else
print "You will donate " .$percentage." ".$project." to charity on any purchase.";
}
print "";
}
else
{
// no commission data
print " We were unable to calculate how much you will donate to charity.";
}
?>

That's my original code for the column and this is what I tried with your code:


print " ";
foreach($contributions as $project => $cost)
{
$percentage = sprintf("%.2f",(($donation / $cost) ));
if ($commission[$product["merchant"]])
{
if (strpos($commission[$product["merchant"]],"%"))
{
print "You will donate " .$percentage." ".$project." to charity.";
if ($product["price"] > 0)
{
print "You will donate " .$percentage." ".$project." to charity for every £10 spent.";
}
else
{
print "You will donate " .$percentage." ".$project." to charity on any purchase.";
} }
else
{
print "We were unable to calculate how much your will donate to charity.";
}

?>

Submitted by steve on Sat, 2008-09-27 13:06

Hi Dave, I think I solved this by using the similar structure I had before. This works:


if (strpos($commission[$product["merchant"]],"%") && $product["price"] == 0)
{print "You will donate " .$percentage." ".$project." to charity for every £10 spent.";}
else if (strpos($commission[$product["merchant"]],"%") && $product["price"] > 0)
{print "You will donate " .$percentage." ".$project." to charity.";}
else
{print "You will donate " .$percentage." ".$project." to charity on any purchase.";}
}
print "";
}
else
{
// no commission data

A lot of this was playing around as I don't know php, so i'm shocked it worked but I suppose it makes sense!

Cheers for your help :-)