Phone number replacement/validation

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #255535

Hi,

I am looking to replace some of numbers in address phone number field.
I need to have phone number format like this: +37068312345
Our customers mostly enter it like this: 868312345 or 68312345
So I need to take last 8 digits and add +370 at the beginning. I don't want to force user to enter they phone number like I need. I just want that on save address it would change automatically.
How can I achieve this?

Thanks

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

  • Posts: 26251
  • Thank you received: 4039
  • MODERATOR
8 years 6 months ago #255538

Hi,

If you wanted to control the data provided by the user, a regular expression in the custom field would be enough.
Knowing that you want to modify dynamically the data, the usage of a custom plugin is required.
You can use the triggers "onBeforeAddressCreate" and "onBeforeAddressUpdate" in order to have an access on the address content before his save in the database.
www.hikashop.com/support/documentation/6...ntation.html#address

Please note that some PHP/development skills are required.

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.

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #255578

Hi,

Thanks for replay Jerome.
Would it be possible to do it with simple js regex format? I could restrict how much simbols can be entered in custom fields settings and after user starts to enter it. Phone number would modify it self. Like in example below.
I am looking right now google but cant find what i need. Mostly everything is to format USA number....as this example:

jsfiddle.net/cruznunez/a4jbqqsv/

The problem is that we want to use acysms and with gateway textmagic sms isnt send due wrong format. All was working fine with smsgateway.me which is using android app...

Thanks

Last edit: 8 years 6 months ago by kyratn.

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

  • Posts: 26251
  • Thank you received: 4039
  • MODERATOR
8 years 6 months ago #255582

Hi,

Like you wrote :

I don't want to force user to enter they phone number like I need. I just want that on save address it would change automatically.

So no, my answer is still the valid answer.

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.

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #255671

Hi,

So after some time i did what i need with js. It does change to +370 on first key press. I'll wait and see if it works. Otherwise i will have to go with plugin as per advise.

Now i have 2 other problems.

1. I have set phone field display limited to my country. All fine. For international i have created another phone field and it seems i cant find a way how to limit it to show only with international country's and exclude my own country. I dont want to create 1 phone field per country.

2. For city field i need to add my own class, id, data-source but i dont see a way to do it?

Thank you

Last edit: 8 years 6 months ago by kyratn.

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
8 years 6 months ago #255686

Hi,

1. There is no option for that. The "Display limited to" setting only allow you to limit the display of the field for one value of another field, not several. So you would also have to add custom javascript to the page to hide/display it based on the selection of the country field.

2. Hard to give a precise answer as I don't know why you want to do that, what the field currently ouputs as HTML, etc.
There are several ways to add modify HTML attributes of a custom field.
First, you have the "attributes" setting of the custom field, when you edit it via the menu Display>Custom fields, which allows you to add custom attributes.
Then, you can also edit the view where the field is displaying (for example the "form" or the "show" view files of the "address" view) and use some str_replace to modify/add the attributes of fields on the fly.
You could also use javascript code to dynamically change/add attributes of fields on the pages.
Or you could even create your own custom type of custom field by developping a HikaShop plugin and implementing the custom field API like we did with the advanced date picker plugin.

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #255691

Hi,

1. I thought about javascript but hikashop has so many functions so i better ask before doing it...

2. I have tried to add it via "attributes" but doesnt work. I think it is to long or something and gives me error on saving. I need to add this:

aria-autocomplete="list" aria-haspopup="true" class="autocompleteReceiverLocality ui-autocomplete-input" data-source=" www.mysite.com/ajax_service.php?fnc=autocompleteLocalityDefault "

and it gives me error on saving. If i add only aria-autocomplete="list" aria-haspopup="true" it works fine.

So could you please show me how can i add it to address_city field via str_replace or i will have to go with javascript.

Thank you

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
8 years 6 months ago #255732

Hi,

There is no length restriction. There are however many checks done so that you can't break the custom field HTML. So the option will prevent you to add complex things in it even though they would be valid.

As I still don't know how you configured your checkout, I can't say for sure.
For the registration form, you would for example change the code:

$this->type = 'address';
		echo $this->loadTemplate();
to:
$this->type = 'address';
		echo str_replace('XXX','YYY',$this->loadTemplate());
where XXX is the bit that you want to replace and YYY the bit to replace XXX.

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #256080

Hi,

So i have managed to do what i want. I have added some autocomplete to address_city, search post code button to address_post_code and phone number regex to address_telephone.
Now i was thinking how should i handle this for international people. From all possible solutions i think the best would be to run this js functions based on country selected so i wont need to have more fields.

However as much as i try it doesnt work. As example i have this:

$(document).ready(function() {
      $('#address_country').change(function() {
       var thisVal = $(this).val(); 
        if(thisVal=='country_Lithuania_123') {
                   $('#address_city').autocomplete({
    source: function (request, response) {
        $.getJSON("https://www.mysite.com/ajax_autoservice.php?fnc=myAmazingFunction&term=" + request.term, function( data, status, xhr ) {
            response( $.map( data, function( item ) {
    return {
        value: item.label,
      
    }
    
}));
        });
    },
    minLength: 3,
    delay: 200
});
}
});
});

It does work always and looking into html it seems default country is always preselected. On choosing another country from dropdown it still shows default selected value. Please check images.
I have spent some time and could find a way how to run my js based on selected value/country.
Could i have help here please?

Thank you

Attachments:
Last edit: 8 years 6 months ago by kyratn.

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
8 years 6 months ago #256088

Hi,

I'm sorry but that's custom development. I've already given you plenty of tips regarding development. I can't spend the day trying to reproduce a problem with custom code you have done and then debugging it for you. I don't even know what doesn't work exactly.

I can just answer to your last sentence:

I have spent some time and could find a way how to run my js based on selected value/country.

What you did looks good with the code $(document).ready(function() { $('#address_country').change(function() { } ); });
I don't see why the trigger on the field wouldn't work. Try with an alert(); you check on whether that piece works properly.

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

  • Posts: 1119
  • Thank you received: 114
8 years 6 months ago #256124

Hi,

I am sorry Nicolas. Probably i have asked wrong question...

My code works fine if option has attribute selected="selected"

It looks like that hikashop only will add this attribute after you press save. It does not change when you select another country from dropdown list you must click save.

So i thought to get quick tip of what kinda function i should use to get it work based on dropdown list country i choose.

Update. So i have solved my problem with another jquery which toggles class based on option selected.

Thanks again Nicolas for your guide.

Have a great evening

Last edit: 8 years 6 months ago by kyratn.

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

Time to create page: 0.073 seconds
Powered by Kunena Forum