Adding RRP Price to better showcase “Our Price” in Prestashop

If you are selling products at a competitive price, you might want to showcase how much your customer can save in comparison to the normal online (or retail price). Let’s add a new price field for your products then!

Download Project Files
  • Version Used: Prestashop 1.5 (works on all 1.5 versions)

You might be selling products at an extremely competitive price. So, your customers have the right to know (and you have all the interest in showing) how much they are saving, compared to other online shops or in any case compared to the recommended retail price (rrp).

Once more, although Prestashop doesn’t come with such a functionality as out-of-the-box, there is a simple way to add it by using our beloved overrides. In this case:

  • Product.php
  • prices.tpl (back office template file)
  • product.tpl (front office, to showcase the price)
  • optional: product-list.tpl (to show the price in the products list as well)
  • optional(for multiple currencies support): Product Controller
  • optional(for multiple currencies support): Category Controller

If you didn’t do it already, it might be worth reading my tutorial on How to extend Prestashop Objects, before tackling this one, as we will use the same base method to extend Products.

Step 1 – Overriding and extending the Product Class

Database Operations

As a first step, we must extend the Product Class so it accepts another field. We will call it rrp so it’s easy to understand what it is.
The very first thing to do is to add the field to the database. Therefore, login to your database manager, look for the ps_product table in your web shop’s database, and add a new field as follows:

Adding the RRP price field in Pretashop's Database

Please note that this way won’t allow you to have a different RRP price if you use multistore.

Adding the Override

Now that the product table contains another column, we can proceed and tell the Product Object about its new property. To do it, create a new php file inside override/classes and call it Product.php. Open it and add the following inside php tags:

class Product extends ProductCore
{
}

Then, add the $rpp property, and using the method described (once more!) in my other tutorial on How to extend Prestashop Objects, add the field to the Object’s definition:


class Product extends ProductCore
{

    public $rrp;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }

}

This part is finished already, so head over to /cache/ and delete class_index.php so our new override can be seen by Prestashop.

Step 2 – The back office input

We need, of course, a way to add the retail price to our products. No better place than the default price tab, in the product’s back office, right? Therefore, we must override the tpl which is used to generate the page. Head over to your admin folder, then themes\default\template\controllers\products and copy prices.tpl

Paste it in override/controllers/admin/templates/products. Where to put the RRP field is entirely up to you; I chose to insert the field right above the normal price (Pre-tax retail price). In addition, as this one already reads “retail price” I will change it to “Our Price”, and let the new one as “RRP”.

Therefore, look for the next snippet:

	<tr>
		<td class="col-left">
			{include file="controllers/products/multishop/checkbox.tpl" field="price" type="price"}
			<label>{l s='Pre-tax retail price:'}</label>
		</td>
		<td style="padding-bottom:5px;">
			<input type="hidden"  id="priceTEReal" name="price" value="{toolsConvertPrice price=$product->price}" />
			{$currency->prefix}<input size="11" maxlength="14" id="priceTE" name="price_displayed" type="text" value="{{toolsConvertPrice price=$product->price}|string_format:'%.2f'}" onchange="noComma('priceTE'); $('#priceTEReal').val(this.value);" onkeyup="$('#priceType').val('TE'); $('#priceTEReal').val(this.value.replace(/,/g, '.')); if (isArrowKey(event)) return; calcPriceTI();" />{$currency->suffix}
			<p class="preference_description">{l s='The pre-tax retail price to sell this product'}</p>
		</td>
	</tr>

Right before it, add

	<tr>
		<td class="col-left">
			{include file="controllers/products/multishop/checkbox.tpl" field="price" type="price"}
			<label>{l s='Retail Price:'}</label>
		</td>
		<td style="padding-bottom:5px;">
			<input type="hidden"  id="priceTEReal2" name="rrp" value="{toolsConvertPrice price=$product->rrp}" />
			{$currency->prefix}<input size="11" maxlength="14" id="priceTE2" name="price_displayed" type="text" value="{{toolsConvertPrice price=$product->rrp}|string_format:'%.2f'}" onchange="noComma('priceTE2'); $('#priceTEReal2').val(this.value);" onkeyup="$('#priceType').val('TE2'); $('#priceTEReal2').val(this.value.replace(/,/g, '.')); if (isArrowKey(event)) return; calcPriceTI();" />{$currency->suffix}
			<p class="preference_description">{l s='Normal retail price'}</p>
		</td>
	</tr>

