Product listing by name - with Falang

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 2 months ago #267076

-- HikaShop version -- : 3.0.1
-- Joomla version -- : 3.6.5
-- PHP version -- : 5.5.12
-- Browser(s) name and version -- : Firefox 52.0

Hikashop Business - product listing by product_name.
I have products either with original names or translated names.
Listing is working allright with all original names or with translated names. But if we had both, translated names all come after the products with original names. HIKA sorts products with original names first, then all other products,with translated names.

It should be one alphabetically sorted list.

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 2 months ago #267085

Hi,

You can select how HikaShop do the ordering of the listing with the "ordering column" of the menu item/module. If you select "product_name", then it will use the data in product_name for the ordering and thus only take into account the untranslated value as the other languages are not stored there but in Falang.
There is no system to do the ordering based on the translation. That would require a left join to be added to the MySQL query on the falang_content table. While that's possible, it will really slow down the MySQL query so I don't really recommend it.
That could potentially be added as a plugin implementing the onBeforeProductListingLoad trigger for your website:
www.hikashop.com/support/documentation/6...reProductListingLoad

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

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 2 months ago #267247

Hi Nicolas,

Then why are the translated products listed at the end of the list? They should be ordered by their original product_name.
It would be acceptable, at least.

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 2 months ago #267254

Hi,

That's what it does on my end. Are you sure that you selected "product_name" in the "ordering column" setting under the "products options" tab of your menu item ? Are you sure that you set the correct product name in each product of the listing ?
Because I don't see any other reason it would not work.

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

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 2 months ago #267341

Of course, that has been set in the Menu Product Options.

Look at here the first two items listed in Manufacturers listing in original language;
Schoeps A 20 Elastic Suspension, 20/21mm
Schoeps A 20 S Elastic Suspension, stiff version, 20/21mm
link: w3.studio-general.hu/index.php/en/brands/cat/schoeps

There are 'translations' for them by Falang, with exactly the same string and only for the product_name:
Schoeps A 20 Elastic Suspension, 20/21mm
Schoeps A 20 S Elastic Suspension, stiff version, 20/21mm
Look at them on the Hungarian pages:
w3.studio-general.hu/index.php/hu/brands/cat/schoeps
You have to navigate to the last page to find them as they are listed the very last two items.

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 2 months ago #267344

Hi,


Can you turn on the debug mode of the Joomla configuration and provide the MySQL queries on the table hikashop_product for both links (you can find then in the debug area at the bottom of the page when that option is activated) ?

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

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 1 month ago #267637

Hi Nicolas,
Here they are;

Original language (en)
46.
SELECT DISTINCT b.* 
  FROM ykvxb_hikashop_product AS b 
  LEFT JOIN ykvxb_falang_content AS trans_table 
  ON trans_table.reference_table='hikashop_product' 
  AND trans_table.language_id=1 
  AND trans_table.reference_field='product_name' 
  AND b.product_id=trans_table.reference_id 
  WHERE (b.product_published = 1) 
  AND (b.product_type = 'main') 
  AND (b.product_manufacturer_id IN (32)) 
  AND ((b.product_access = 'all' OR b.product_access LIKE '%,9,%')) 
  ORDER BY trans_table.value ASC, b.product_name ASC 
  LIMIT 0, 20

63.
SELECT COUNT( DISTINCT b.product_id ) 
  FROM ykvxb_hikashop_product AS b 
  LEFT JOIN ykvxb_falang_content AS trans_table 
  ON trans_table.reference_table='hikashop_product' 
  AND trans_table.language_id=1 
  AND trans_table.reference_field='product_name' 
  AND b.product_id=trans_table.reference_id 
  WHERE (b.product_published = 1) 
  AND (b.product_type = 'main') 
  AND (b.product_manufacturer_id IN (32)) 
  AND ((b.product_access = 'all' OR b.product_access LIKE '%,9,%')) 
  ORDER BY trans_table.value ASC, b.product_name ASC

Secondary language (hu)
47.
SELECT DISTINCT b.* 
  FROM ykvxb_hikashop_product AS b 
  LEFT JOIN ykvxb_falang_content AS trans_table 
  ON trans_table.reference_table='hikashop_product' 
  AND trans_table.language_id=2 
  AND trans_table.reference_field='product_name' 
  AND b.product_id=trans_table.reference_id 
  WHERE (b.product_published = 1) 
  AND (b.product_type = 'main') 
  AND (b.product_manufacturer_id IN (32)) 
  AND ((b.product_access = 'all' OR b.product_access LIKE '%,9,%')) 
  ORDER BY trans_table.value ASC, b.product_name ASC 
  LIMIT 0, 20
 
