7 replies [Last post]
interactiveallstar's picture
Offline
Joined: 04/23/2008
Juice: 3
Was this information Helpful?

Hi

This should be an easy one for someone who knows what they are doing! I'm looking to display the amount of discount offered off the List Price of a product on each products description e.g

List Price:£999
Our Price:£499
Discount:50%

Can anyone point me in the right direction?

Cheers

Martin

Al
Al's picture
Offline
Bug FinderGetting busy with the Ubercode.Internationalizationizer
Joined: 02/14/2008
Juice: 249
Computed field

Hi Martin,
you could use http://drupal.org/project/computed_field

Add a computed field to your product type, in Computed Code you enter without the PHP tags:

<?php
if ($node->list_price != $node->sell_price && $node->list_price > '0.01') {
 
$node_field[0]['value'] = round((1 - ($node->sell_price / $node->list_price)) * 100, 0);
}
?>

in Display Format:

<?php
if ($node_field_item['value']) {
 
$display = t('Discount') . ': ' . $node_field_item['value'] . '%';
}
?>

Use with caution, it's a long time since I did something similar, so no guarantee, but it should work.

green_nature's picture
Offline
Joined: 08/07/2007
Juice: 6
want a comma (instead of a point) in the discount value

Hi Al,
thank you for this workaround, it works for me.
If i change the line

<?php
$node_field
[0]['value'] = round((1 - ($node->sell_price / $node->list_price)) * 100, 0);
?>

to

<?php
$node_field
[0]['value'] = round((1 - ($node->sell_price / $node->list_price)) * 100, 2);
?>

i get a discount of "50.56 %" but i want a discount of "50,56 %" ?
I mean the comma in the discount...

In admin/store/settings/store/edit/format
my current format is: € 1.000,12 and
Number of decimal places: 2

Any idea to solve this?

PS. in my node-product.tpl.php i show this field with

<?php
print $node->field_discount[0]['value']
?>

TR
TR's picture
Online
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
<?php  print
<?php
 
print uc_currency_format($node->field_discount[0]['value']);
?>
<tr>.
green_nature's picture
Offline
Joined: 08/07/2007
Juice: 6
Hi TR, thank you for your

Hi TR,

thank you for your reply! I see it's the right way but now i get "Discount: € 50,50 %"
How can i format the field without the € symbol?
I need only 50,50 %. Have you any idea?

TR
TR's picture
Online
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
<?php  print
<?php
 
print uc_currency_format($node->field_discount[0]['value'], false);
?>
<tr>.
green_nature's picture
Offline
Joined: 08/07/2007
Juice: 6
Re: <?php  print

Merci! It works nicely!

Thank you

fehin's picture
Offline
Joined: 12/17/2008
Juice: 151
Re: Computed field

subscribing