And the new price field will be added as input to the back office. Just to make sure to avoid useless confusion, I personally suggest you to change the previous “Pre-tax retail price” label to “Our price” or something equally meaningful.

RRP price added to the Prestashop Back Office

Add your rrp and save, it should be preserverd once you are back to the page.

Step 3 – Showcasing the RRP Price

Everything is settled, we only need to show the normal RRP price in the front office. Let’s start by amending the product.tpl file, which can be found in your current theme’s folder. Make sure you back up the file before editing it, of course!
Once more, I arbitrary chose the display position, so feel free to place it wherever you like.

Locate:

<div class="price">
				<p class="our_price_display">

And right before it, add:

{if $product->rrp|floatval}
	<div class="rrp-price">
	{l s='RRP:'}
	<span class="rrp" style="text-decoration:line-through">
		{displayPrice price=$product->rrp}
	</span>
	</div>
{/if}

Explanation: First, we make sure that the float value of the RRP price is not 0 (otherwise it means we didn’t set an RRP). Then, we simply display the value and format it as the current price settings.

HOLD ON! How to deal with multiple currencies? If you notice, at the moment the RRP will stay the same, even if you change currency. This is a huge issue for web stores featuring multiple currencies! Let’s see how to deal with it.

Dealing with multiple currencies

This step is entirely optional, as you won’t need it if you run your sop in one currency only.

To achieve the multi-currency result, we have to add some logic at the time the RRP is retrieved. For the product page, we must override the ProductController. Therefore, create a new file named ProductController.php and add the following inside:


Class ProductController extends ProductControllerCore
{

}


Then, let’s extend initContent as follows

	public function initContent()
	{
		
		$default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
		
		$this->product->rrp = Tools::convertPriceFull($this->product->rrp, $default_currency, $this->context->currency);

		parent::initContent();
		
	}

Explanation: We must get the rrp in the default currency. So, assuming the price we input from the back office is in the default one, we get an instance of the shop’s default currency, then we use the Tools::convertPriceFull($amount, $from_currency, $to_currency) method to convert it to the current customer’s one. Lastly, we need, of course, to call the original initContent().

Delete the class_index fdile again, and refresh the page. You should see the correct RRP appear!

RRP Price in the Prestashop Product Detail Page

Adding the RRP in category pages

Similarly to what we did before, let’s add the rrp to the product-list.tpl file too (once more, theme folder) and locate the following snippet:

{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
				<div class="content_price">

Note that I am using the default template again. Inside the content_price element, add:

	{if $product.rrp|floatval}
		<div class="rrp-price-listing">
		{l s='RRP:'}
		<span class="rrp" style="text-decoration:line-through">
			{displayPrice price=$product.rrp}
		</span>
		</div>
	{/if}

It’s almost identical to the one we used in the product template file, with the only difference that we are accessing the product as an array, instead of an object.

What about supporting multiple currencies here? It’s a little trickier, we need to edit the CategoryController!

Multiple currencies in the product list (Category page)

So, we need another override! This time it will we a little tricker. Create a new file named CategoryController in override/controllers/front, and paste the usual override snippet:

	public function initContent()
	{
    	parent::initContent();

	}

We are overriding the initContent() method once again.

Inside it, add


 	$default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));

	if($this->cat_products)
	{
		foreach ($this->cat_products as $pk => $product) {

			$this->cat_products[$pk]['rrp'] = Tools::convertPriceFull($product['rrp'], $default_currency, $this->context->currency);
		}
	}

	$this->context->smarty->assign('products', $this->cat_products);

	

Explanation: We first grab the default currency again. Then, we loop through all the category’s products (if they have been assigned!), converting the RRP price for each of them. In the end, we simply re-assign the products variable so that changes are reflected in the front office.

For the last time, delete the class_index file.

RRP Price in the Prestashop Products List Page

Conclusion

Although we added the RRP column in the database and Product Class, further steps need to be taken in order to show the correct price in multiple currencies. Please note that the above methods do not apply to other pages and modules (best sales page, search page, home featured module); you’ll have to use other overrides, or edit core files the same way to achieve the expected results. Bummer! Hopefully, we will get a uniform method, in the future.

