-
Notifications
You must be signed in to change notification settings - Fork 1
/
multistore.php
53 lines (44 loc) · 1.43 KB
/
multistore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
$files = glob(__DIR__ . '/../../../app/etc/env.php.*');
if (empty($files) || empty($_SERVER['CONFIG__DEFAULT__WEB__SECURE__BASE_URL'])) {
return;
}
$validStores = ['default' => 'default*'];
foreach ($files as $file) {
$code = substr(strrchr($file, '.'), 1);
if ($code != 'production') {
$validStores[$code] = $code;
}
}
if (empty($_SERVER['MAGE_RUN_CODE'])
&& stristr($_SERVER['PHP_SELF'], 'bin/magento')
&& php_sapi_name() === 'cli'
) {
$input = readline('Select store (' . implode(', ', $validStores) . '): ');
if (!empty($validStores[$input])) {
$_SERVER['MAGE_RUN_CODE'] = $validStores[$input];
$_SERVER['MAGE_RUN_TYPE'] = 'store';
}
return;
}
if (!isset($_SERVER['REQUEST_URI'])) {
return;
}
// Determine the store view code from the URL
$requestUri = $_SERVER['REQUEST_URI'];
$paths = explode('/', ltrim($requestUri, '/'));
$pathsFiltered = array_filter($paths);
$storeCode = reset($pathsFiltered);
$storeCode = str_replace('_admin', '', $storeCode);
if (!array_key_exists($storeCode, $validStores)) {
return;
}
// Set run code and run type
$_SERVER['MAGE_RUN_CODE'] = $storeCode;
$_SERVER['MAGE_RUN_TYPE'] = 'store';
if (strstr($_SERVER['REQUEST_URI'], '_admin')) {
$newRequestUri = str_replace('/' . $storeCode . '/', '', $requestUri);
} else {
$newRequestUri = str_replace('/' . $storeCode . '/', '/', $requestUri);
}
$_SERVER['REQUEST_URI'] = $newRequestUri;