1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||
5 | * @copyright Aimeos (aimeos.org), 2016 |
||
6 | * @package laravel |
||
7 | * @subpackage Base |
||
8 | */ |
||
9 | |||
10 | namespace Aimeos\Shop\Base; |
||
11 | |||
12 | |||
13 | use Illuminate\Support\Facades\Request; |
||
14 | use Illuminate\Support\Facades\Route; |
||
15 | |||
16 | |||
17 | /** |
||
18 | * Service providing the context objects |
||
19 | * |
||
20 | * @package laravel |
||
21 | * @subpackage Base |
||
22 | */ |
||
23 | class Locale |
||
24 | { |
||
25 | /** |
||
26 | * @var \Illuminate\Contracts\Config\Repository |
||
27 | */ |
||
28 | private $config; |
||
29 | |||
30 | /** |
||
31 | * @var \Aimeos\MShop\Locale\Item\Iface |
||
32 | */ |
||
33 | private $locale; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Initializes the object |
||
38 | * |
||
39 | * @param \Illuminate\Contracts\Config\Repository $config Configuration object |
||
40 | */ |
||
41 | public function __construct( \Illuminate\Contracts\Config\Repository $config ) |
||
42 | { |
||
43 | $this->config = $config; |
||
44 | } |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Returns the locale item for the current request |
||
49 | * |
||
50 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
51 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||
52 | */ |
||
53 | public function get( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Locale\Item\Iface |
||
54 | { |
||
55 | if( $this->locale === null ) |
||
56 | { |
||
57 | $site = Request::get( 'site', 'default' ); |
||
58 | $currency = Request::get( 'currency', '' ); |
||
59 | $lang = Request::get( 'locale', '' ); |
||
60 | |||
61 | if( Route::current() ) |
||
62 | { |
||
63 | $site = Route::input( 'site', $site ); |
||
64 | $currency = Route::input( 'currency', $currency ); |
||
65 | $lang = Route::input( 'locale', $lang ); |
||
66 | } |
||
67 | |||
68 | $localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
||
69 | $disableSites = $this->config->get( 'shop.disableSites', true ); |
||
70 | |||
71 | $this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites ); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
72 | } |
||
73 | |||
74 | return $this->locale; |
||
75 | } |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Returns the locale item for the current request |
||
80 | * |
||
81 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
82 | * @param string $site Unique site code |
||
83 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||
84 | */ |
||
85 | public function getBackend( \Aimeos\MShop\Context\Item\Iface $context, string $site ) : \Aimeos\MShop\Locale\Item\Iface |
||
86 | { |
||
87 | $localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
||
88 | |||
89 | try { |
||
90 | $localeItem = $localeManager->bootstrap( $site, '', '', false, null, true ); |
||
91 | } catch( \Aimeos\MShop\Exception $e ) { |
||
92 | $localeItem = $localeManager->createItem(); |
||
93 | } |
||
94 | |||
95 | return $localeItem->setCurrencyId( null )->setLanguageId( null ); |
||
96 | } |
||
97 | } |
||
98 |