Ca'nt get field values in the right language

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 month ago #157196

-- HikaShop version -- : 2.3.1
-- Joomla version -- : 2.5.20
-- PHP version -- : 5.5.10
-- Browser(s) name and version -- : all

I've been using for long this piece of code suggested by the Hikari Support Team:

$db = JFactory::getDBO();


$db->setQuery('SELECT category_id FROM '.hikashop_table('product_category').' WHERE product_id='.(int)$this->row->product_id);
$categoryName = $db->loadResult();
$db->setQuery('SELECT category_name FROM '.hikashop_table('category').' WHERE category_id='.(int)$categoryName);
$categoryName = $db->loadResult();



The problem is that now I made the site multilanguage with FaLang but no matter what is the browsed language all values are always captured in the default language of the site.

Of course the categories are already translated and show right in most parts of the site but not in the pieces coded by me.

I guess I should add something extra to the code but no clue on what to try.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #157333

Hi,

Could you be more precise about what you need ?
Where are the fields not translated, how do you add the content to these fields ? etc.

To have translated text, it need to be in the PHP code:

<?php echo JText::_('MY_TRANSLATION_KEY'); ?>
And then you need to add a transaltion on this key in the language files.

For the custom field, you maybe have to add the entry in the FaLang xml file.

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 month ago #157335

The problem relies not in product fields or custom fields but in the category names.

I have several categories entered originally in spanish. Later I added English and the names of categories were succesfully translated. They show right in all default list views, but can't get the english translated value when using the code showed above. It retains the spanish version of the category name.

Last edit: 11 years 1 month ago by PeterChain.

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 month ago #157396

I can handle without the problem the fixed translations in the mode suggested by you of

<?php echo JText::_('MY_TRANSLATION_KEY'); ?>

what can't I get is the category name in the right language, is always coming in the default original language like there was no language handling

Please Log in or Create an account to join the conversation.

  • Posts: 84079
  • Thank you received: 13634
  • MODERATOR
11 years 1 month ago #157401

If you don't get the override used for a translation, it means that there must be an error in the translation override file.
Turn on the "debug language" option of the Joomla configuration and you'll get at the bottom of the page the translation files parsing information with the file paths and lines where there is a problem in the translation files which joomla tries to load.

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 month ago #157491

i don't think the translations for my product categories are stored in any override file.

I want my category "Carretilla elevadora" to show as "Forklift" when displaying the site in english. It does when I render a listing__div or any default hikashop view.

It does not when the view is created by me, but is a view override and not a language override because the name of a category is contained somewhere in the database, can't believe my categories names and translations are contained in a file.

I already included the code I run to get the name of a category, but this only works to show the default langague category name, not the translations built with falang.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #159154

Hi,

After reading again this topic, I think that you have to edit your request in order to left join the FaLang table.
As far as I know, the translations are stored in FaLang tables, so thanks to a left join, you should be able to get the translated string of the desired category.

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 month ago #159178

Thank you Xavier!

But I don't understand the concept "left join", could you assess me a little bit about it?

thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
11 years 1 month ago #159490

Hi there,

LEFT JOIN is a joint you make between two tables in your query.
Basically these two table must have a key in common (for example product_id, or article_id) and by joining it you create virtually a big table with correspondances.
It should look like this:
SELECT category_id FROM '.hikashop_table('product_category').' AS a LEFT JOIN falang_content AS b ON a.category_id=b.category_id WHERE ....

It's just an example though.

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 month ago #159540

Thank you, I will investigate this way

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 2 weeks ago #162350

Still need help with this, I don't think this should be so complicated to handle as I believe there is lack of understanding maybe because of my bad explanation, what I request must be handled by a simple function of the framework and not inventing new code

so I will restart explaining hopefully in a better way:

1. For a product_listing.php view I made this code so I can show the category for that product:

<?php
$db = JFactory::getDBO();
$db->setQuery('SELECT category_id FROM '.hikashop_table('product_category').' WHERE product_id='.(int)$this->row->product_id);
$categoryName = $db->loadResult();
$db->setQuery('SELECT category_name FROM '.hikashop_table('category').' WHERE category_id='.(int)$categoryName);
$categoryName = $db->loadResult();
?>

2. This code ends storing in $categoryName the name of the category of the viewed product.

