3

In Magento 1.7 and 1.8 there are 2 "eav_attribute" regarding VAT: 'vat_id' and 'taxvat'. I can display the vat_id on customer address simply from system -> configuration -> customer configuration adding in the address templates:

{{depend vat_id}}VAT ID: {{var vat_id}}{{/depend}}

And it works fine. if I try the same thing with the 'taxvat' field

{{depend taxvat}}CF: {{var taxvat}}{{/depend}}

it doesn't work...

I think that it depends from the file

/app/code/core/Mage/Customer/etc/config.xml

so I create a custom module and added my config.xml, then I tried to edit the configuration to make the taxvat field like the vat_id field, but still it doesn't work. What's the best practice to display this builtin field in the address?

2

The reason that the taxvat is not working is because there is not attribute taxvat saved as part of the address. You can see this by looking into the table eav_attribute and filter on entity_type_id where the id is 2 (note that this is in the default data the address id)

You can either make a new attribute on the address, but that is a lot of work. What you could do instead is to look at the event customer_address_format here you can add items to the address object before rendering so you should be able to add the taxvat from the customer to the address.

| improve this answer | |
2

Here is the code to add the vat_id (taxvat) as variable in address :

app/code/local/ClientName/Sales/etc/config.xml

<?xml version="1.0"?>
<config>
    <adminhtml>
        <events>
            <customer_address_format>
                <observers>
                    <clientname_sales_customer_address_format_observer>
                        <type>model</type>
                        <class>clientname_sales/observer</class>
                        <method>addAdditionalDataToAddress</method>
                    </clientname_sales_customer_address_format_observer>
                </observers>
            </customer_address_format>
        </events>
    </adminhtml>
</config>

app/code/local/ClientName/Sales/Model/Observer.php

<?php

class ClientName_Sales_Model_Observer
{

    /**
     * Add vat_id in address
     *
     */
    public function addAdditionalDataToAddress(Varien_Event_Observer $observer)
    {
        $event = $observer->getEvent();
        $address = $event['address'];
        $orderData = $address->getOrder()->getData();
        $address->setData(
            array_merge(
                $address->getData(),
                array(
                    'vat_id' => $orderData['customer_taxvat'],
                )
        ));
    }
}

Then you can use this in your address template :

{{depend vat_id}}VAT ID: {{var vat_id}}{{/depend}} 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.