[ - Search Plugin - ] - Itemid & Multilanguage

  • Posts: 69
  • Thank you received: 11
12 years 2 weeks ago #74109

My site has to be in 2 languages ( or could be more.. ) and, I noticed in the default language that SEF URL's weren't working on the search results.

1. The all said: component/hikashop/product/... /category_pathaway_2?Itemid=###

I fixed that by specifying a Menu Item ID as mentioned in this other thread: www.hikashop.com/en/forum/2-general-talk...b/post.html?do=reply

That seemed to work for a second...

If I only can specify 1 menu item id, the URLs will all be in one language only. ( that's my new problem ) and also, the links won't work because I have the menus set for one language each one.

My Menu configuration looks like this:



When I change the Itemid to the other menu language, I'm able to click and get correct URL's for the other language as well.

Note: doing the same for the checkout does the same in terms of language, it forces all users to certain SEF URL and language and in my case I get broken URLs.


Eduardo Chongkan - Likan Development
http://likandevelopment.com

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

  • Posts: 69
  • Thank you received: 11
12 years 2 weeks ago #74197

Update:

For resolving the problem with the search results links I made plugin so I can configure as many Itemids for as many languages I need.

Then, on the com_Search tmpl override, I pulled the plugin's params to see what ItemID I needed to use for the current language. It now works with my 2 languages and I think I will work if I add a new language.

The plugin is not for admins, is more for developers and customizers. I'm attaching it in case someone needs it.

Note: You can add more fields to the plugin by editing the XML. You can also use a different logic for determining the name of the param to be used.

File Attachment:

File Name: pgl_likan_...lang.zip
File Size:1 KB


The code I used in the com_search override (default_results.php) was:

On the First lines of the file:
$plugin = JPluginHelper::getPlugin('system', 'likan_hikashop_multilang');
$params = new JRegistry;
$params->loadString($plugin->params);
$localizedParamID = JText::_('LK_LOCALIZED_ITEM_ID'); // You need to add the fieldnamames to the language file(S)
$localizedItemid = $params->get($localizedParamID);

Then, right before displaying each result:

	<?php 
			
				if ( $result->href ) : 
				// Added by Likan
					$hspattern = '/com_hikashop/'; 
					if (preg_match($hspattern,  $result->href)){
						// This is a HS product, brand or category
						$pattern = '/Itemid=[0-9A-Za-z]*/'; 
			    		$url_itemID = 'Itemid=' . $localizedItemid; 
						if (preg_match($pattern,  $result->href))
							$result->href = preg_replace($pattern, $url_itemID, $result->href);
						else
							$result->href .= '&' . $url_itemID;
					}
			?>

Note: On the foreach, I added a '&' to the $result var, to modify it's actual content.
<?php foreach ($this->results as &$result) : ?>
That worked for me. Please update this thread if you guys know how to do it in a better way.


Eduardo Chongkan - Likan Development
http://likandevelopment.com
Attachments:
Last edit: 12 years 2 weeks ago by likandev.
The following user(s) said Thank You: nicolas

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

  • Posts: 69
  • Thank you received: 11
11 years 10 months ago #86849

Note:

The above code worked for the search RESULT page only.

I was also using a Yootheme AJAX based search and today we noticed that in the secondary language, the Sanish URLs were broken because of a malformed SEF URL:

It was always returning:

es/shop/p/148-cartera-retro-floreada-cierre-pellizco/category_pathway-87

That URL should in fact be:

es/catalogo/p/148-cartera-retro-floreada-cierre-pellizco/category_pathway-87

This time, since the URL was comming from the Hikashop Plugin and the JS code was obfuscated, I needed to modify the product search pugin:

plugins/search/hikashop_products/hikashop_products.php

On line 240, I modified it as follows:

                        // Original 
                         //$item_id = $this->params->get('item_id','');
			
			// Likan 
			$lkplugin = JPluginHelper::getPlugin('system', 'likan_hikashop_multilang');
			$lkparams = new JRegistry;
			$lkparams->loadString($lkplugin->params);
			$localizedParamID = JText::_('LK_LOCALIZED_ITEM_ID'); // You need to add the fieldnamames to the language file(S)
			$item_id = $lkparams->get($localizedParamID);

The Ajax search now works fine in both languages.

PS. I still need to do some work on the URL translations when you click on Language Options ( Switching Languages ) It is based on the same plugin.

In case you want to check the ajax or regular search: madecostarica.com/es/


Eduardo Chongkan - Likan Development
http://likandevelopment.com
The following user(s) said Thank You: nicolas

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

Time to create page: 0.059 seconds
Powered by Kunena Forum