0

There is a custom extension that manage the shipping address for a local shipping carriers. Besides some extra fields for local data there is a custom field called tipo_direccion (address type in spanish) that holds just one value: 1 (for the office address of some shipping carrier) or NULL (for an specific shipping address). There's no other value for that field.

Now, in the config.xml, the text of the address_templates has a condition asking if tipo_direccion is set, if is true it will display the shipping carrier office address, but if it's not then it will display the particular shipping address. Once again, as the tipo_direccion never is null then the specific shipping address is never displayed.

I tried with jQuery (in the checkout/onepage/shipping.phtml template), PHP (in Checkout/controllers/OnePageController.php) and finally as a MySQL trigger (attached to sales_flat_quote_address table). Nothing seems to work (the trigger works perfectly in a testing database but not in the Magento database).

Here is the trigger:

DELIMITER $$
CREATE TRIGGER fix_quote_address 
BEFORE INSERT ON sales_flat_quote_address
FOR EACH ROW 
BEGIN
    IF NEW.tipo_direccion = 0 THEN 
        SET NEW.tipo_direccion = NULL;
    END IF;
END;$$
DELIMITER ;

EDIT: here is the config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <!-- modules -->  
    <admin>
        <fieldsets>
            <customer_account>
                <!-- *** -->
            </customer_account>
        </fieldsets>
    </admin>

    <global>
        <models>
            <!-- *** -->
        </models>
        <blocks>
            <!-- *** -->
        </blocks>
        <helpers>
            <!-- *** -->
        </helpers>
        <resources>
            <!-- *** -->
        </resources>
        <fieldsets>
            <customer_account>
                <!-- *** -->                
            </customer_account>      
            <sales_copy_order_billing_address>
                <!-- *** -->
                <tipo_direccion>
                    <to_order>*</to_order>
                </tipo_direccion>
                <!-- *** -->
            </sales_copy_order_billing_address>
            <sales_copy_order_shipping_address>
                <!-- *** -->
                <tipo_direccion>
                    <to_order>*</to_order>
                </tipo_direccion>
                <!-- *** -->
            </sales_copy_order_shipping_address>
            <sales_convert_quote_address>
                <!-- *** -->      
                <tipo_direccion>
                    <to_order_address>*</to_order_address>
                    <to_customer_address>*</to_customer_address>
                </tipo_direccion>
                <!-- *** -->
            </sales_convert_quote_address>
            <sales_convert_order_address>
                <!-- *** -->
                <tipo_direccion>
                    <to_quote_address>*</to_quote_address>
                </tipo_direccion>
                <!-- *** -->
            </sales_convert_order_address>
            <customer_address>
                <!-- *** -->
                <tipo_direccion>
                    <to_quote_address>*</to_quote_address>
                </tipo_direccion>
                <!-- *** -->
            </customer_address>
            <checkout_onepage_billing>
                <!-- *** -->
            </checkout_onepage_billing>
        </fieldsets>
    </global>

    <frontend>
        <!-- *** -->
    </frontend>

    <default>
        <carriers>
            <!-- *** -->
        </carriers>
        <customer>
            <address_templates>
                <text>
                    {{depend prefix}}{{var prefix}}{{/depend}}
                    {{var firstname}}{{depend middlename}}{{var middlename}}{{/depend}}
                    {{var lastname}}
                    {{depend suffix}} {{var suffix}}{{/depend}}
                    {{depend tipo_nif}}{{var tipo_nif}}{{var codigo_nif}}{{/depend}}
                    {{depend company}}{{var company}}{{/depend}}
                    {{if tipo_direccion}}
                        {{depend nombre_estado}}{{var nombre_estado}}, {{/depend}}
                        {{depend ciudad}}{{var nombre_ciudad}}, {{/depend}}
                        {{depend nombre_oficina}}{{var nombre_oficina}}, {{/depend}}
                        {{depend nombre_responsable}}{{var nombre_responsable}}, {{/depend}}
                        {{depend cedula_responsable}}{{var cedula_responsable}}{{/depend}}
                    {{else}}
                        {{var nombre_direccion}}
                        {{depend street1}}{{var street1}}{{/depend}}
                        {{depend street2}}{{var street2}}{{/depend}}
                        {{depend street3}}{{var street3}}{{/depend}}
                        {{depend street4}}{{var street4}}{{/depend}}
                        {{depend city}}{{var city}}, {{/depend}}
                        {{depend region}}{{var region}}, {{/depend}}
                        {{depend postcode}}{{var postcode}}{{/depend}}
                        {{var country}}
                        {{depend ekl_municipio}}{{var ekl_municipio}}, 
                        {{var ekl_parroquia}}{{/depend}}
                        T1: {{var local_phone_cod}}-{{var local_phone_num}}
                        T2: {{var cellular_cod}}-{{var cellular_num}}
                        {{depend fax}}F: {{var fax}}{{/depend}}
                        {{depend vat_id}}VAT: {{var vat_id}}{{/depend}}
                    {{/if}}
                </text>
                <oneline>
                    <!-- *** -->
                </oneline>
                <html>
                    <!-- *** -->
                </html>
                <pdf>
                    <!-- *** -->
                </pdf>
                <js_template>
                    <!-- *** -->
                </js_template>
            </address_templates>
        </customer>
    </default>
</config>
  • Please post related config.xml code. Better to handle via Magento itself than to have trigger for this. – Kalpesh Feb 23 '16 at 0:26
  • @Kalpesh done, check it out. – abiyi Feb 23 '16 at 13:47
  • You said tipo_direccion is a custom field from custom extension. Can't you change the logic in that extension itself? Also does it work as expected if tipo_direccion is set to NULL instead of 0? – Kalpesh Feb 23 '16 at 17:41
  • 1
    Can you try {{if customer.getTipoDireccion()}} instead of {{if tipo_direccion}}? – Kalpesh Feb 23 '16 at 19:18
  • 1
    Glad to hear. I know Magento reads config.xml for setting default values first time only when module is registered/updated, not sure why didn't noticed in your question, my bad. I am posting this as answer it can help other developers stuck in similar situation. – Kalpesh Feb 23 '16 at 20:14
0

Changing {{if tipo_direccion}} to {{if customer.getTipoDireccion()}} worked for OP.

Also the change was done in core_config_data table where all the Magento configuration resides. If your module is not already registered, you can do this change in config.xml file but if the module is already registered (in core_resource table there will be an entry) then you have to modify it in core_config_data table (be careful!).

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.