PHP Question

find Prestashop shop available languages within a module

Good day all.
I'm doing a Prestashop module, and actually I'm using this logic in the .tpl file:

{foreach $languages as $lang}

I'd like to move this kind of logic into the module PHP, and not into the .tpl file, because the logic is becoming a little complex and I don't like templates with logic in them.

The problem I have is that I can't find a way to get ALL the languages within a module (I'm not considering db queries at this stage, I'd switch to brutal fetch in case I didn't solve in a more smooth way).
actually, I can retrieve the actual language by using:


it's cool but isn't enough, what I need is:

  1. all the current languages of this shop

  2. all the shops

  3. all the languages of a gives shop

point 1 is the most important, but also point 2 and 3 are to be considered because I'd like to scale this solution also in multishop environments.

does anyone have a clue on whre I should start search?

does anyone can answer to point 1?

Answer Source

You can easily do it with Language class through static methods.

  1. Languages of current shop: Language::getLanguages(true, $this->context->shop->id);
  2. Languages of all shops Language::getLanguages(true);
  3. Languages of given shop Language::getLanguages(true, $whatever_shop_id);

First parameter true is to get only active languages, set to false if you need all languages. You can also specify third parameter as true if you wish to retrieve only language IDs.