knitting

Author Topic: Added display of price in alternative currency  (Read 126979 times)

djlongy

  • Jr. Member
  • **
  • Posts: 132
Added display of price in alternative currency
« on: February 15, 2006, 12:47:39 PM »
I live in a country where EURO is going to replace local currency.
But there's a period of time where price in BOTH, local and EURO currency, must be displayed.

So here's a tweak to achieve this, if you got a fixed exchange rate. But note that this customization means changing two files directly - I have not enough php programming knowledge to add some exchange rate field into vm backend. It would also mean changing database table structures and only Soeren can probably approve such a thing as it would influence on all users/developers.
So what you need to do is:
- in file shop.browse.php (/administrator/components/com_virtuemart/html/) find the following string:

$product_cell = str_replace( "{product_sku}", $db_browse->f("product_sku"), $product_cell );

it should be around line 412. After above line add the following:

$product_price_num= str_replace(".", "", $product_price);
$product_price_num= str_replace(",", ".", $product_price_num);   
$product_price_num= str_replace("SIT", "", $product_price_num);         
$eur_product_price = number_format( strip_tags($product_price_num) / 239.64,2,",",".");                  
$product_cell = str_replace( "{eur_product_price}", $eur_product_price, $product_cell );

The factor 239,64 is my exchange rate between SIT and EUR. You will put  another number here, based on your own exchange rate.

Save the file and open your browse template (usually "browse_1.php" in /administrator/components/com_virtuemart/html/templates/browse/)

at end of line containing the following:

{product_price}

add <br/> tag and put in new line:
{eur_product_price} EUR

Save file and that's it. If you want, you can change text "EUR" to some other currency.

All this will display EUR price under usual price on product browse page.

Hope I helped someone with this.

Bostjan

UrKo

  • Beginner
  • *
  • Posts: 10
Re: Added display of price in alternative currency
« Reply #1 on: April 10, 2006, 09:39:38 AM »
Hi Bostjan....

Is it also possible to add same thing on product.detal page and at random records??

Thanks,

samsa

  • Beginner
  • *
  • Posts: 3
Re: Added display of price in alternative currency
« Reply #2 on: April 16, 2006, 11:36:59 AM »
Hi Bostjan.

this don't work for me.

Show 0,00 EUR for all products

Can you help me? please, thanks

samsa

  • Beginner
  • *
  • Posts: 3
Re: Added display of price in alternative currency
« Reply #3 on: April 16, 2006, 14:49:53 PM »
I fix my error.   
   
it was the currency symbol.

Thanks


djlongy

  • Jr. Member
  • **
  • Posts: 132
Re: Added display of price in alternative currency
« Reply #4 on: April 18, 2006, 03:13:20 AM »
Hi Bostjan....

Is it also possible to add same thing on product.detal page and at random records??

Thanks,

Yes, it's possible, I just haven't had time to do it yet. You need it?

samsa

  • Beginner
  • *
  • Posts: 3
Re: Added display of price in alternative currency
« Reply #5 on: April 18, 2006, 18:53:30 PM »
some of you knows if the possibility exists of having 2 currency, alternately, to the way that has it osCommerce

djlongy

  • Jr. Member
  • **
  • Posts: 132
Re: Added display of price in alternative currency
« Reply #6 on: April 19, 2006, 06:22:41 AM »
 VM has no such thing by default, only modification of source code helps. How OSCommerce has it I cannot tell as I've never used it.

UrKo

  • Beginner
  • *
  • Posts: 10
Re: Added display of price in alternative currency
« Reply #7 on: April 19, 2006, 11:29:30 AM »
I would need the code for show EUR prices in random records and detail page.
So if you will decide to write it here would be great  :)

djlongy

  • Jr. Member
  • **
  • Posts: 132
Re: Added display of price in alternative currency
« Reply #8 on: April 19, 2006, 13:49:22 PM »
Ok, here's how it goes:

you need to modify shop.product_details.php (same location as shop.browse.php...). Find /** PRODUCT PRICE **/ section and few lines lower you'll find:
      $product_price .= $ps_product->show_price( $product_id );
after this line add:

 //*EURmod1*//     
      $product_price_num= str_replace(".", "", $product_price);
      $product_price_num= str_replace("Cena:", "", $product_price_num);
      $product_price_num= str_replace(",", ".", $product_price_num);   
      $product_price_num= str_replace("SIT", "", $product_price_num);             
      $eur_product_price = number_format( strip_tags($product_price_num) / 239.64,2,",",".");                 
//**EURmod1**// 

then on the end of this same file find line /** NOW LET'S BEGIN AND FILL THE TEMPLATE **/.
after the last "$template =..." line add this:

//***EURmod2***/
$template = str_replace( "{eur_product_price}", $eur_product_price, $template ); // EUR PRICE
//***EURmod2***/

then open flypage.php (if that's you're using the usual flypage for product details) and find this line:
   <td width="33%" valign="top" align="left">{product_price}<br /></td>

and modify it so it looks like this
   <td width="33%" valign="top" align="left">{product_price}<br />
                                                                 {eur_product_price} EUR<br/></td>

and that's it.

But beware(!): it will only work if you're using SIT as currency and slovenian language pack because of the string "Cena:" in the price (whole price is formed as "Cena: xxx.xxx,xx SIT" and that's the string I'm deformating to get to the number itself for conversion to EUR)

All the rest, non-slovenian people replace currency and "Price:" word with your own...

More info: bostjanATtsc-laba.si (AT = @)

Hope I helped.

Ryan

  • Beginner
  • *
  • Posts: 3
Re: Added display of price in alternative currency
« Reply #9 on: April 24, 2006, 06:08:30 AM »
Cool hack, will probably make use of it to show values in GBP and EUR in my shop.

Wish we'd bite the bullet and join the EURO zone, though the banks here won't exactly be for it - they make a LOT of money from us having a seperate currency..

diver

  • Beginner
  • *
  • Posts: 5
Re: Added display of price in alternative currency
« Reply #10 on: April 25, 2006, 02:59:18 AM »
Hi Bostjan.

this don't work for me.

Show 0,00 EUR for all products in page product detail.
What is exchange rate? My curency - australian dollar.

Can you help me? please, thanks

djlongy

  • Jr. Member
  • **
  • Posts: 132
Re: Added display of price in alternative currency
« Reply #11 on: April 25, 2006, 17:10:19 PM »
Hey,

check how your price is displayed (=format). Mine looks like:

Cena: 150.000,00 SIT

If you examine the //*EURmod1*// part of the code you will see that what is done is (line by line):
- remove thousand separator (".")
- remove "Price:" word ("Cena:")
- replace decimal comma with decimal dot ("," -> ".")
- remove currency sign
- extract plain number (unformatted), divide by exchange rate (239,64) and format the result so it will look like:
xxx.xxx,xx

In short: in order to achieve php to be able to divide the main price with some exchange rate you need to totally deformat whole "Price: xxx.xxx,xx AUD" (for example, I'm not sure this is your actual price display) into plain number: xxxxxx.xx

That in my opinion is the only thing causing this hack not to work for you. So if you won't be able to properly modify code, just give me URL of your site and I'll tell you what to change in the code so it'll work for you...

Cheers

UrKo

  • Beginner
  • *
  • Posts: 10
Re: Added display of price in alternative currency
« Reply #12 on: April 25, 2006, 22:31:34 PM »
Is it also posible to put two currencies in random product display??' This would be also great  ;D

djlongy

  • Jr. Member
  • **
  • Posts: 132
Re: Added display of price in alternative currency
« Reply #13 on: April 26, 2006, 02:19:06 AM »
Diver, I had some problems with your site displaying details but here's what I think should work for you. The assumption is that your price is listed like this: "Price: 100,000.00 AU$"

 //*EURmod1*//     
      $product_price_num= str_replace(",", "", $product_price);
      $product_price_num= str_replace("Price:", "", $product_price_num);
      $product_price_num= str_replace("AU$", "", $product_price_num);             
      $eur_product_price = number_format( strip_tags($product_price_num) / 239.64,2,".",",");                 
//**EURmod1**// 

Instead of 239.64 in the last line enter YOUR exchange rate between AU$ and EUR. Ah, and answer to your question "what is exchange rate": in my case 1 EUR = 239.64 SIT, so 239.64 is the exchange rate. In your case it means HOW MUCH AU$ is 1 EUR. That's the rate.

Let me know how it goes.

djlongy

  • Jr. Member
  • **
  • Posts: 132
Re: Added display of price in alternative currency
« Reply #14 on: April 26, 2006, 02:20:32 AM »
Is it also posible to put two currencies in random product display??' This would be also great  ;D

Hey, I agree  ;D However, I don't use random product display myself...but I'll try and see if I can do this.

VirtueMart Forum

Re: Added display of price in alternative currency
« Reply #14 on: April 26, 2006, 02:20:32 AM »