Post by vourlismenos » Fri Jan 31, 2025 7:44 pm

Is there a way - custom code/extension - to display different number of decimals in the front end and the the admin?

I don't want to modify how the prices are stored, just how they are displayed.
For example I want to display the prices with three decimals in the admin side, but only two in the front end.
Last edited by vourlismenos on Wed Feb 05, 2025 8:01 pm, edited 1 time in total.

New member

Posts

Joined
Wed Dec 05, 2018 5:01 pm

Post by by mona » Fri Jan 31, 2025 9:01 pm

For future reference please read the forum rules before posting which you can find here viewtopic.php?t=200480

In admin it is displayed in 4 decimal places and in the front end in 2

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by vourlismenos » Tue Feb 04, 2025 3:30 pm

Sorry you are right, my question was too vague.
I have website in oc 3.0.3.2 in php 8.2.
It has several extensions and modifications and a very peculiar owner.

The product prices have indeed 4 decimals in the price, but that's shown when you actually edit or create the product.
In the product list and the order list - and when you click to see order details - the prices use the same amount of decimals as defined in the currency. In my case 2. Is there a way to see 3 (or more) decimals in the product/order lists? But still display 2 decimals in the front end?

New member

Posts

Joined
Wed Dec 05, 2018 5:01 pm

Post by nonnedelectari » Tue Feb 04, 2025 6:48 pm

vourlismenos wrote:
Tue Feb 04, 2025 3:30 pm
Sorry you are right, my question was too vague.
I have website in oc 3.0.3.2 in php 8.2.
It has several extensions and modifications and a very peculiar owner.

The product prices have indeed 4 decimals in the price, but that's shown when you actually edit or create the product.
In the product list and the order list - and when you click to see order details - the prices use the same amount of decimals as defined in the currency. In my case 2. Is there a way to see 3 (or more) decimals in the product/order lists? But still display 2 decimals in the front end?
Both admin and the catalog use the same currency data which includes the decimals which is stored in the database and used by the common currency class.
When inputting a price that field is just a number and is not controlled by the currency class.
To have different currency representation for admin and the catalog you would need an extension/modification.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by by mona » Tue Feb 04, 2025 10:44 pm

vourlismenos wrote:
Tue Feb 04, 2025 3:30 pm
Sorry you are right, my question was too vague.
I have website in oc 3.0.3.2 in php 8.2.
It has several extensions and modifications and a very peculiar owner.

The product prices have indeed 4 decimals in the price, but that's shown when you actually edit or create the product.
In the product list and the order list - and when you click to see order details - the prices use the same amount of decimals as defined in the currency. In my case 2. Is there a way to see 3 (or more) decimals in the product/order lists? But still display 2 decimals in the front end?
The simplest way would be to remove currency in admin for the list
In admin catalog controller under getList find all the prices (inc specials etc) and change them from

Code: Select all

'price'      => $this->currency->format($result['price'], $this->config->get('config_currency')),
and change to

Code: Select all

'price'      => $result['price'],
Alternatively you could set up a second currency for the back end and add it directly to the database to have something like

Code: Select all

'price'      => $this->currency->format($result['price'], $this->config->get('config_currency2')),
If you dont understand / not following / not know how to do this you will have to get an extension built.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by vourlismenos » Tue Feb 04, 2025 11:53 pm

Thank you that looks promising!
I'll have a go and see if it works out !

by mona wrote:
Tue Feb 04, 2025 10:44 pm
vourlismenos wrote:
Tue Feb 04, 2025 3:30 pm
Sorry you are right, my question was too vague.
I have website in oc 3.0.3.2 in php 8.2.
It has several extensions and modifications and a very peculiar owner.

The product prices have indeed 4 decimals in the price, but that's shown when you actually edit or create the product.
In the product list and the order list - and when you click to see order details - the prices use the same amount of decimals as defined in the currency. In my case 2. Is there a way to see 3 (or more) decimals in the product/order lists? But still display 2 decimals in the front end?
The simplest way would be to remove currency in admin for the list
In admin catalog controller under getList find all the prices (inc specials etc) and change them from

Code: Select all

'price'      => $this->currency->format($result['price'], $this->config->get('config_currency')),
and change to

Code: Select all

