Jump to content

Import different languages from DB


Harmen
 Share

Recommended Posts

Hey all,

For my website I had to make a connection with an external DB. In that DB there are categories of products in different languages, and I want to import these categories in the languages that are available in processwire, I can do that with a very long code but I want to make it shorter. So I wrote a function to get the categories, but the different languages of the category names not, only if I insert the ISO-code hard-code. So here is my code:

protected function get_category()
	{   $languages = wire("languages");
		try {
			$prestashp = $this->get_dbPrestashop();
			foreach($languages as $language) 
				{
					$iso_code= $language->name ;
							
						$categories = $prestashp->query(
							"SELECT l.id_lang, l.iso_code, cl.description, cl.name AS category_title, cl.id_shop, c.active, c.id_category, c.id_parent, c.position, cl.link_rewrite
							FROM ps_category c
							INNER JOIN ps_category_lang cl
							ON c.id_category=cl.id_category
							LEFT JOIN ps_lang l
							ON cl.id_lang=l.id_lang
							WHERE c.active='1'
							AND cl.id_shop='1'
							AND c.id_parent = '2'
							ORDER BY c.position
							");
				}
		}catch(Exception $e) {
			$this->message('Failed to show categories. Try again later.');

			return false;

		}
		return $categories;
	}

 

So in the DB there is Deutsch, Dutch, English(default), Spanish, Italian. And when I edit the template the different languages of the category names need to be imported in the right tab of the field.  52a3549a8adaed2d5f44cac6dfb6d9d3.png
https://gyazo.com/52a3549a8adaed2d5f44cac6dfb6d9d3 As you can see, there are language tabs above the field, and the names of the category in that language need to be insterted there. 

Anyone have an idea how I can fix this?

Link to comment
Share on other sites

3 hours ago, Harmen said:

I'm not really used to hooks, maybe there is another option?

I don't think @Zeka was saying you have to use hooks - I think he was showing you the code that soma used for saving a language specific value to a field.

Using:

"name$lname" where $lname is actually defined as the ID of the language.

Take another look at soma's code and I think you will find what you need.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...