Values of the "value" attribute of the states list in the addresses

  • Posts: 117
  • Thank you received: 6
6 years 1 month ago #288019

-- HikaShop version -- : 3.2.2
-- Joomla version -- : 3.8.5
-- PHP version -- : 7.2.0
-- Browser(s) name and version -- : Firefox 58.0.2

Hi!

Tell me, please, are values of the "value" attribute of the states list in the addresses used anywhere in HikaShop?

If these values are not used anywhere, I have a question - did you think about filling these values with something more useful? For example, it would be very useful to indicate there the states codes according to https://en.wikipedia.org/wiki/ISO_3166-2ISO 3166-2 . HikaShop already have these codes and withdraw them will not be very difficult. But then it will be possible to use these codes to third-party developers to improve the user experience, for example, to offer address hints in the selected region.

Please consider the possibility of replacing these values with unified states codes.

P.S. Tell me, please, how can I get the value of the "value" attribute of the currently selected region using jQuery?


Sorry for my English, it's not my native language.
Attachments:
Last edit: 6 years 1 month ago by alin.

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

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
6 years 1 month ago #288020

Hi,

The value you see there is the namekey of the zone. That's what is used in the hikashop_zone_link table to link zones with sub zones.

Changing these values to use the zone 2 letter code won't be simple.
It would require changing the state dropdown handler, of course, but it would also require keeping backward compatibility for the addresses already in the shops, and most importantly, all the payment plugins and shipping plugins made for HikaShop expect the namekey of the zone in the address. Changing that would require modifying all the plugins, which is impossible, or add some conversion layer.

Now, you could do is differently and run an ajax request to get the code of the zone dynamically.

Getting the selected value of a dropdown with jQuery is easy:
jQuery('#ID').value
where ID is the ID of the dropdown select tag.

The following user(s) said Thank You: alin

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

  • Posts: 117
  • Thank you received: 6
6 years 1 month ago #288167

Thank you for detailed explanation!

I'm trying to get the current value of the drop-down list (State) using this code:

<script>
$(document).ready(function(){
  var currentRegion = ($("#data_address_address_state_chzn").text());
  alert(currentRegion);
});
</script>

It works but only when I edit an address in the Customer Account. When I try to edit an address at the checkout page - it doesn't work. Apparently, this is due to the fact that it needs to perform an AJAX request to display the address fields. I tried a lot of ways that I found on the Stack Exchange, but nothing helps.

Is it possible to get the current value of the drop-down list (State) on the checkout page after clicking edit?


Sorry for my English, it's not my native language.
Attachments:
Last edit: 6 years 1 month ago by alin.

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

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
6 years 1 month ago #288169

For the AJAX, you can use:

if(window.Oby){
 window.Oby.registerAjax(['checkout.address.updated'], function(params){
   // your code
 });
}
It will act like $(document).ready

The following user(s) said Thank You: alin

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

  • Posts: 117
  • Thank you received: 6
6 years 1 month ago #288227

Hi,

I've tried:

<script>
if(window.Oby){
 window.Oby.registerAjax(['checkout.address.updated'], function(){
  var currentRegion = ($("#data_address_address_state_chzn").text());
  alert(currentRegion);
 });
}
</script>
but it shows nothing after clicking edit link at the checkout page, what am I doing wrong?

I'm trying to create code that will allow me to assign a state identifier (ISO code or name) to a variable to use this variable later for comparison in the if else construct. However, there are several cases:
1. The drop-down list of states while changing / adding address in the Customer Area.
2. The drop-down list of states while adding address at the checkout page (if the address was not added earlier).
3. A drop-down list of states at the checkout page (if the address was added earlier) by clicking on the address editing link (AJAX request).

May be you can explain how to do that:

nicolas wrote: run an ajax request to get the code of the zone dynamically.

to define variable which contains the code of the zone?


Sorry for my English, it's not my native language.
Last edit: 6 years 1 month ago by alin.

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

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
6 years 1 month ago #288229

Hi,

I don't know. Please provide a link with instructions to reproduce so that we can look at it.

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

  • Posts: 117
  • Thank you received: 6
6 years 1 month ago #288418

Hi,