'price'      => $result['price'],
Alternatively you could set up a second currency for the back end and add it directly to the database to have something like

Code: Select all

'price'      => $this->currency->format($result['price'], $this->config->get('config_currency2')),
If you dont understand / not following / not know how to do this you will have to get an extension built.

New member

Posts

Joined
Wed Dec 05, 2018 5:01 pm

Post by nonnedelectari » Wed Feb 05, 2025 1:07 pm

You can also do this:

in system/library/cart/currency.php

add variable:

Code: Select all

private $decimal_place_override = false;
add function:

Code: Select all

	public function decimal_place_override_set ($value) {
		$this->decimal_place_override = (int)$value;
	}
in function format, replace this:

Code: Select all

$decimal_place = $this->currencies[$currency]['decimal_place'];
with:

Code: Select all

$decimal_place = ($this->decimal_place_override !== false ? $this->decimal_place_override : $this->currencies[$currency]['decimal_place']);
in admin/controller/startup/startup.php
add this:

Code: Select all

$this->currency->decimal_place_override_set (4);
after this:

Code: Select all

		// Currency
		$this->registry->set('currency', new Cart\Currency($this->registry));
That will make sure that while using the same currency class as the front-end, in admin only the decimal places are overridden with 4.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by vourlismenos » Wed Feb 05, 2025 3:21 pm

Thank you I'll try it as well!
nonnedelectari wrote:
Wed Feb 05, 2025 1:07 pm
You can also do this:

in system/library/cart/currency.php

add variable:

Code: Select all

private $decimal_place_override = false;
add function:

Code: Select all

	public function decimal_place_override_set ($value) {
		$this->decimal_place_override = (int)$value;
	}
in function format, replace this:

Code: Select all

$decimal_place = $this->currencies[$currency]['decimal_place'];
with:

Code: Select all

$decimal_place = ($this->decimal_place_override !== false ? $this->decimal_place_override : $this->currencies[$currency]['decimal_place']);
in admin/controller/startup/startup.php
add this:

Code: Select all

$this->currency->decimal_place_override_set (4);
after this:

Code: Select all

		// Currency
		$this->registry->set('currency', new Cart\Currency($this->registry));
That will make sure that while using the same currency class as the front-end, in admin only the decimal places are overridden with 4.

New member

Posts

Joined
Wed Dec 05, 2018 5:01 pm

Post by vourlismenos » Wed Feb 05, 2025 6:10 pm

It worked like a charm!
Thank you
I made a small xml and uploaded it in vqmod and works great.

nonnedelectari wrote:
Wed Feb 05, 2025 1:07 pm
You can also do this:

in system/library/cart/currency.php

add variable:

Code: Select all

private $decimal_place_override = false;
add function:

Code: Select all

	public function decimal_place_override_set ($value) {
		$this->decimal_place_override = (int)$value;
	}
in function format, replace this:

Code: Select all

$decimal_place = $this->currencies[$currency]['decimal_place'];
with:

Code: Select all

$decimal_place = ($this->decimal_place_override !== false ? $this->decimal_place_override : $this->currencies[$currency]['decimal_place']);
in admin/controller/startup/startup.php
add this:

Code: Select all

$this->currency->decimal_place_override_set (4);
after this:

Code: Select all

		// Currency
		$this->registry->set('currency', new Cart\Currency($this->registry));
That will make sure that while using the same currency class as the front-end, in admin only the decimal places are overridden with 4.

New member

Posts

Joined
Wed Dec 05, 2018 5:01 pm

Post by paulfeakins » Wed Feb 05, 2025 7:30 pm

vourlismenos wrote:
Wed Feb 05, 2025 6:10 pm
It worked like a charm!
So could you add [SOLVED] to the start of this topic title?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by vourlismenos » Wed Feb 05, 2025 8:02 pm

of course, done!
paulfeakins wrote:
Wed Feb 05, 2025 7:30 pm
vourlismenos wrote:
Wed Feb 05, 2025 6:10 pm
It worked like a charm!
So could you add [SOLVED] to the start of this topic title?

New member

Posts

Joined
Wed Dec 05, 2018 5:01 pm
Who is online

Users browsing this forum: Amazon [Bot], khnaz35 and 11 guests