|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Globally useful tools |
|
5
|
|
|
*/ |
|
6
|
|
|
class ShopTools |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Get the DB connection in a SS 3.1 and 3.2+ compatible way |
|
10
|
|
|
* @param string $name |
|
11
|
|
|
* @return SS_Database |
|
12
|
|
|
*/ |
|
13
|
8 |
|
public static function DBConn($name = 'default') |
|
14
|
|
|
{ |
|
15
|
8 |
|
if (method_exists('DB', 'get_conn')) { |
|
16
|
8 |
|
return DB::get_conn($name); |
|
17
|
|
|
} |
|
18
|
|
|
return DB::getConn($name); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public static function price_for_display($price) |
|
22
|
|
|
{ |
|
23
|
|
|
$currency = ShopConfig::get_site_currency(); |
|
24
|
|
|
$field = Money::create("Price"); |
|
25
|
|
|
$field->setAmount($price); |
|
26
|
|
|
$field->setCurrency($currency); |
|
27
|
|
|
return $field; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
87 |
|
public static function get_current_locale() |
|
31
|
|
|
{ |
|
32
|
87 |
|
if (class_exists('Translatable')) { |
|
33
|
|
|
return Translatable::get_current_locale(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
87 |
|
if (class_exists('Fluent')) { |
|
37
|
|
|
return Fluent::current_locale(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
87 |
|
return i18n::get_locale(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
4 |
|
public static function install_locale($locale) |
|
44
|
|
|
{ |
|
45
|
|
|
// If the locale isn't given, silently fail (there might be carts that still have locale set to null) |
|
46
|
4 |
|
if (empty($locale)) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
if (class_exists('Translatable')) { |
|
51
|
|
|
Translatable::set_current_locale($locale); |
|
52
|
|
|
} else { |
|
53
|
4 |
|
if (class_exists('Fluent')) { |
|
54
|
|
|
Fluent::set_persist_locale($locale); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
// Do something like Fluent does to install the locale |
|
59
|
4 |
|
i18n::set_locale($locale); |
|
60
|
|
|
|
|
61
|
|
|
// LC_NUMERIC causes SQL errors for some locales (comma as decimal indicator) so skip |
|
62
|
4 |
|
foreach (array(LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_TIME) as $category) { |
|
63
|
4 |
|
setlocale($category, "{$locale}.UTF-8", $locale); |
|
64
|
4 |
|
} |
|
65
|
|
|
// Get date/time formats from Zend |
|
66
|
4 |
|
require_once 'Zend/Date.php'; |
|
67
|
4 |
|
i18n::config()->date_format = Zend_Locale_Format::getDateFormat($locale); |
|
68
|
4 |
|
i18n::config()->time_format = Zend_Locale_Format::getTimeFormat($locale); |
|
69
|
4 |
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.