Jump to content

Ask for VAT only on European countries


Recommended Posts

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.

  • Like 1

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@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 ?

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites
  • 2 months later...

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 :)

Share this post


Link to post
Share on other sites
  • 2 weeks later...

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?

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More