How to round prices for yen in PrestaShop v1.6

This is NOT a solution, it creates a visual solution in the frontend but backend has a problem with other currencies.

Here is my version and record in how I enabled the ability to round up the prices of yen to a number that is cleaner then what was converted by the exchange rate.

The problem explained.
1. I use PrestaShop v1.6
2. Prices of products are added in USD.
3. These prices are converted to JPY for Japanese customers.
4. The conversion of $650 to JPY at an exchange rate of 119.361 JPY (to 1 USD) equals a price of 77,584.47 JPY.
5. This price of 77,584.47 JPY is unreadable and lacks professions marketing image. It should/could read something like ¥77,500 or ¥78,000.

This fix was done by making a few edits, which ended up creating problems in the BackOffice… I will work on fixing those as well.
1. Need to add the option of rounding numbers to BackOffice -> Preferences -> General under line line ‘Round mode’.
2. Add the function for this new option.
3. Activate this option.

Part 1 – Adding option:
Under the ROOT/config/defines.inc.php file. I added line 149.

define('PS_ROUND_UP', 0);
define('PS_ROUND_DOWN', 1);
define('PS_ROUND_HALF_UP', 2);
define('PS_ROUND_HALF_DOWN', 3);
define('PS_ROUND_HALF_EVEN', 4);
define('PS_ROUND_HALF_ODD', 5);
define('PS_ROUND_YEN', 6);

Added this:

define('PS_ROUND_YEN', 6);

It is important to note the number ‘6’ as we will use that in creating the function. Also, the ‘PS_ROUND_YEN’ is the title I gave it.

It is important to note that this above edit may/will be removed upon any PrestaShop upgrade as it is not in the override folder.

Part 2 – ??
Copy the ROOT/controllers/admin/AdminPreferencesController.php to ROOT/override/controllers/admin/AdminPreferencesController.php
By placing changed files in this /override/ folder it should be kept if any update occurs.
I added lines 64 to 67.

if (get_class($this) == 'AdminPreferencesController')
		{
			$round_mode = array(
				array(
					'value' => PS_ROUND_HALF_UP,
					'name' => $this->l('Round up away from zero, when it is half way there (recommended)')
				),
				array(
					'value' => PS_ROUND_HALF_DOWN,
					'name' => $this->l('Round down towards zero, when it is half way there')
				),
				array(
					'value' => PS_ROUND_HALF_EVEN,
					'name' => $this->l('Round towards the next even value')
				),
				array(
					'value' => PS_ROUND_HALF_ODD,
					'name' => $this->l('Round towards the next odd value')
				),
				array(
					'value' => PS_ROUND_UP,
					'name' => $this->l('Round up to the nearest value')
				),
				array(
					'value' => PS_ROUND_DOWN,
					'name' => $this->l('Round down to the nearest value')
				),
				array(
					'value' => PS_ROUND_YEN,
					'name' => $this->l('Round to the nearest 100 yen')
				),
			);

Added this:

				array(
					'value' => PS_ROUND_YEN,
					'name' => $this->l('Round to the nearest 100 yen')
				),
			);

Part 3 – Add the actual function to Tools.php

I added 1633 & 1634.
I tested this code on this php tester site.

public static function ps_round($value, $precision = 0)
	{
		if (Tools::$round_mode == null)
			Tools::$round_mode = (int)Configuration::get('PS_PRICE_ROUND_MODE');

		switch (Tools::$round_mode)
		{
			case PS_ROUND_UP:
				return Tools::ceilf($value, $precision);
			case PS_ROUND_DOWN:
				return Tools::floorf($value, $precision);
			case PS_ROUND_HALF_DOWN:
			case PS_ROUND_HALF_EVEN:
			case PS_ROUND_HALF_ODD:
				return Tools::math_round($value, $precision, Tools::$round_mode);
			case PS_ROUND_HALF_UP:
			default:
				return Tools::math_round($value, $precision, PS_ROUND_HALF_UP);
			case PS_ROUND_YEN:
				return round($value, -3, PHP_ROUND_HALF_UP);
		}
	}

Part 4 – more tools.
I don’t understand why the function must be created twice… but here it is. This could relate to the inconsistency in the pricing in the backend.

It is important to note that this above edit may/will be removed upon any PrestaShop upgrade as it is not in the override folder.

Under the ROOT/js/tools.js file. I added line 137 & 138.

	if (method === 0)
		return ceilf(value, places);
	else if (method === 1)
		return floorf(value, places);
	else if (method === 2)
		return ps_round_half_up(value, places);
	else if (method == 6)
		return Math.round(value / 1000) * 1000;
	else if (method == 3 || method == 4 || method == 5)

PROBLEM…. I now get all lists of USD prices in the BackOffice in a rounded format… this could create more problems.

Avoid being blocked by a website or online service because you are overseas!

I first came to Japan 10 years ago and technology has changed a lot since then. I wanted to see website content, like CBC or NBC online content, but was frequently blocked due to my IP address. UnblockUs Inc. is a company and service which will allow for freedom from these current restrictions. I first used this service to watch the Sochi Olympics, now I use it to watch many different shows which are not broadcasted on Japanese networks.