As I already stressed, this tutorial will not set a different price for each store, if you are on a multistore environment, so keep an eye on that!

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

  • Albert

    Hi Nemo. Thanks for the tutorial. It works on 1.6 but I have a few issues. For products that have combinations where the combo increases the price, it’s not increasing the RRP price as well. So say I select combination B and it adds $1 to the price, it should add $1 to the RRP price as well.

    Also, it’s showing $0.00 for products that I haven’t added the RRP price to. How can we disable the RRP price for products that I don’t have one entered for?

    Thanks!

    • NemoPS

      Hi Albert! Did you add the condition? It should not display with that, unless it’s a positive value

  • Bodo Hauser

    Hello, great tutorial and am glad it works in general but have often rrp=our price in the database and in the back office product prices fields.
    In these cases I don´t want to show in front office an rrp (same price as the price we want) Makes no good impression having a stroken price of the same amount called rrp as the above shown valid price..
    Anybody any idea how to solve this ?
    Ths so much, regards, B.

  • Nandos

    Hi Nemo, very interesting guide. Any hint to make it effective for a PS v1.6.1.12? Because the structure and the files differ greatly from the ones in this article. Let me know.
    Also, Happy Easter!

  • Emmanuel Swami

    Hi Nemo,

    I have installed it on 1.6.1.2 but the rrp field is not visible in backend, can you please help me on this.

    Regards,

    Jimmy

  • NemoPS

    Thanks for spotting, fixed :)

  • Nick

    Hi Nemo

    Does this functionality extend to the combination prices?

    • NemoPS

      Hi Nick,
      Unfortunately not, you’ll have to modify the product_attribute table in order to do that, as well as the Combination class

  • J. Fernando Galvez

    Hi there.!! how i can override the price.js … and use it…. thk… for the BO

  • Splash Salons

    Hello Nemo,

    This is an amazing tutorial, it helped me a lot with my work…However I have a question, if I wanted to use this rrp price to feed a module in order to use this price instead of the original product price, should I use the $Product->rrp expression? or there is another way to do it?

  • Mobilista

    Hi, Should you instructions to version 1.6.0.8? Thank you. This not work :-(.

  • http://macuration.tumblr.com/ Michele.

    Hello Nemo, your tutorial just save my night (and money). Thank you!
    I’ve tried an another tutorial of your that didn’t work for me (the cart ajax) but this one is really awesome !

    It’s working with PS 1.6.06 !

  • Kon Rad

    Works with 1.6.0.5 with ease!

  • Dawid

    Percentage “save money” just adding in product.tpl:

    {if $product->rrp|floatval}

    {l s=’RRP:’}

    {displayPrice price=$product->rrp}

    {l s=’You save:’}
    {if !$priceDisplay || $priceDisplay == 2}
    {convertPrice price=($product->rrp – $product->getPrice(true, $smarty.const.NULL))}
    {l s='(‘}{round((($product->rrp – $product->getPrice(true, $smarty.const.NULL)) / $product->rrp) * 100, 0)}%{l s=’)’}
    {elseif $priceDisplay == 1}
    {convertPrice price=($product->rrp – $product->getPrice(false, $smarty.const.NULL))}
    {l s='(‘}{round((($product->rrp – $product->getPrice(false, $smarty.const.NULL)) / $product->rrp) * 100, 0)}%{l s=’)’}
    {/if}

    {/if}

  • Angela

    Hi Nemo, your tutorial is very good.

    If possible, I need your help, I added 2 new fields ( discount_whls – markup ) int the ps_product and ps_product_shop and i added them in the B.O.

    I follow the steps of your tutorial but now I would to calculate the variable price from the wholesale_price and the new % fields … I don’t know how to do it.

    this is the formula to calculate the price pre-tax:
    price = (wholesale_price – (wholesale_price/100 * discount_whls)) + ((wholesale_price – (wholesale_price/100 * discount_whls)) * markup )

    Can you help me?
    thanks
    Angela

  • Zen

    What if 3 different attribute has three different retail price for example 8gb= rrp 200, 16gb = rrp 300 and 32gb =rrp 400

Store Top Sales

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: