2

I want to make "open" field in Opencart 3 store setting multilingual.

In the admin\view\template\setting\setting.twig. I have found these lines:

<div class="form-group">
    <label class="col-sm-2 control-label" for="input-open"><span data-toggle="tooltip" data-container="#tab-general" title="{{ help_open }}"> {{ entry_open }}</span></label>
    <div class="col-sm-10">
      <textarea name="config_open" rows="5" placeholder="{{ entry_open }}" id="input-open" class="form-control">{{ config_open }}</textarea>
    </div>
</div>

I have made from textarea - input and add {% for language in languages %}, language flags, and language ID.

{% for language in languages %}
<div class="form-group">
    <label class="col-sm-2 control-label" for="input-open{{ language.language_id }}"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /><span data-toggle="tooltip" data-container="#tab-general" title="{{ help_open }}"> {{ entry_open }}</span></label>
    <div class="col-sm-10">
        <input type="text" name="config_open[{{ language.language_id }}][title]" placeholder="{{ entry_open }}" id="input-open{{ language.language_id }}" value="{{ config_open[language.language_id] ? config_open[language.language_id].title }}" class="form-control" />
    </div>
</div>
{% endfor %}

After this, in the store settings, I have "open" field in the two languages. And the information in these fields is now stored.

In the front end controller, I have made this.

$data['open'] = nl2br($this->config->get('config_open'));

When was one language all is work but now I have an error:

Warning: nl2br() expects parameter 1 to be string, array given in /var/www/fastuser/data/www/localstite.loc/storage/modification/catalog/controller/common/header.php on line 81
F. Müller
  • 3,969
  • 8
  • 38
  • 49
Alines
  • 37
  • 6

1 Answers1

2

EDITED...

Coresponding controller file must contain this code:

$this->load->model('localisation/language');
    $languages = $this->model_localisation_language->getLanguages();
        
            foreach ($languages as $language) {
                if (isset($this->request->post[config_open' . $language['language_id']])) {
                    $data['config_open'][$language['language_id']] = $this->request->post['config_open' . $language['language_id']];
                } else {
                    $data['config_open'][$language['language_id']] = $this->config->get('config_open' . $language['language_id']);
                }   
            }

line:

 <input type="text" name="config_open[{{ language.language_id }}][title]" placeholder="{{ entry_open }}" id="input-open{{ language.language_id }}" value="{{ config_open[language.language_id] ? config_open[language.language_id].title }}" class="form-control" />

replace with:

 <input type="text" name="config_open{{ language.language_id }}" placeholder="{{ entry_open }}" id="input-open{{ language.language_id }}" value="{% if config_open[language.language_id] %}{{ config_open[language.language_id] }}{% endif %}" class="form-control" />

and front end line:

$data['open'] = nl2br($this->config->get('config_open'));

replace with:

$data['open'] = nl2br($this->config->get('config_open' . $this->config->get('config_language_id')));
K. B.
  • 1,388
  • 2
  • 13
  • 25
  • Its done. Now I have an error in the admin panel in the "open" field: `Notice: Array to string conversion in /var/www/fastuser/data/www/localsite.loc/system/library/template/Twig/Environment.php(403) : eval()'d code on line 443Array`. In the frontend nothing. Without any errors. And my information is empty too. – Alines Jul 14 '20 at 13:33
  • After you edited your files you must refresh modifications and clear cache in admin dashboard. And if the error doesn’t go away, it means you missed something. – K. B. Jul 14 '20 at 14:06
  • I have done this. I think mistake in ``. Because I still have this error `Notice: Array to string conversion in /var/www/fastuser/data/www/localsite.loc/system/library/template/Twig/Environment.php(403) : eval()'d code on line 443Array` – Alines Jul 14 '20 at 14:13
  • I have edited my answer. Check your corresponding admin controller file. Does this file contains that code which is placed in may edited answer. – K. B. Jul 14 '20 at 17:50
  • When I add your code in the admin controller file I have an error in the browser: `HTTP ERROR 500`. Your code based on the this string `$languages = $this->model_localisation_language->getLanguages();`. I have found in this controller file string like your `$data['languages'] = $this->model_localisation_language->getLanguages();`. I have `HTTP ERROR 500` with this string only `$languages = $this->model_localisation_language->getLanguages();` Maybe we need to do it somehow differently? – Alines Jul 14 '20 at 19:09
  • add this string `$this->load->model('localisation/language');` before `$languages = $this->model_localisation_language->getLanguages();` – K. B. Jul 14 '20 at 19:19
  • I dont know what happened, but I add all your code without controller. And now I see on the website my infromation from this field. But in the admin panel these fields are empty. When I enter information in these fields on both languages and save, information updated on the website fronted, but in admin panel I see only placeholder, without my text. – Alines Jul 14 '20 at 19:20