|
13 | 13 | require_once dirname(__FILE__) . '/../../classes/RESTMainMenu.php';
|
14 | 14 | require_once dirname(__FILE__) . '/../../classes/RESTProductLazyArray.php';
|
15 | 15 |
|
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; |
20 | 17 |
|
21 | 18 | /**
|
22 | 19 | * Description: This class bootstraps the main page of the application
|
@@ -59,8 +56,13 @@ protected function processGetRequest()
|
59 | 56 | }
|
60 | 57 | }
|
61 | 58 |
|
| 59 | + $id_shop = (int) $this->context->shop->id; |
| 60 | + |
62 | 61 | $psdata = array();
|
63 | 62 | $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); |
64 | 66 |
|
65 | 67 | $this->ajaxRender(json_encode([
|
66 | 68 | 'success' => true,
|
@@ -96,4 +98,80 @@ protected function processDeleteRequest()
|
96 | 98 | ]));
|
97 | 99 | die;
|
98 | 100 | }
|
| 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 | + } |
99 | 177 | }
|
0 commit comments