How To Show Special Price More Clearly

By | August 5, 2008

This question was asked in the official osCommerce forum:

How can i make it so in product_info it shows original price, discount price and percentage off?

The question asker also linked to a website, which I won’t link to, but will show a partial screenshot of what he/she wants osCommerce to do:

My answer was as follows:

Use the “specials” feature of your admin, and then write a new piece of code that shows the % discount.

Honestly, that should be enough to give most people, non-coders included a good clue to get on and write something. Then I thought it might make a good blog post, so…

Step 1 – change the layout of the special price!

OK, so first, we need to slightly amend the way that the special price is shown in the product pages – this is simple, find this code:

[php]$products_price = ‘‘ . $currencies->display_price($product_info[‘products_price’], tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘ ‘ . $currencies->display_price($new_price, tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘‘;[/php]

What we need to do for starters is put a line break between the two prices. Easy as 123, just change the code like this:

[php]$products_price = ‘‘ . $currencies->display_price($product_info[‘products_price’], tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘
‘ . $currencies->display_price($new_price, tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘‘;[/php]

You can see the <br /> I added. This makes the layout of the prices go over two lines…

Step 2: Add a couple extra pieces of “text”

All this is doing is allowing us the ability to add text in the correct osCommerce fashion. So find the piece of code to which you just added a <br /> and change it to:

[php]$products_price = TEXT_LIST_PRICE . ‘‘ . $currencies->display_price($product_info[‘products_price’], tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘
‘ . TEXT_SPECIAL_PRICE . ‘‘ . $currencies->display_price($new_price, tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘‘;[/php]

Now your price should look like this:

Don’t worry that it looks awful – we will be changing this right at the very end of this howto tutorial.

Step 3: Add the code to show the “saving” price

This is a very simple calculation, it’s simply the old price LESS the new price! So, change the piece of code to:

[php]$products_price = TEXT_LIST_PRICE . ‘‘ . $currencies->display_price($product_info[‘products_price’], tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘
‘ . TEXT_SPECIAL_PRICE . ‘‘ . $currencies->display_price($new_price, tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘
‘ . TEXT_YOU_SAVE . $currencies->display_price(($product_info[‘products_price’] – $new_price), tep_get_tax_rate($product_info[‘products_tax_class_id’]));[/php]

Now the price area looks like this:

As you can see, it’s starting to come together.

Step 4: Showing the % saved

We now need to add the % saving – this is a slightly tricky piece of code as it’s quite hard to understand what’s going on…fortunately, this code already exists within the admin page for specials.php and the code looks like this (lifted from admin/specials.php):

[php]$contents[] = array(‘text’ => ” . TEXT_INFO_PERCENTAGE . ‘ ‘ . number_format(100 – (($sInfo->specials_new_products_price / $sInfo->products_price) * 100)) . ‘%’);[/php]

Now, we need to use part of that code and tack it on the end of our “price” code! So, change up the code to look like this:

[php]$products_price = TEXT_LIST_PRICE . ‘‘ . $currencies->display_price($product_info[‘products_price’], tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘
‘ . TEXT_SPECIAL_PRICE . ‘‘ . $currencies->display_price($new_price, tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘
‘ . TEXT_YOU_SAVE . $currencies->display_price(($product_info[‘products_price’] – $new_price), tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘ (‘ . number_format(100 – (($new_price / $product_info[‘products_price’]) * 100)) . ‘%)’;[/php]

Now, our price view looks like this:

As you can see, this is now showing all the calculations that we require. All that is left is to change the wordings…

Step 5: Language Defines

Open up /includes/languages/english/product_info.php and add the following code:

[php]define(‘TEXT_LIST_PRICE’, ‘List Price: ‘);
define(‘TEXT_SPECIAL_PRICE’, ‘Price: ‘);
define(‘TEXT_YOU_SAVE’, ‘You Save: ‘);[/php]

You’ll see where to add this when you open the file – it’s very straightforward. Repeat for each language that you use in your store.

Now, assuming all of the above went smoothly, your price view should look like this:

Voila! If you liked this How To, please consider buying me a beer, it keeps me motivated 😉

7 thoughts on “How To Show Special Price More Clearly

  1. cassie

    Thanks Gary 🙂

    With a little more understanding on my part I was able to change this to my needs.

    Excellent. Thanks for all the work you put in with all this stuff. Learning just how these files work not just adding code like before without understanding any of it
    🙂

  2. GuinnessBoy

    If your Shop use SPPC the above mentionned code is replaced by the PriceFormatter.php class so use this instead.

    line 355

    if ($this->hasSpecialPrice == true) {
    $lc_text = ‘ ‘
    . $currencies->display_price($this->thePrice, tep_get_tax_rate($this->taxClass))
    . ”
    . $currencies->display_price($this->specialPrice, tep_get_tax_rate($this->taxClass))
    . ” . TEXT_YOU_SAVE . ”
    . $currencies->display_price(($this->thePrice – $this->specialPrice), tep_get_tax_rate($product_info[‘products_tax_class_id’])) . ‘soit ‘ . number_format(100 – (($this->specialPrice / $this->thePrice) * 100)) . ‘%’;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *