Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2006
    Location
    Melbourne, VIC
    Posts
    106
    Plugin Contributions
    0

    Where is the Currency Conversion Function?

    Hi,

    I need to do a currency conversion from AUD$ to the default currency set up in ZC.

    This is because the Australian Post postage calculator always returns the postage cost in Aussie dollars.

    What I need to do is convert this to whatever the ZC default currency is set to immediately after it is retrieved from the postage calculator.

    What I'm looking for is the currency converter function of the form:

    value = currency_convert(from, to, amount);
    i.e.
    value = currency_convert(AUD,DEFAULT_CURRENCY, postage cost);


    BTW I'm not a php programmer but if someone can point me to where the function is, I can probably fumble my way through it.

    The initial problem I am trying to solve is detailed in a thread in the contrib-> shipping modules area.

    Thanks,

    Peter.

  2. #2
    Join Date
    Feb 2006
    Location
    Chicago
    Posts
    1,162
    Plugin Contributions
    0

    Default Re: Where is the Currency Conversion Function?

    Will going to Admin->Localization->Currencies wont help?
    Please let us know

  3. #3
    Join Date
    Jun 2006
    Location
    Melbourne, VIC
    Posts
    106
    Plugin Contributions
    0

    Default Re: Where is the Currency Conversion Function?

    Hi,

    Thanks for the reply. No going to Admin->Localization->Currencies in this case won't.

    The problem is that I have my default currency set to USD. This is because all my products prices are set on US prices, as most of my customers are in the US.

    Since the default currency is USD, one can still display prices in AUD or any other currency. Regardless of the displayed currency currency, ZC does is internal calculations in it's default currency. (I presume)

    The problem is that the Australia Post postage calculator returns the cost of the postage in AUD. That is, a 0.25Kg package to the US by airmail is AUD8.50. The calculator returns 8.50. As the ZC default currency is USD it interperates this as USD8.50

    If I have the displayed currency as AUD, the postage is displayed as AUD$13.60

    What I need to do is convert the value returned from the Australia Post calculator to the ZC default currency as soon as it is returned.

    so, if the default currency is USD, I need to convert the 8.50 returned from the calculator to 6.80, the USD equivulant of AUD 8.50


    If I can find out what the function and variables are for performing the conversion I can probably do it myself.

    Cheers,

    Peter.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Where is the Currency Conversion Function?

    This should convert $amount_from_shipping_module into the equivalent amount ($value) matching the customer's selected currency:
    PHP Code:
    global $currencies;
    $value $currencies->value($amount_from_shipping_module); 
    or you might try this, if the above doesn't work:
    PHP Code:
    global $currencies;
    $value $currencies->value($amount_from_shipping_moduletrue'AUD'); 
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jun 2006
    Location
    Melbourne, VIC
    Posts
    106
    Plugin Contributions
    0

    Default Re: Where is the Currency Conversion Function?

    Hi,

    Thanks for the reply.

    This problem is to do with converting the data from the Australia Post calculator with is always returned in AUD to whatever the delault currency is set to by the Admin menu.

    It has nothing to do with what currency the customer has selected to display in.

    I have set my default (base) curreny to USD. I cannot add a postage cost to to the tolat cost without converting it to my default curreny first. Once that is done the customer can view it in any currency they like.

    To show the point, below is a code snippet from line 126 in auspostair.php.

    Code:
     'cost' => ($shipping_auspostair_cost + MODULE_SHIPPING_AUSPOSTAIR_HANDLING) + $insurance)));
    $shipping_auspostair_cost is returned from the Australia Post calculator. It is in AUD.

    $insurance and MODULE_SHIPPING_AUSPOSTAIR_HANDLING are in the ZC default curreny I set, i.e. USD

    As I was taught in primary school, "You can't add apples and oranges". It is stange that no one has picked this up before.

    Anyhow, this morning I managed to fumble through php and work it out.

    What I've done is replaced line 112 where $charge is the value returned by the Australian Post calculator;

    Code:
            $shipping_auspostair_cost = $charge;
    with;

    Code:
    global $currencies;
    
    //        $shipping_auspostair_cost = $charge;
    
    // Change the value returned by the calculator to the default currency.        
            $aus_rate = $currencies->get_value(AUD);
            $shipping_auspostair_cost = $charge/$aus_rate;
    I'm not too sure how "PHP correct" correct what I have done is but it works. It should work no matter what the default currency is.

    At the moment the Australia Post shipping module only works if the default currency is AUD. I presume that this problem also occurs with the Canadian Shipping module, the UPS shipping module as well.

    I cannot believe that this issue has not come up before. It is a problem that will occur whenever an external calculator is called that returns a value that is not in the default currency.

    Anyhow I managed to solve it myself, albeit a lot of unproductive effort was required.

    Cheers,

    Peter.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Where is the Currency Conversion Function?

    Your code will work.

    $currencies->value($amount) ... does the same thing.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Jun 2006
    Location
    Melbourne, VIC
    Posts
    106
    Plugin Contributions
    0

    Default Re: Where is the Currency Conversion Function?

    Hi,

    Told you I was a php dummy.

    Cheers,

    Peter.

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Where is the Currency Conversion Function?

    No worries! Just look at how much you learned in the process!
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Currency conversion
    By Euonym in forum General Questions
    Replies: 21
    Last Post: 25 Oct 2010, 09:56 PM
  2. I cannot change the currency conversion rate
    By breadfan in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 5
    Last Post: 20 Jul 2008, 05:58 AM
  3. Currency Conversion updates
    By bedfordcomputers in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 2
    Last Post: 10 Nov 2006, 01:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR