Skip to content

Commit a509e53

Browse files
committed
Merge branch 'develop'
2 parents 7ba153e + ee95537 commit a509e53

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

controllers/front/lightbootstrap.php

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
require_once dirname(__FILE__) . '/../../classes/RESTMainMenu.php';
1414
require_once dirname(__FILE__) . '/../../classes/RESTProductLazyArray.php';
1515

16-
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
17-
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
18-
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
19-
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
16+
use PrestaShop\PrestaShop\Adapter\ObjectPresenter;
2017

2118
/**
2219
* Description: This class bootstraps the main page of the application
@@ -59,8 +56,13 @@ protected function processGetRequest()
5956
}
6057
}
6158

59+
$id_shop = (int) $this->context->shop->id;
60+
6261
$psdata = array();
6362
$psdata['menuItems'] = $menuItems;
63+
$psdata['currencies'] = $this->getCurrencies();
64+
$psdata['languages'] = $this->getLanguages();
65+
$psdata['logo_url'] = Tools::getHttpHost(true) . _PS_IMG_ .Configuration::get('PS_LOGO', null, null, $id_shop);
6466

6567
$this->ajaxRender(json_encode([
6668
'success' => true,
@@ -96,4 +98,80 @@ protected function processDeleteRequest()
9698
]));
9799
die;
98100
}
101+
102+
protected function getCurrencies(){
103+
$current_currency = null;
104+
$serializer = new ObjectPresenter();
105+
$currencies = array_map(
106+
function ($currency) use ($serializer, &$current_currency) {
107+
$currencyArray = $serializer->present($currency);
108+
109+
// serializer doesn't see 'sign' because it is not a regular
110+
// ObjectModel field.
111+
$currencyArray['sign'] = $currency->sign;
112+
113+
$url = $this->context->link->getLanguageLink($this->context->language->id);
114+
115+
$parsedUrl = parse_url($url);
116+
$urlParams = [];
117+
if (isset($parsedUrl['query'])) {
118+
parse_str($parsedUrl['query'], $urlParams);
119+
}
120+
$newParams = array_merge(
121+
$urlParams,
122+
[
123+
'SubmitCurrency' => 1,
124+
'id_currency' => $currency->id,
125+
]
126+
);
127+
$newUrl = sprintf('%s://%s%s%s?%s',
128+
$parsedUrl['scheme'],
129+
$parsedUrl['host'],
130+
isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '',
131+
$parsedUrl['path'],
132+
http_build_query($newParams)
133+
);
134+
135+
$currencyArray['url'] = $newUrl;
136+
137+
if ($currency->id === $this->context->currency->id) {
138+
$currencyArray['current'] = true;
139+
$current_currency = $currencyArray;
140+
} else {
141+
$currencyArray['current'] = false;
142+
}
143+
144+
return $currencyArray;
145+
},
146+
Currency::getCurrencies(true, true)
147+
);
148+
149+
return [
150+
'currencies' => $currencies,
151+
'current_currency' => $current_currency,
152+
];
153+
}
154+
155+
protected function getLanguages(){
156+
$languages = Language::getLanguages(true, $this->context->shop->id);
157+
158+
foreach ($languages as &$lang) {
159+
$lang['name_simple'] = $this->getNameSimple($lang['name']);
160+
}
161+
162+
return array(
163+
'languages' => $languages,
164+
'current_language' => array(
165+
'id_lang' => $this->context->language->id,
166+
'name' => $this->context->language->name,
167+
'name_simple' => $this->getNameSimple($this->context->language->name),
168+
'iso_code' => $this->context->language->iso_code
169+
)
170+
);
171+
}
172+
173+
private function getNameSimple($name)
174+
{
175+
return preg_replace('/\s\(.*\)$/', '', $name);
176+
}
99177
}

0 commit comments

Comments
 (0)