1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2016 |
6
|
|
|
* @package laravel |
7
|
|
|
* @subpackage Controller |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Controller; |
12
|
|
|
|
13
|
|
|
use Illuminate\Routing\Controller; |
14
|
|
|
use Illuminate\Support\Facades\View; |
15
|
|
|
use Illuminate\Support\Facades\Input; |
16
|
|
|
use Illuminate\Support\Facades\Route; |
17
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Controller providing the ExtJS administration interface |
22
|
|
|
* |
23
|
|
|
* @package laravel |
24
|
|
|
* @subpackage Controller |
25
|
|
|
*/ |
26
|
|
|
class AdminController extends Controller |
27
|
|
|
{ |
28
|
|
|
use AuthorizesRequests; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns the initial HTML view for the admin interface. |
33
|
|
|
* |
34
|
|
|
* @return Response Response object containing the generated output |
35
|
|
|
*/ |
36
|
|
|
public function indexAction() |
37
|
|
|
{ |
38
|
|
|
if( config( 'shop.authorize', true ) ) { |
39
|
|
|
$this->authorize( 'admin' ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$param = array( |
43
|
|
|
'resource' => 'product', |
44
|
|
|
'site' => Route::input( 'site', 'default' ), |
45
|
|
|
'lang' => Input::get( 'lang', config( 'app.locale', 'en' ) ), |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
return redirect()->action( 'Aimeos\Shop\Controller\JqadmController@searchAction', $param ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the version of the Aimeos package |
54
|
|
|
* |
55
|
|
|
* @return string Version string |
56
|
|
|
*/ |
57
|
|
|
protected function getVersion() |
58
|
|
|
{ |
59
|
|
|
if( ( $content = @file_get_contents( base_path( 'composer.lock' ) ) ) !== false |
60
|
|
|
&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] ) |
61
|
|
|
) { |
62
|
|
|
foreach( (array) $content['packages'] as $item ) |
63
|
|
|
{ |
64
|
|
|
if( $item['name'] === 'aimeos/aimeos-laravel' ) { |
65
|
|
|
return $item['version']; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return ''; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Sets the locale item in the given context |
76
|
|
|
* |
77
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
78
|
|
|
* @param string $sitecode Unique site code |
79
|
|
|
* @param string $lang ISO language code, e.g. "en" or "en_GB" |
80
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
81
|
|
|
*/ |
82
|
|
View Code Duplication |
protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode = 'default', $lang = null ) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
85
|
|
|
|
86
|
|
|
try |
87
|
|
|
{ |
88
|
|
|
$localeItem = $localeManager->bootstrap( $sitecode, '', '', false ); |
89
|
|
|
$localeItem->setLanguageId( null ); |
90
|
|
|
$localeItem->setCurrencyId( null ); |
91
|
|
|
} |
92
|
|
|
catch( \Aimeos\MShop\Locale\Exception $e ) |
93
|
|
|
{ |
94
|
|
|
$localeItem = $localeManager->createItem(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$context->setLocale( $localeItem ); |
98
|
|
|
$context->setI18n( app('\Aimeos\Shop\Base\I18n')->get( array( $lang ) ) ); |
99
|
|
|
|
100
|
|
|
return $context; |
101
|
|
|
} |
102
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.