Results 1 to 9 of 9

Thread: Address Fields

  1. #1
    lmiller is offline Sugar Community Member
    Join Date
    Feb 2010
    Posts
    106

    Default Address Fields

    Under accounts we have 2 different address fields, one for the business's location, and the other for the billing address. Seeing that most websites allow you to check a box, and it will fill out the other address very easily, I decided to do the same. I've decided to share what I came up with, just for the sake of anybody who is new to PHP, like I am, to see how it's done.
    there is a lot of commenting in the file, just in case, later on down the road, you have to change it. Commenting is always VERY good to do, whether your code is simple or not.
    PHP Code:
    <?php 

    /************************************* 
    Project:Address form hook
    Developer: Lane Miller 
    Desc:Hook to fill in address if checkbox is selected.
    The contents of this file are governed by the GNU General Public License (GPL). 
    A copy of said license is available here: http://www.gnu.org/copyleft/gpl.html 
    This code is provided AS IS and WITHOUT WARRANTY OF ANY KIND. 

    *************************************/ 

    class addresshook 

    function 
    convertToProper(&$bean$event$arguments){ 
        
    #the IF statement dictating that if the box is checked, the hook is executed
                
    if ($bean->same_as_billing_c == ){  
    /*different address fields that match-the first one is the one that you want to be CHANGED
     and the second one is the one that has already been input. In my case, the first set of addresses
    , that gets filled in manually ALL the time, is the billing address. The check box is for the physical 
    address being the same as billing address, so the way that my custom fields are set up, the billing
     address will be what gets moved into the section for physical address*/
       #this is where my logic hook does the work, only if the IF statement is true
        #street    
            
    $bean->physical_address_c $bean->billing_adress_c 
        
    #city
            
    $bean->physical_address_city_c $bean->billing_adress_city_c ;
        
    #state
            
    $bean->state_c $bean->billing_state_c ;
        
    #zip
            
    $bean->physical_address_postalcode_c $bean->billing_adress_postalcode_c ;    
    }    


    }
    ?>

  2. #2
    nileshdave is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Gujarat
    Posts
    95

    Smile Re: Address Fields

    Very useful feature. Thaks for sharing

  3. #3
    lmiller is offline Sugar Community Member
    Join Date
    Feb 2010
    Posts
    106

    Default Re: Address Fields

    Your welcome! I figured I wasn't the only person who would use something like that, so I figured I'd post how I did it!

  4. #4
    rohitk is offline Sugar Community Member
    Join Date
    Mar 2010
    Location
    Poona
    Posts
    84

    Default Re: Address Fields

    can anyone please tell in which files these changes are to be made. Coz this seems like a good code which will resolve my issue but i dont know where this code needs to be added.

  5. #5
    lmiller is offline Sugar Community Member
    Join Date
    Feb 2010
    Posts
    106

    Default Re: Address Fields

    If you have worked with logic hooks before, you need to make the file logic_hooks.php which goes in the directory root/custom/modules/(your module that you want this to be done in)

    Mine is in public_html/custom/modules/Accounts and it looks like this
    PHP Code:
     <?php 
    $hook_version 
    1
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    #first page hook-this is the hook to make the accounts status change according to a number
        
    $hook_array['before_save'][] = Array(1'firstpagehook''custom/modules/Accounts/1stpagehook.php''firstpagehook''convertToProper'); 
    #zip code->state this is the logic hook to change the state to match the zip code
        
    $hook_array['before_save'][] = Array(2'ziphook''custom/modules/Accounts/ziphook.php''ziphook''convertToProper');
    #address hook - this is the hook that you want to use
        
    $hook_array['before_save'][] = Array(3'addresshook''custom/modules/Accounts/addresshook.php''addresshook''convertToProper');
    ?>
    So if you don't have any other logic hooks in the custom module that you are using, you want it to look like this
    PHP Code:
    <?php 
    $hook_version 
    1
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'addresshook''custom/modules/Accounts/addresshook.php''addresshook''convertToProper');
    ?>
    and then you would have a file called addresshook.php

    and that would include the file that you see in the first post.

  6. #6
    rohitk is offline Sugar Community Member
    Join Date
    Mar 2010
    Location
    Poona
    Posts
    84

    Default Re: Address Fields

    Hi iMiller,

    I tried what you had explained in post but the issue doesnt get resolve. i have a custom module: carriers in /modulebuilder/modules/carrier/ . i have added your logic hook in /customfolder/metadata/editview.php (here
    checkbox is also created with code:

    array('customCode'=>'Copy address from left: <input type="checkbox" name="same_as_billing_c" id="same_as_billing_c" value="" /> '),
    ),

    then created another file logichook.php in \module\carriers\logichook.php at same level, address_hook.php is also created.

    my problem is i can get the check box but i couldnt associate this logic_hook to the checkbox i have created.

    Can u plz help me out with this and thnx for reply.
    Rohit.

  7. #7
    lmiller is offline Sugar Community Member
    Join Date
    Feb 2010
    Posts
    106

    Default Re: Address Fields

    did you rename the fields in my code to match the fields in your own code? And if that is done correctly, the only other problem is that your logichook.php file should be name logic_hooks.php


    and this line in your logic_hooks.php file
    PHP Code:
    $hook_array['before_save'][] = Array(1'addresshook''custom/modules/Accounts/addresshook.php''addresshook''convertToProper'); 
    ?> 

    where it says addresshook.php, you need to make it match the name of your other file.

    So to recap, one file HAS TO BE named logic_hooks.php
    and then the other file, has to have the same name, and location as what is written under your hook array,
    mine is custom/modules/Accounts/addresshook.php so under the directory custom/modules/Accoutns you will find the file named addresshook.php

  8. #8
    rohitk is offline Sugar Community Member
    Join Date
    Mar 2010
    Location
    Poona
    Posts
    84

    Default Re: Address Fields

    Hi iMiller,

    Thnx for your reply. but it is still not running . here is the code that of files

    1) addresshook.php

    only the changed part i have copied and pasted, rest all is same as your file.


    if ($bean->copy_address == 1 ){
    #this is where my logic hook does the work, only if the IF statement is true
    #street
    $bean->shipping_address = $bean->billing_address ;
    #city
    $bean->shipping_address_city = $bean->billing_address_city ;
    #state
    $bean->shipping_address_state = $bean->billing_address_state ;
    #zip
    $bean->shipping_address_postalcode = $bean->billing_address_postalcode ;
    #country
    $bean->shipping_address_country = $bean->billing_address_country ;
    }

    2) logic_hooks.php

    <?php
    $hook_version = 1;
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1, 'addresshook', 'custom/modulebuilder/packages/carrier/modules/carrier/addresshook.php', 'addresshook', 'convertToProper');
    ?>



    all the files are at right locations. as you had mentioned they should e in custom/module/module_name
    mine are in 'custom/modulebuilder/packages/module_name' ....is this the cause of logic_hook not working.


    Thnx for all your help.

    Rohit.

  9. #9
    mangesh1757 is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    India
    Posts
    226

    Default Re: Address Fields

    Hi rohitk,

    'custom/modulebuilder/packages/module_name' ,this has to be

    custom/modules/carrier/''

    If it doesn't exists create it....also what i could find is if you have a custom module it can't have name 'carrier' to best of my knowledge....so do verify that exact module name.

    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I reorder the address fields
    By zzpiff in forum Help
    Replies: 4
    Last Post: 2009-08-12, 11:45 AM
  2. Cumulative fields (like post address)
    By Monkeyman in forum Help
    Replies: 3
    Last Post: 2009-05-30, 02:30 PM
  3. Auto populate address fields in 4.5
    By joshmark in forum Help
    Replies: 3
    Last Post: 2008-04-18, 11:01 AM
  4. Merged Fields - like First name & Address
    By russellp in forum Help
    Replies: 0
    Last Post: 2006-10-02, 09:23 AM
  5. Address Fields
    By rateck in forum Feature Requests
    Replies: 0
    Last Post: 2004-09-09, 08:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •