Thursday, December 24, 2009

Websitecode, currency, language (for sonician)

Problem:
get through code the current values for website, currency and language.
Hello,
Website:
//for name
Mage::app()->getWebsite()->getName();
//for code
Mage::app()->getWebsite()->getCode();
Currency:
Mage::app()->getStore()->getCurrentCurrencyCode();
Language:
This is a little tricky. You can get the ISO code for the language, because by standards French for France is different from French for Belgium
Mage::app()->getLocale()->getLocale();//will return something like fr_FR, fr_BE or en_US
if you want to go further and see only the language code it's simple
$isoCode = Mage::app()->getLocale()->getLocale();
$parts = explode("_", $isoCode);
$language = $parts[0];
$country = $parts[1];

5 comments:

  1. BTW, you haven't happened to look into switching language and currency when having multiple websitecodes in Magento?

    I wonder if there's a way to include the store-view name, and preferrably even a currency-selection, when doing a websitecode-switch in index.php, like :

    [code]switch($_SERVER['HTTP_HOST']){
    case 'website1.com':
    Mage::run('website1,'website');
    break;
    case 'website2.com':
    Mage::run('website2,'website');
    }
    [/code]

    The wiki on http://www.magentocommerce.com/wiki/how-to/how_to_automatically_redirect_to_a_store_view_based_on_the_browser_language

    uses the web-browser settings rather than the IP-address lookup. But the main problem is that it's for a one-website shop only, and not for when you have multiple URLs, too. (Unless I've missed something)

    Unfortunately, the server doesn't allow doing a htaccess redirect based on http://www.maxmind.com/app/mod_geoip, so I would need to, like the wiki-post, do something with index.php (either by using the wiki-post or http://www.maxmind.com/app/php preferrably).

    ReplyDelete
  2. Oh, sorry, I just realized that was quite rude posting to you instead of posting to the Magento-forum directly! Sorry, it was just that I was so helped by you the last time.

    Never mind my post (unless you perhaps know it from the top of your head), and it's absolutely OK to not approve it, either! I'll post it to Magento under Programming Questions instead.

    ReplyDelete
  3. I will approve any comments that are not offensive, so anyone can post whatever they want.

    ReplyDelete
  4. hay i see your post about magento.see my magento forum also at http://magentoforum.blogspot.com .send me your suggestion to improve my blog

    ReplyDelete