etsilhooq Posted September 16, 2016 Share Posted September 16, 2016 Hello. I'm trying to configure Prestashop to ask the VAT number ONLY for countries which are covered by this. So, to make things clear: - If i chose FRANCE or SPAIN on the registration field, i should be asked for the VAT NUMBER, - If i chose UNITED STATES or CANADA, i shouldn't be asked for the VAT number. This result can be viewed on this Shop: https://www.flexoptix.net/en/customcheckout/registration/form/ Any idea how to accomplish this (that seems obvious to me for all shops needing VAT number, B2B shops) ? Many thanks. 1 Link to comment Share on other sites More sharing options...
rocky Posted September 18, 2016 Share Posted September 18, 2016 I would suggest using JavaScript to show or hide the VAT number field depending on the currently selected country. For example, change: <select id="id_country" class="form-control" name="id_country">{$countries_list}</select> to: <select id="id_country" class="form-control" name="id_country" onchange="if ($(this).val() == 1 || $(this).val() == 2) $('#vat-area').show(); else $('#vat-area').hide();">{$countries_list}</select> Change 1 and 2 to the IDs of France and Spain. Modify the code as needed depending on which countries need VAT numbers. Link to comment Share on other sites More sharing options...
Mascara Snake Posted September 18, 2016 Share Posted September 18, 2016 Wouldn't it be easier to show the VAT number field only for the zone Europe? Because it's required for all European countries, not just France and Spain. Link to comment Share on other sites More sharing options...
etsilhooq Posted September 18, 2016 Author Share Posted September 18, 2016 @Mascara of corse, the provided example was just it, an example @rocky many thanks, any idea how to apply this for all European countries ? My question is : Why isn't this a PS Core feature, as it seems obvious to ask it ONLY for European countries ? Link to comment Share on other sites More sharing options...
rocky Posted September 22, 2016 Share Posted September 22, 2016 It's hard, since there is no zone variable in the JavaScript or any function to get it. I think you'll have to create an array with all the European country IDs and then check whether the selected country ID is in that array to determine whether to hide the VAT number. For example, something like: <select id="id_country" class="form-control" name="id_country" onchange="if ($.inArray($(this).val(), [1, 3, 6, 8, 9, 13, 14, 16, 18, 26, 37, 86, 131, 139, 193, 216, 236]) $('#vat-area').show(); else $('#vat-area').hide();">{$countries_list}</select> Change the country IDs as required. 1 Link to comment Share on other sites More sharing options...
etsilhooq Posted September 22, 2016 Author Share Posted September 22, 2016 @rocky : Thanks, i'll do give this a try. Link to comment Share on other sites More sharing options...
etsilhooq Posted December 6, 2016 Author Share Posted December 6, 2016 in file vatManagement.js i have this: $(document).ready(function(){ vat_number(); vat_number_ajax(); $(document).on('input', '#company, #company_invoice', function(){ vat_number(); }); }); function vat_number() { if (($('#company').length) && ($('#company').val() != '')) $('#vat_number, #vat_number_block').show(); else $('#vat_number, #vat_number_block').hide(); if (($('#company_invoice').length) && ($('#company_invoice').val() != '')) $('#vat_number_block_invoice').show(); else $('#vat_number_block_invoice').hide(); } function vat_number_ajax() { $(document).on('change', '#id_country', function() { if (typeof vatnumber_ajax_call !== 'undefined' && vatnumber_ajax_call) $.ajax({ type: 'POST', headers: {"cache-control": "no-cache"}, url: baseDir + 'modules/vatnumber/ajax.php?id_country=' + parseInt($(this).val()) + '&rand=' + new Date().getTime(), success: function(isApplicable){ if(isApplicable == "1") { $('#vat_area').show(); $('#vat_number').show(); } else $('#vat_area').hide(); } }); }); } Can't this be modified to accomplish this more easy? I'm not a JS expert so i'm asking, thanks Link to comment Share on other sites More sharing options...
WebPT Posted December 16, 2016 Share Posted December 16, 2016 in file vatManagement.js i have this: $(document).ready(function(){ vat_number(); vat_number_ajax(); $(document).on('input', '#company, #company_invoice', function(){ vat_number(); }); }); function vat_number() { if (($('#company').length) && ($('#company').val() != '')) $('#vat_number, #vat_number_block').show(); else $('#vat_number, #vat_number_block').hide(); if (($('#company_invoice').length) && ($('#company_invoice').val() != '')) $('#vat_number_block_invoice').show(); else $('#vat_number_block_invoice').hide(); } function vat_number_ajax() { $(document).on('change', '#id_country', function() { if (typeof vatnumber_ajax_call !== 'undefined' && vatnumber_ajax_call) $.ajax({ type: 'POST', headers: {"cache-control": "no-cache"}, url: baseDir + 'modules/vatnumber/ajax.php?id_country=' + parseInt($(this).val()) + '&rand=' + new Date().getTime(), success: function(isApplicable){ if(isApplicable == "1") { $('#vat_area').show(); $('#vat_number').show(); } else $('#vat_area').hide(); } }); }); } Can't this be modified to accomplish this more easy? I'm not a JS expert so i'm asking, thanks This should be in the core version. Makes no sense that for all european countries we need to input a company name just to see the VAT field. People from Portugal (for example) do have a VAT and companies have another separate VAT. BTW etsilhooq how did you solved that on your website? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now