|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
|
6
|
|
|
* @package flow |
|
7
|
|
|
* @subpackage Base |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Base; |
|
12
|
|
|
|
|
13
|
|
|
use Neos\Flow\Annotations as Flow; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class providing the context object |
|
18
|
|
|
* |
|
19
|
|
|
* @package flow |
|
20
|
|
|
* @subpackage Base |
|
21
|
|
|
* @Flow\Scope("singleton") |
|
22
|
|
|
*/ |
|
23
|
|
|
class Locale |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var \Aimeos\MShop\Locale\Item\Iface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $locale; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private $settings; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns the locale item for the current request |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
|
40
|
|
|
* @param \Neos\Flow\Mvc\RequestInterface $request Request object |
|
41
|
|
|
* @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
|
42
|
|
|
*/ |
|
43
|
|
|
public function get( \Aimeos\MShop\Context\Item\Iface $context, \Neos\Flow\Mvc\RequestInterface $request ) |
|
44
|
|
|
{ |
|
45
|
|
|
if( $this->locale === null ) |
|
46
|
|
|
{ |
|
47
|
|
|
$params = $request->getArguments(); |
|
48
|
|
|
|
|
49
|
|
|
$site = ( isset( $params['site'] ) ? $params['site'] : 'default' ); |
|
50
|
|
|
$lang = ( isset( $params['locale'] ) ? $params['locale'] : '' ); |
|
51
|
|
|
$currency = ( isset( $params['currency'] ) ? $params['currency'] : '' ); |
|
52
|
|
|
|
|
53
|
|
|
$disableSites = (bool) ( isset( $this->settings['flow']['disableSites'] ) ? $this->settings['flow']['disableSites'] : true ); |
|
54
|
|
|
|
|
55
|
|
|
$localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
|
56
|
|
|
$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites ); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $this->locale; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the locale item for the current request |
|
65
|
|
|
* |
|
66
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
|
67
|
|
|
* @param string $site Unique site code |
|
68
|
|
|
* @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getBackend( \Aimeos\MShop\Context\Item\Iface $context, $site ) |
|
71
|
|
|
{ |
|
72
|
|
|
$localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
|
73
|
|
|
|
|
74
|
|
|
try { |
|
75
|
|
|
$localeItem = $localeManager->bootstrap( $site, '', '', false, null, true ); |
|
76
|
|
|
} catch( \Aimeos\MShop\Exception $e ) { |
|
77
|
|
|
$localeItem = $localeManager->createItem(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $localeItem->setCurrencyId( null )->setLanguageId( null ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Inject the settings |
|
86
|
|
|
* |
|
87
|
|
|
* @param array $settings |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
public function injectSettings( array $settings ) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->settings = $settings; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|