Price: Hide currency code and not show decimals

  • Posts: 23
  • Thank you received: 0
12 years 2 weeks ago #120602

-- HikaShop version -- : 2.2.0
-- Joomla version -- : 3.1.5
-- PHP version -- : 5.3.27

Hi,

Is there a way in the product price to hide the currency code and not show decimal numbers?

Regards

Last edit: 12 years 2 weeks ago by cipionhabla.

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
12 years 2 weeks ago #120622

Hi there,

To do so you have to edit the view listing_price of product (Display>Views).
You will find there the html and php code used to display the price so you can add a round() on a price to not display the decimal and you can delete the currency code by using directly:

$price->price_orig_value_with_tax
instead of:
echo $this->currencyHelper->format($price->price_orig_value_with_tax,$price->price_orig_currency_id);

(this is an example, it may be a different line according to the way you display your prices)

Please Log in or Create an account to join the conversation.

  • Posts: 44
  • Thank you received: 0
11 years 2 months ago #163504

Hi,

I've tried this.
Result: 13,00 € -> 13.00000
What do I have to add to "echo $price->price_value_with_tax;" or delete from "echo $this->currencyHelper->format(@$price->price_value_with_tax,$price->price_currency_id);" to hide only currency code?

Thanks in advance.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 2 months ago #163514

Hi,

You can simply change the settings via the menu System > Currencies.

Or edit:

echo $this->currencyHelper->format(@$price->price_value_with_tax,$price->price_currency_id);
To add a '!' as third parameter, like:
echo $this->currencyHelper->format(@$price->price_value_with_tax,$price->price_currency_id,'!');

Please Log in or Create an account to join the conversation.

  • Posts: 44
  • Thank you received: 0
11 years 2 months ago #163635

Hi, Xavier

thank you. The second solution better suits my needs, because I want to hide currency code only in a certain part of my web. But when I have added '!' as third parameter, I got the price looking like " !".

UPD: Now I see that I can't hide currency code in a particular part of the web, directly editing listing_price...
I want to hide currency code in listing table.

Last edit: 11 years 2 months ago by denoo.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #163639

Hi,

Indeed, so another solution is just to use the str_replace php function like:

$curr = '';
$currencyInfo = $this->currencyHelper->getCurrencies($price->price_currency_id,$curr);
echo str_replace(array($currencyInfo[1]->currency_symbol,$currencyInfo[1]->currency_code),'',$this->currencyHelper->format(@$price->price_value_with_tax,$price->price_currency_id));

Last edit: 11 years 1 month ago by Jerome. Reason: improve code
The following user(s) said Thank You: denoo

Please Log in or Create an account to join the conversation.

  • Posts: 44
  • Thank you received: 0
11 years 1 month ago #163820

Hi,

amatuer question: where it must be pasted?
I figure that it must be pasted directly in listing_table instead of loading listing_price template, so:

<?php
if($this->params->get('show_price','-1')=='-1'){
$config =& hikashop_config();
$this->params->set('show_price',$config->get('show_price'));
}
if($this->params->get('show_price')){ ?>
<td class="hikashop_product_price_row">
<?php
//$this->setLayout('listing_price');
//echo $this->loadTemplate();
$currencyClass = hikashop_get('class.currency');
$curr = '';
$currencyInfo = $currencyClass->getCurrencies($price->price_currency_id,$curr);
echo str_replace(array($currencyInfo[1]->currency_symbol,$currencyInfo[1]->currency_code),'',$this->currencyHelper->format(@$price->price_value_with_tax,$price->price_currency_id));
?>
</td>
<?php } ?>

But the result is "0,00 €" for all prices. Perhaps I did an obvious mistake, but I can not figure it out.

Thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
11 years 1 month ago #163823

Hi,

Xavier gave you some for the same view (same line) than the previous post : listing_price.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 44
  • Thank you received: 0
11 years 1 month ago #163865

Hi, Jerome

When I add this code to listing_price than currency code is hidden everywhere (I can achieve it, as Xavier said, setting via the menu System > Currencies ). But I want it to be hidden only in the product listing table.
If there is a simple solution, I'm gonna find it. If it's complicated I'm gonna hide currency code via the menu System > Currencies and add it where it is needed (for example CART) using language variable.

Thanks
Denis

Please Log in or Create an account to join the conversation.

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
11 years 1 month ago #163869

Hi,

So I will suggest you to make some text replacement in the view listing_table.
Instead of

$this->setLayout('listing_price');
echo $this->loadTemplate();
You can get the content and modify it, like this example:
$this->setLayout('listing_price');
$currentyData =  $this->loadTemplate();
echo str_replace('$', '', $currentyData);
Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: denoo

Please Log in or Create an account to join the conversation.

  • Posts: 44
  • Thank you received: 0
11 years 1 month ago #163933

Hi, Jerome

that's it. In my case it was "€", so I just changed it in your example. Now I know how to use str_replace in such cases, so in future I'll use it.

Thank you for your product and support.
Denis

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds
Powered by Kunena Forum