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.tpl. Open it and add the following inside php tags:

<br />class Product extends ProductCore<br />{<br />}<br />

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:

<br /><br />class Product extends ProductCore<br />{<br /><br /><%%KEEPWHITESPACE%%>    public $rrp;<br /><br /><%%KEEPWHITESPACE%%>    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)<br /><%%KEEPWHITESPACE%%>    {<br /><%%KEEPWHITESPACE%%>        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');<br /><%%KEEPWHITESPACE%%>        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);<br /><%%KEEPWHITESPACE%%>    }<br /><br />}<br /><br />

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:

<br /><%%KEEPWHITESPACE%%>	<tr><br /><%%KEEPWHITESPACE%%>		<td class="col-left"><br /><%%KEEPWHITESPACE%%>			{include file="controllers/products/multishop/checkbox.tpl" field="price" type="price"}<br /><%%KEEPWHITESPACE%%>			<label>{l s='Pre-tax retail price:'}</label><br /><%%KEEPWHITESPACE%%>		</td><br /><%%KEEPWHITESPACE%%>		<td style="padding-bottom:5px;"><br /><%%KEEPWHITESPACE%%>			<input type="hidden"  id="priceTEReal" name="price" value="{toolsConvertPrice price=$product->price}" /><br /><%%KEEPWHITESPACE%%>			{$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}<br /><%%KEEPWHITESPACE%%>			<p class="preference_description">{l s='The pre-tax retail price to sell this product'}</p><br /><%%KEEPWHITESPACE%%>		</td><br /><%%KEEPWHITESPACE%%>	</tr><br />

Right before it, add

<br /><%%KEEPWHITESPACE%%>	<tr><br /><%%KEEPWHITESPACE%%>		<td class="col-left"><br /><%%KEEPWHITESPACE%%>			{include file="controllers/products/multishop/checkbox.tpl" field="price" type="price"}<br /><%%KEEPWHITESPACE%%>			<label>{l s='Retail Price:'}</label><br /><%%KEEPWHITESPACE%%>		</td><br /><%%KEEPWHITESPACE%%>		<td style="padding-bottom:5px;"><br /><%%KEEPWHITESPACE%%>			<input type="hidden"  id="priceTEReal2" name="rrp" value="{toolsConvertPrice price=$product->rrp}" /><br /><%%KEEPWHITESPACE%%>			{$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}<br /><%%KEEPWHITESPACE%%>			<p class="preference_description">{l s='Normal retail price'}</p><br /><%%KEEPWHITESPACE%%>		</td><br /><%%KEEPWHITESPACE%%>	</tr><br /><br />

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:

<br /><div class="price"><br /><%%KEEPWHITESPACE%%>				<p class="our_price_display"><br />

And right before it, add:

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

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:

<br /><br />Class ProductController extends ProductControllerCore<br />{<br /><br />}<br /><br />

Then, let’s extend initContent as follows

<br /><%%KEEPWHITESPACE%%>	public function initContent()<br /><%%KEEPWHITESPACE%%>	{<br /><br /><%%KEEPWHITESPACE%%>		$default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));<br /><br /><%%KEEPWHITESPACE%%>		$this->product->rrp = Tools::convertPriceFull($this->product->rrp, $default_currency, $this->context->currency);<br /><br /><%%KEEPWHITESPACE%%>		parent::initContent();<br /><br /><%%KEEPWHITESPACE%%>	}<br />

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:

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

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

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

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:

<br /><%%KEEPWHITESPACE%%>	public function initContent()<br /><%%KEEPWHITESPACE%%>	{<br /><%%KEEPWHITESPACE%%>    	parent::initContent();<br /><br /><%%KEEPWHITESPACE%%>	}<br /><br />

We are overriding the initContent() method once again.

Inside it, add

<br /><br /><%%KEEPWHITESPACE%%> 	$default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));<br /><br /><%%KEEPWHITESPACE%%>	if($this->cat_products)<br /><%%KEEPWHITESPACE%%>	{<br /><%%KEEPWHITESPACE%%>		foreach ($this->cat_products as $pk => $product) {<br /><br /><%%KEEPWHITESPACE%%>			$this->cat_products[$pk]['rrp'] = Tools::convertPriceFull($product['rrp'], $default_currency, $this->context->currency);<br /><%%KEEPWHITESPACE%%>		}<br /><%%KEEPWHITESPACE%%>	}<br /><br /><%%KEEPWHITESPACE%%>	$this->context->smarty->assign('products', $this->cat_products);<br /><br />

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!

Need Prestashop Modules? Have a look at my Prestashop Addons Store!

Looking for quality PrestaShop Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , | Posted under PrestaShop | RSS 2.0

Author Spotlight

Fabio Porta

Fabio Porta

Fabio has been involved in web development and design since 2005, when launched his first website at the age of 16. He’s now highly skilled in both client and server side development, along with design, and since August 2012 runs a successful website about PrestaShop tutorials and Prestashop Modules called Nemo’s Post Scriptum, at http://nemops.com

6 Comments on Adding RRP Price to Better Showcase “Our Price” in Prestashop

  1. Maria says:

    Hi Fabio,
    First of all, I would like to congratulate you for this fabulous post. I was thinking about doing something very similar in my store and I was wondering if you could help me with this:
    I would like to display in the front two prices: pretax whole sale price and retail price with tax (already displayed by default). I am working in a store for a distributor who sells to small shops. These shops need to know their cost price and also the recommended retail price to know their benefits. I am using the field pretax whole sale price to indicate the cost price of the shops, not the one of the distributor.
    Do you know if it is possible to do this?
    Thank you so much!
    María

    • Fabio Porta Fabio Porta says:

      Hi Maria,
      I am not sure I understood your query 100%, but if you mean displaying the wholesale price in the front office, it should be $product.wholesale_price in the product list (it *should* be available by default) and $product->wholesale_price in the product page.

  2. Mobilista says:

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

Leave a Reply

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


5 + = 7

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>