Jump to content

[SOLVED]Change flag order?


Recommended Posts

Hi folks!

 

Just a quick question - how do you change the order of flags?

 

for example my site supports 3languages,

and I want them to show up in specific order.

 

I tried changing the id's in mysql and it all went bollocks.

 

So is there a correct way to do it? Thanks!

 

 

Also in which file to remove

Link to comment
Share on other sites

  • 1 year later...

What languages do you support, what order are they now and what order do you want them?
What PrestaShop version do you use?

pascal

 

<EDIT: when using features, this solution may give problems. For alternative, see post #23. pascal>


General idea is like this. Override Language class:

change+add functions:

//change this function:
public static function getLanguages($active = true, $id_shop = false)
{
if (!self::$_LANGUAGES)
Language::loadLanguages();

$languages = array();
foreach (self::$_LANGUAGES as $language)
{
if ($active && !$language['active'] || ($id_shop && !isset($language['shops'][(int)$id_shop])))
continue;
$languages[] = $language;
}

// example: start array {'English','Dutch','Greek'} N.B. elements of array are 0, 1, 2 !!
// add these red lines (modify order as needed for you)

Language::swapLanguages($languages,0,2); // in example: change 1st lang with 3rd: {'Greek', 'Dutch', 'English'}
Language::swapLanguages($languages,0,1); // in example: change 1st lang with 2rd: {'Dutch', 'Greek', 'English'}

// result: array contains {'Dutch', 'Greek', 'English'}

return $languages;
}


//add this function
function swapLanguages(&$ary,$element1,$element2)
{
$temp=$ary[$element1];
$ary[$element1]=$ary[$element2];
$ary[$element2]=$temp;
}

Hope this helps,
pascal

 

 

<EDIT: when using features, this solution may give problems. For alternative, see post #23. pascal>

Edited by PascalVG
When using features this may cause problems. See post #23 for alternative (see edit history)
Link to comment
Share on other sites

Hi Paul,

You should make the changes in /classes/Language.php

 

(actually you should override this file and do it there. See Prestashop documentation how you can do that:

http://doc.prestashop.com/display/PS15/Overriding+default+behaviors

 

If you can't find out how this works, just change it in the file above self, but don't forget you did it here (Make a big note!), because when upgrading PrestaShop this file will be overwritten, losing your modifications.

 

pascal

Link to comment
Share on other sites

Im finishing to tune the shop but i need to add a back button in the product description page. The is suppose to look as the buy now button.

Is possible to may be copy and paste the button code ?

Also is a bit tricky about the translations, as its label should said: back in english, volver in spanish and catalan.

 

Any ideas about hit new challenge ?

 

Thanks !

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Hi maca,

You have to make the changes in classes/Language.php, in the function getLanguages, as described in post #3, and add the swap function (also shown in post #3)

 

What order are your flags now, and what order do you want them to be?? Then I can give you the swaps needed.

Pascal

Link to comment
Share on other sites

The problem is in the back office. When I am in catalog/products, this takes place in the tab features. If I change anything, the features are listed and stored in the original order of language, that is not current. So the features in Spanish appear under the English flag ... But if I don't change anything, th order in front office is ok, why?

Link to comment
Share on other sites

Hmmm, maca, in my back office I don't see any problem.

 

Would you mind to let me into your back office for a moment, so I can see directly in your shop where it goes wrong?

If you want that:

please make a temporary 'employee' with "admin" rights (Administration->Employee)

then Send me a private message (PM) with the login and password (DON'T show it here, for obvious reasons... :-) )

 

let me know,

pascal

Link to comment
Share on other sites

Hi maca,

I checked your site and see what you mean. What happens is that the when the values of the features are displayed on the screen for editing (i.e. they are already saved one time in the database, and are no modified), they are coupled to the languages, using the ID of the languages:

 

Sample:

original Language order ,before we swap:

ID - Language

1-EN

2-FR

3-ES

 

After swap:

2-FR

3-ES

1-EN

 

The value are 'matched with the ID's of the language, NOT the order of he language:

What I believe is happening is, that Featurevalue 1 (When added the first time, originally FR), is now matched with language-ID 1 (ENG), and thus displayed first, so French Feature Value gets coupled to ENG language flag...

 

I tried to fix it, but for now still in vein. I'll try to have another look when I have time.

If you want to have a look yourself, look at codes like this:

 

$feature_value->value[$language['id_lang']] = ...

{foreach from=$available_features item=available_feature}

  {foreach from=$available_feature.featureValues item=value}

etc.

and files like Feature.php, FeatureValue.php, AdminFeaturesController.php.

I expect the problem (and solution) to be in there somewhere...

 

What might work is on this page only to have the languages UN-swapped. We then need to make a function GetLanguagesNoSwap or so and use this one to get the languages here. Not sure if that works, as it's a tab, not a separate page though, so there is a real possibility of mix-up!

 

Other solution is maybe to turn it around: Only in the case where we show the Language selection block we use a swapped version of GetLanguages. We then DON'T change the normal Function GetLanguages as we did in my example, but for the blocklanguages module only we use a GetLanguagesSwapped instead. Back office stays the same then, fixing the problem with FeatureValues automatically...

 

Well, I let you think with me about a solution. Think what would work for you. Best would be to fix the Featurevalues of course, but I didn't see an obvious solution yet...

pascal

Link to comment
Share on other sites

Hi maca,

After struggling to just change the flags in the blocklanguages only, I found a solution on the TPL level:

 

Take out all old changes (in language.php), as it mixed up things for back office->features, right?

We will ONLY change the language order when choosing the flags in Front Office:

 

Open file themes/<your theme folder>modules/blocklanguages/blocklanguages.tpl   (if you don't have this file, copy it here from /modules/blocklanguages/blocklanguages.tpl)

 

Here you'll see some code like this, at the top of the file:

<!-- Block languages module -->
{if count($languages) > 1}
<div id="languages_block_top">
	<div id="countries">

	{* @todo fix display current languages, removing the first foreach loop *}
{foreach from=$languages key=k item=language name="languages"}

What we'll do is just re-arrange the order here in the array to display:

<!-- Block languages module -->
{if count($languages) > 1}

{$lang_temp    = $languages[0]}
{$languages[0] = $languages[2]}
{$languages[2] = $lang_temp}

{$lang_temp    = $languages[0]}
{$languages[0] = $languages[1]}
{$languages[1] = $lang_temp}

<div id="languages_block_top">
	<div id="countries">

	{* @todo fix display current languages, removing the first foreach loop *}

See? We applied the same swap as in the original post I made,  but now at the tpl (display) level, instead of a higher level in the program, leaving the original order in place, causing no problems in back office anymore.

 

Hope this helps!

pascal

Link to comment
Share on other sites

Thanks. It works!! For me it were:

<!-- Block languages module -->
{if count($languages) > 1}

{$lang_temp    = $languages[1]}
{$languages[1] = $languages[2]}
{$languages[2] = $lang_temp}

{$lang_temp    = $languages[0]}
{$languages[0] = $languages[1]}
{$languages[1] = $lang_temp}

<div id="languages_block_top">
		<ul id="first-languages" class="countries_ul">
		{foreach from=$languages key=k item=language name="languages"}
	
			<li>
	
				

Didn't you know something about this, http://www.prestashop.com/forums/topic/277235-visualization-and-linking-of-packages/ Pascal?

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
×
×
  • Create New...