Localization Support

Localization is a very powerful and elegantly implemented feature of CSCart. However, many people will not need it so it is disabled by default.

Basically it allows your CSCart website to appear different depending on where it is being accessed from. So, for example, if your website is being accessed from Germany you will probably want to display the website in the German language, with prices in Euros, and metric measures. If it is being accessed from the USA, you will want the site to be in English, with prices in $ and non metric weights and measures. You may also have products which are only available in certain regions.

Quoting from the original CSCart documentation "A localization is a set of regional settings, including the region-specific currency, language and measures. A localization can then be used to control accessibility of products, shipping methods,credit card types, locations, etc."

My website uses localizations extensively for this purpose.

However, CSCart has quietly decided to cease supporting this valuable feature. Localizations still work and the code is still present, but localizations have been removed from the documentation and CSCart refuses to fix any bugs related to localizations.

See http://forum.cs-cart.com/topic/37523-are-you-really-planning-to-delete-localization-functionality/and http://forum.cs-cart.com/tracker/issue-5316-manual-config-shows-incorrect-shipping-destinations-for-shipping-method-localization/

I don't understand why CSCart has made this decision but if they do remove localization capability from the code base, my website and any others that depend on it will cease to work. I will be forced to branch the code base and continue developing and maintaining myself. I certainly hope I never have to do this but CSCart may give me no choice.

The localization code in CSCart is elegantly and simply implemented and therefore very reliable and flexible. However, occasionally I have come across a few minor bugs. I have reported these bugs to CSCart - often together with simple fixes for the bugs, but CSCart refuses to include the fixes in the code base.

Therefore I plan to post the fixes on this thread to help others in the same position as me.

I am posting this in the Wishlist and Feature Requests forum in the hope that CSCart will reconsider reinstating this feature - or at least will give users like myself some working alternative to localizations.

Turning On Localization Support

By default localization support is disabled.

To turn it on set the following in your configuration file - eg config.local.php

$config['tweaks']['disable_localizations'] = false;

Fix bug where disabled locations still appear in manual shipping methods.

This has been reported here: http://forum.cs-cart.com/tracker/issue-5984-disabled-locations-still-appear-in-shipping-methods/

The bug report includes the fix which involves simply commenting out a couple of lines which look like a crude hack to force the code to ignore a condition related to localizations.

Here is a copy of the relevant part of the bug report:

...the bug is in this bit of code in function fn_get_available_destination
```php $condition = '';
if (AREA == 'C') {
$condition .= fn_get_localizations_condition('localization');
if (!empty($condition)) {
$condition = db_quote('OR (1 ?p)', $condition);
}
}
$__dests = db_get_array("SELECT a.* FROM ?:destination_elements as a LEFT JOIN ?:destinations as b ON b.destination_id = a.destination_id WHERE b.status = 'A' ?p", $condition); ```

The bug fix is to remove that strange if (!empty(condition)) statement. By turning the AND into an OR it means that the WHERE b.status = 'A' clause in the SELECT is ignored if localization matches.

Fix bug in manual shipping method configuration

This has been reported here: http://forum.cs-cart.com/tracker/issue-5316-manual-config-shows-incorrect-shipping-destinations-for-shipping-method-localization/

Here is a copy of the relevant part of the bug report:

...the problem is in the fn_get_shipping_info method of fn.cart.php.

I would replace the following lines:

```php $destinations = array();
if ($shipping['rate_calculation'] == 'M') {
$destinations = fn_get_destinations();
foreach ($destinations as $k => $v) {
if (!empty($shipping['localization'])) { // check available destinations, but skip default destination
$_s = fn_explode(',', $shipping['localization']);
$_l = fn_explode(',', $v['localization']);
if (!array_intersect($_s, $_l)) {
continue;
}
}
$destinations[$k] = array_merge($destinations[$k], fn_get_shipping_rate($shipping_id, $v['destination_id']));
}
} else {
...
```

with

```php $destinations = array();
if ($shipping['rate_calculation'] == 'M') {
$alldestinations = fn_get_destinations();
foreach ($alldestinations as $k => $v) {
if (!empty($shipping['localization'])) { // check available destinations, but skip default destination
$_s = fn_explode(',', $shipping['localization']);
$_l = fn_explode(',', $v['localization']);
if (!array_intersect($_s, $_l)) {
continue;
}
}
$destinations[$k] = array_merge($alldestinations[$k], fn_get_shipping_rate($shipping_id, $v['destination_id']));
}
} else {
...
```

In other words I use the temporary variable $alldestinations and only add appropriate destinations (with matching localizations) to the $destinations variable

Hello,

I have v4.3.4 when I activate LOCALIZATIONS i cann ot go to my product pages.

Do I have to activate something else ?

Hello,

I have v4.3.4 when I activate LOCALIZATIONS i cann ot go to my product pages.
Do I have to activate something else ?

Since this functionality is not supported anymore, it can completely brake the store. It is required to examine error on your server to fix it