3. THE PROBLEM: It always pick the original language category name. Never the falang value. But in the same view I can get all product fields values translated to the current language.

4. SO, I miss some small code like getTranslations() or something so the code picks the text for category name in the right language.

I serached and carved and investigated in the helpers and default views but I don't get the clue. I'm not a real PHP coder but I honestly don't think is really a need to create complex LEFT JOIN solutions as in other places of HikaShop the correct language for category names is displayed inside prdouct_listing.

Example of right category language show:

www.activacions.com/en/forklift-catalog/...nspaletas-electricas (you will see the text "Electric Pallet Truck" which is in english inside a product_view)

Example of wrong category language show:

www.activacions.com/en/forklift-catalog/.../834-ejc-10-k-250-zt (you will see the text "Apiladores eléctricos" which is in Spanish)

Unfortunatley now I discover that also the product fields don't show in teh current language but only in the original. My code to show product files is this:

<?php echo JText::_('MASTIL');?> // This shows right for each language
<?php echo '<a class="pagina_producto_datos">'.$this->row->mastil.'</a>';?> // This shows only in the original language

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 2 weeks ago #162379

OK. Let's forget this thread.

Now I discovered the translation system is far more simple and primitive than I expected. It requires a lot more steps than what seems logical, I suppose due to the poor translation system in Joomla 2.5

I wonder if translating would be simpler with Joomla 3.x

Anyhow I did all the steps for translating some products and my catgories and the system still doesn't work.

Do you have any clear documentation for understanding the whole translation universe related to Joomla-HikaShop? Now I feel really disappointed that it is not simpler like in many other frameworks.

I'll be back to you when I figure out the whole thing and the real cost of building a multilanguage e-commerce solution with Joomla-HikaShop.

Sorry if I made waste your time.

Please Log in or Create an account to join the conversation.

  • Posts: 84079
  • Thank you received: 13634
  • MODERATOR
11 years 2 weeks ago #162359

Hi,

So you raise two issues. One when loading the category name, and one for the translation of custom product fields.

1. Falang should automatically translate the return of the query. I guess that your query is a case not handled by Falang. Try like that instead:

<?php
$db = JFactory::getDBO();
$db->setQuery('SELECT category_id FROM '.hikashop_table('product_category').' WHERE product_id='.(int)$this->row->product_id);
$categoryName = $db->loadResult();
$db->setQuery('SELECT *FROM '.hikashop_table('category').' WHERE category_id='.(int)$categoryName);
$category = $db->loadObject();
$categoryName = $category->category_name;
?>
Maybe Falang will have it easier with all the fields of the category... Otherwise, I would recommend to check on that with Falang support as this is supposed to work automatically with the Falang database plugin.

2. It's normal that the code you used display the original value since you don't use the custom field display function. You should use instead such code :
<?php
$this->fieldsClass = hikashop_get('class.field');
$itemFields = $this->fieldsClass->getFields('frontcomp',$this->row,'product','checkout&task=state');
echo $this->fieldsClass->show($itemFields['mastil'],$this->row->mastil);
?>

The following user(s) said Thank You: PeterChain

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 2 weeks ago #162425

Thank you very much!

I'll try your suggestions in the next few hours.

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 2 weeks ago #162428

Many many many thanks Nicolas!

You are a great team and me a bad coder. After so many days without having a good answer and cluelessly investigating today I arrived to a deep point of frustration, there are so many parameters and processes suitable for translation that it became to me a big disappointment with Joomla 2.5

ALL YOUR CODE WORKED at first although I still have to learn what is doing each part.

Thank you!

Please Log in or Create an account to join the conversation.

  • Posts: 639
  • Thank you received: 16
  • Hikashop Business
11 years 1 week ago #162570

Could you briefly explain me how this piece of code you suggested works?

echo $this->fieldsClass->show($itemFields['mastil'],$this->row->mastil);

It is working to me for custom fields but not for core fields (al least for product_code), is this the expected behavior?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 week ago #162571

Hi,

This code allow to display the custom field values. The product_code is not a custom field, you can't find it through the Display > Custom fields menu.

So to display the product code, you only need "echo $this->row->product_code".

Please Log in or Create an account to join the conversation.

Time to create page: 0.236 seconds
Powered by Kunena Forum