64.
SELECT COUNT( DISTINCT b.product_id ) 
  FROM ykvxb_hikashop_product AS b 
  LEFT JOIN ykvxb_falang_content AS trans_table 
  ON trans_table.reference_table='hikashop_product' 
  AND trans_table.language_id=2 
  AND trans_table.reference_field='product_name' 
  AND b.product_id=trans_table.reference_id 
  WHERE (b.product_published = 1) 
  AND (b.product_type = 'main') 
  AND (b.product_manufacturer_id IN (32)) 
  AND ((b.product_access = 'all' OR b.product_access LIKE '%,9,%')) 
  ORDER BY trans_table.value ASC, b.product_name ASC

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 1 month ago #267648

Hi,

As you can see, the problem is that the language_id in the queries are the same in both case.
Normally, the language_id there should change when you change the language.
That's actually what I have on my end with I try to reproduce the problem.
So all I can think of is that there is a problem with the current language set in Joomla.
We use this code to get the current language id there:

	$language = JFactory::getLanguage();
	$language_id = (int)$translationHelper->getId($language->getTag());
and apparently, the $language->getTag() doesn't return the correct language, or the data in the #__languages table has some problem on your website.

Last edit: 8 years 1 month ago by Jerome. Reason: code indent

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

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 1 month ago #267742

Hi,

No, you can see at the primary language:
AND trans_table.language_id=1

and at the secondary language:
AND trans_table.language_id=2

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 1 month ago #267795

Hi,

Ahh, yes, I had missed that. Then, I reread the whole thread and I understand what's going. I thought that your problem was that the products were not ordered properly, but they do, it's just that the data is not consistent.

Yes, when you have Falang, and you order the listing on the product_name column, the system will order the listings by first ordering the products by their translation and then by their original text. So if you don't fill all the translations, then you'll have strange orderings. We do that so that you can still have the ordering properly when you just have falang but didn't translate the product names at all (because you don't need to).

Try replacing the code:

	$on .= ' LEFT JOIN #__'.$trans_table.' AS trans_table ON trans_table.reference_table=\'hikashop_product\' AND trans_table.language_id='.$language_id.' AND trans_table.reference_field=\''.$match[3].'\' AND '.$match[2].'.product_id=trans_table.reference_id';
	$order = $match[1].'trans_table.value '. $match[4].', '.$match[2].'.'.$match[3].' '.$match[4].$match[5];
to:
	$select2 .= ', CONCAT(trans_table.value, '.$match[2].'.'.$match[3].') AS translation_for_orderby';
	$on .= ' LEFT JOIN #__'.$trans_table.' AS trans_table ON trans_table.reference_table=\'hikashop_product\' AND trans_table.language_id='.$language_id.' AND trans_table.reference_field=\''.$match[3].'\' AND '.$match[2].'.product_id=trans_table.reference_id';
	$order = $match[1].'translation_for_orderby '. $match[4].$match[5];
in the file components/com_hikashop/views/product/view.html.php
That should allow it to order the products with either the translation or the product_name. However, that query will be much slower, but I don't see any way to do that differently.

Last edit: 8 years 1 month ago by Jerome. Reason: code indent

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

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 1 month ago #267838

Does not work.

At primary language - the proper alphabetical order is broken somehow;
At secondary language - products with translated product_name are still at the very ending, just like before.

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 1 month ago #267840

Hi,

It might be because of the NULL values since translations are missing.
Try changing CONCAT to CONCAT_WS in the code of my previous message. That should skip the NULL values instead of screwing the ordering. Let us knwo how it goes.

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

  • Posts: 35
  • Thank you received: 0
  • Hikashop Business
8 years 1 month ago #267925

It gives the same result...

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

  • Posts: 26253
  • Thank you received: 4040
  • MODERATOR
8 years 1 month ago #267926

Hello,

Can you please activate temporally the debug mode in your Joomla global configuration ?
The goal is to get the result query and have more details about it.
In the Joomla debug console, you should find the query for the loading of the products and be able to copy-paste it in PhpMyAdmin to watch the result.
By having the value you got for "translation_for_orderby" and the full "order by" rules, we would better understand the situation.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.076 seconds
Powered by Kunena Forum