Jump to content

[SOLVED] State does not show in the dropdown


angelina.mrp

Recommended Posts

Hi,

 

I have the following issue

 

When i try to register as a user, the registration form works well, the dropdowns are all populated and if the user does not make any mistake, everything is fine.

 

The issue is that when the user makes a mistake such as forgets to fill out a required field, the form loads again with the errors displayed on top but the state dropdown is empty and even if the correct country is selected, the state dropdown still is empty and remains so until I completely leave the form process and start all over again.

 

Has anyone had a similar issue or might be able to guide me in ten right direction to solve this? 

 

I am using Prestashop 1.6.0.13 and the New Parure theme. You can view the issue by following the above steps at 151.80.151.101/prestashop/

 

Thank you very much,

Link to comment
Share on other sites

Hi Again,

 

Trying to fix this problem within authentication.tpl I have placed {html_options values=$smarty.post.id_state output=$smarty.post.id_state} between the <select name="id_state" id="id_state"> tags. By doing this, after the user attempts to register and an error occurs, the user would see the state.id in the dropdown, but he would not be able to select any other value. By clicking submit at this point, the process would finish and the database would be updated correctly.

 

However, I noticed that although the database is updated, the state never appears in the user addresses. It does appear in the back office under Clients/addresses, although you don't see it at first sight and you must modify the address in order to see it correctly.

 

Checking more thoroughly, this last issue is persistent amongst all users. When they display their address, the state never appears although it is registered in the database.

 

I have imported the localization pack which included all the states (in my cases they are provinces within the country of Spain) and it seems that it is correctly configured.

Have any one of these issues happened to anyone or is there anyone that can help me / guide me to attempt to fix this?

 

If we can resolve this last issue, then I would still need to display the state name as opposed to the state.id. Does anyone know which array I could iterate that contain both state.id and state.name or if that is not possible, how can one do a SQL query directly from a tpl file?

 

This last option is not a perfect hack because if the user chooses the wrong state, he would not be able to change it and would need to start all over again. I assume that there is a better way to fix this, so if anyone can help/guide me that would be great, otherwise I could probably live with this last solution, but I really need urgent help.

 

Thank you very much,

 

Angela

Link to comment
Share on other sites

Hi Angela,

 

Can you check if it also happens when switching back to the default PrestaShop theme? If there everything goes correctly, I suggest to contact the theme developer first. If it here goes wrong as well, please report back here.

 

pascal.

Link to comment
Share on other sites

Hi Pascal,

 

Thanks for your answer.

 

On the bootstrap and the first issue works as expected, the dropdown gets populated after a user error. We did ask the theme developer if he could help but he could not tell why this happens nor could he guide us in any way. He did offer to return the money for the theme but after all the time and money spent configuring and adapting this, it is not an option.

 

On the other issue where the State field does not appear in the user screens, that also happens in the bootstrap.

 

What do you propose I do now?

 

Best,

 

Angela

Link to comment
Share on other sites

Hi Angela,

 

Is this a life site? If not, can you turn on Debug mode?

 

If it is, can you shortly turn on maintenance mode (Preferences, maintenance, turn off shop, and click 'add my IP', so that you still can get to the front office), and then debug mode, and register someone. Then make a mistake. See if any error pops up. Please copy error and show it here. Then quickly turn off debug mode again and

REOPEN your shop.

 

I see some errors on the page happening in the console. (use Chrome browser, Press Ctrl+Shift+J (in Windows)/ Command+Option+J (Mac)

 

pascal.

Link to comment
Share on other sites

Hi Pascal,
 
No it is not live yet.
 
I left it as it originally was (that is I do not capture the state ID) just in case the changes I did were causing the console error. It is placed on debug mode.
 
The errors displayed due to the debug mode is the following
 
Notice: Undefined index: id_category in /var/www/prestashop/tools/smarty/sysplugins/smarty_internal_templatebase.php(157) : eval()'d code on line 206
 
However, that error appears in every page and I am not sure why but it does not seem to have relation with this issue.
 
As you pointed out, on the console three other errors apear.
 
1. Blocked loading mixed active content "http://fonts.googleapis.com/css?family=Open+Sans" https://miscosasbellas.com/prestashop/index.php?controller=authentication Line 0

2. SyntaxError: unterminated string literal https://miscosasbellas.com/prestashop/index.php?controller=authentication Line 1948

Where line 1948 on the console appears as:
 

$('.id_state option[value=320]').attr('selected', true); });

 
and line 82 of authentication.tpl has
 

$('.id_state option[value={if isset($smarty.post.id_state)}
{$smarty.post.id_state}
{else}
{if isset($address)}{$address->id_state|intval}{/if}
{/if}]').attr('selected', true);

 
 
3. ReferenceError: countries is not defined https://miscosasbellas.com/prestashop/themes/newparuresix/js/tools/statesManagement.js Line 30
 
where line 30 is the second line of this funtion

function updateState(suffix)
{
    $('select#id_state'+(suffix !== undefined ? '_'+suffix : '')+' option:not(:first-child)').remove();
    var states = countries[$('select#id_country'+(suffix !== undefined ? '_'+suffix : '')).val()];
    if(typeof(states) != 'undefined')
    {
        $(states).each(function (key, item){
            $('select#id_state'+(suffix !== undefined ? '_'+suffix : '')).append('<option value="'+item.id+'"'+ (idSelectedCountry == item.id ? ' selected="selected"' : '') + '>'+item.name+'</option>');
        });
        
        $('p.id_state'+(suffix !== undefined ? '_'+suffix : '')+':hidden').slideDown('slow');
    }
    else
        $('p.id_state'+(suffix !== undefined ? '_'+suffix : '')).slideUp('fast');
}

Those errors definitely seem to be linked to the issue but, I have never touched these file nor I am really sure if what I would touch without breaking something else. To be more precise, I am not sure what I would need to do and exactly where to do it to fix the issue.

 

Any and all the help you can provide will be much appreciated.

 

Kindest regards,

 

Angela

 

Link to comment
Share on other sites

Hi Angela,

 

Can you change some code for me on line 82 of authentication.tpl?

 

Put the code you copied in your latest post on ONE single line.

 

$('.id_state option[value={if isset($smarty.post.id_state)}{$smarty.post.id_state}{else}{if isset($address)}{$address->id_state|intval}{/if{/if}]').attr('selected', true);

 

 

Javascript doesn't like the hard RETURN's inside the string.

 
 
pascal.
 
 
N.B. This would also explain why it gives no problem the first time it loads, as then the {if} ... {/if} removes all the hard RETURNS if the state isn't set yet (and no previous address has been added) :
 
$('.id_state option[value={if isset($smarty.post.id_state)}
{$smarty.post.id_state}
{else}
{if isset($address)}{$address->id_state|intval}{/if}
{/if}
]').attr('selected', true);
 
leaves:
$('.id_state option[value=]').attr('selected', true);
 
You see, the string is all on one line here :-)
Edited by PascalVG (see edit history)
  • Like 1
Link to comment
Share on other sites

Hi Pascal,

 

That did it!!!

 

Thank you so much,

 

Your explanation makes a lot of sense. Is this something the theme developer changed without knowing or do those lines come like this out of the box, in which case, I would suppose this must happen to everyone, no?

 

In any veent thank you very much for resolving this issue!

 

Best regards,

 

Angela

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...