I've inserted the following code before the head tag:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
if(window.Oby){
 window.Oby.registerAjax(['checkout.address.updated'], function(){
  var currentRegion = ($("#data_address_address_state_chzn").text());
  alert(currentRegion);
 });
}
</script>

I see it in the source code of the page. But there is no any alert after clicking address edit link icon at the checkout page.

How can I provide link and credentials? How does confidential tag work?

Addition.

After changing checkout.address.updated to checkoutBlockRefresh alert is showing but doesn't contain any text. Reverted it back.


Sorry for my English, it's not my native language.
Attachments:
Last edit: 6 years 1 month ago by alin.

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

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
6 years 1 month ago #288451

Hi,

My code was meant to run after the address has been changed, and not when you click on the edit button.
If you want to have javascript code run when you edit the an address, then you can directly add your code in the show_block_address view file, and not in a "$(document).ready(function(){" but directly.
That way, the javascript will run when the address edition is loaded in AJAX.

The following user(s) said Thank You: alin

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

  • Posts: 117
  • Thank you received: 6
6 years 1 month ago #288465

nicolas wrote: directly add your code in the show_block_address view file

Thanks! May be it's the best way but needs overriding show_block_address view file and then every time after HikaShop update, I will need to check whether this file has changed. On the one hand, this simplifies the task of implementing the code, on the other hand, it complicates the task of maintaining the file in an up-to-date state.

Maybe you have an example of a plugin that dynamically injects the code into the show_block_address view file or maybe there is a way to use "clean" jQuery for this purpose, without having to override the show_block_address view file?

Addition.

Sorry it's my fault :oops: I made a mistake in the ID of the element. I used ID from the address editing page in Custom Area - #data_address_address_state_chzn instead #data_address_1_1_address_state_chzn. This code works:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
if(window.Oby){
 window.Oby.registerAjax(['checkoutBlockRefresh'], function(){
  var currentRegion = ($("#data_address_1_1_address_state_chzn").text());
  alert(currentRegion);
 });
}
</script>


Sorry for my English, it's not my native language.
Last edit: 6 years 1 month ago by alin.

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

  • Posts: 117
  • Thank you received: 6
6 years 1 month ago #288654

Hi,

Tell me please is the Chosen library used in some special way in HikaShop? When the Chosen library is disabled and a normal select element is used, the following code displays an alert every time the State changes:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
if(window.Oby){
  window.Oby.registerAjax(['checkoutBlockRefresh'], function(){
    $('#data_address_1_1_address_state').change(function(){
      var currentStateSelect = $("#data_address_1_1_address_state option:selected").text();
      alert(currentStateSelect);
    })
  });
}
</script>

But when the Chosen library is enabled and is used, the following code displays nothing when the State changes:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
if(window.Oby){
  window.Oby.registerAjax(['checkoutBlockRefresh'], function(){
    $("#data_address_1_1_address_state_chzn").chosen().change(function(){
      var currentStateChosen = ($("#data_address_1_1_address_state_chzn").text());
      alert(currentStateChosen);
    });
  });
}
</script>

Also I tried in window.Oby.registerAjax(, function():
$('#data_address_1_1_address_state_chzn').on('change', function() {
      var currentStateChosen = ($("#data_address_1_1_address_state_chzn").text());
      alert(currentStateChosen);
});
and
$('#data_address_1_1_address_state_chzn').change(function(){
      var currentStateChosen = $("#data_address_1_1_address_state_chzn option:selected").text();
      alert(currentStateChosen);
})
and
$('#data_address_1_1_address_state_chzn').change(function(){
      var currentStateChosen = $("#data_address_1_1_address_state_chzn").text();
      alert(currentStateChosen);
})

Perhaps there is a way to handle the Chosen select change event in HikaShop?


Sorry for my English, it's not my native language.
Last edit: 6 years 1 month ago by alin.

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

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 1 month ago #288660

Hello,

Chosen is a JS lib provided by the Joomla core and usually loaded by templates.
Afterwards, there is a setting in HikaShop to force the loading of chosen.
www.hikashop.com/support/documentation/5...html#display_general

If you want to know more about Chosen, I recommend you their website for documentation.
harvesthq.github.io/chosen/

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.090 seconds
Powered by Kunena Forum