Localization can be defined as a set of entities (such as Languages and Translations, Currencies, Countries, Taxes, etc.) which are related to a customer’s geographical area.
A special Localization tab located in the back office helps administer these parameters.
This menu section contains the following sub-sections:
1. Localization
This section is responsible for setting default parameters:
Importing entities to a certain country
Setting default configurations for the current store
Setting default localizations for the current store
Setting additional configurations
2. Languages
This section helps install different language versions on a website.
Creating/editing a language version for a magazine
Class-Model: Language (classes/Language.php)
3. Zones
This one is responsible for managing geographical zones:
Class-Model: Zone (classes/Zone.php)
4. Countries
Managing available countries:
Class-Model: Country (classes/Country.php)
5. States
Managing states/regions of a certain country:
Class-Model: State (classes/State.php)
6. Currencies
Managing available store currencies:
Class-Model: Currency (classes/Currency.php)
7. Translations
Managing translations into other available languages:
The sections Taxes and Tax Rules are described in the article “Cart in Prestаshоp”.
Initializing localizations
You can get the current localization by using the method Context::getContext(). The properties of this class are set in the file config/ config.inc.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
$context = Context::getContext(); /* Initialize the current Shop */ $context->shop = Shop::initialize(); /* Loading default country */ $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); $context->country = $defaultCountry; /* Instantiate cookie */ $cookie_lifetime = (int)(defined('_PS_ADMIN_DIR_') ? Configuration::get('PS_COOKIE_LIFETIME_BO') : Configuration::get('PS_COOKIE_LIFETIME_FO')); $cookie_lifetime = time() + (max($cookie_lifetime, 1) * 3600); if (defined('_PS_ADMIN_DIR_')) $cookie = new Cookie('psAdmin', '', $cookie_lifetime); else { if ($context->shop->getGroup()->share_order) $cookie = new Cookie('ps-sg'.$context->shop->getGroup()->id, '', $cookie_lifetime, $context->shop->getUrlsSharedCart()); else { $domains = null; if ($context->shop->domain != $context->shop->domain_ssl) $domains = array($context->shop->domain_ssl, $context->shop->domain); $cookie = new Cookie('ps-s'.$context->shop->id, '', $cookie_lifetime, $domains); } } $context->cookie = $cookie; /* Create employee if in BO, customer else */ if (defined('_PS_ADMIN_DIR_')) { $employee = new Employee($cookie->id_employee); $context->employee = $employee; /* Auth on shops are recached after employee assignation */ if ($employee->id_profile != _PS_ADMIN_PROFILE_) Shop::cacheShops(true); $cookie->id_lang = (int)$employee->id_lang; } /* if the language stored in the cookie is not available language, use default language */ if (isset($cookie->id_lang) && $cookie->id_lang) $language = new Language($cookie->id_lang); if (!isset($language) || !Validate::isLoadedObject($language)) $language = new Language(Configuration::get('PS_LANG_DEFAULT')); $context->language = $language; /* Link should also be initialized in the context here for retrocompatibility */ $https_link = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://'; $context->link = new Link($https_link, $https_link); |
Using localizations
A static method is used here to get localizations in modules or other customizations there is used Contex::getContex(). For example:
- Context::getContext()->country //get customer’s current country model
- Context::getContext()->currency //get customer’s current currency model
- Context::getContext()->language //get customer’s current language model
Maria,
By default, all users get into the guest group. And for this group, you can create settings.
Hi, I just stumbled upon your blog and I find it very educational, thanks for all the effort you’re putting into this
I have this (maybe) weird question: I know how to show prices with or without taxes depending on the kind of user (guest, visitor, client). But is it possible to show prices or not depending on the LANGUAGE the user is viewing the site in?
Most users don’t log in at first (so we don’t know where they come from, and therefore, we cannot apply tax rules), and are seeing prices with taxes when it shouldn’t be like this