CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adding / Updating Custom Location
Pages: [1]

Author Topic: Adding / Updating Custom Location  (Read 886 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Adding / Updating Custom Location
August 26, 2010, 04:47:46 am
Civi 3.1.5 w Drupal 6.19.

I created a new location type called 'Delivery' and its id is 6.

I'm trying to add addresses to it via a custom drupal module. It works fine when the code is set to use the 'Home' location with the location ids set to 1 and the is_primary set to TRUE. But once I try to change it to my 'Delivery' location nothing happens. I don't get an error but the address doesn't add. What am I doing wrong? here is the gist of the code that is related to this piece:

Code: [Select]
<?php 
require_once 'api/v2/Location.php';
$address = array(
        
6 => array(
            
'location_type_id' => 6,
            
'is_primary' => false,
            
'city' => $mycit,
            
'state_province' => $prov,
            
'postal_code' => $postal_code,
            
'street_address' => $street1,
            
'supplemental_address_1' => $street2,
            
'country' => $countries[0]['country_iso_code_2']
        )
    );

     
$Phone = array(
          
'is_primary' => false,
          
'phone' => $phone,
          
'phone_type_id' => 1,
          
'location_type' => 'Delivery'
      
);

    
// Put phone in an array and then add to $params array along with address
    
$phones = array( $Phone );
    
$params = array(
        
'version' => '3.0',
        
'contact_id' => $cid,
        
'phone' => $phones,
        
'address' => $address
    
);

    
$newLocation =& civicrm_location_update( $params );
?>


Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Adding / Updating Custom Location
August 26, 2010, 06:16:17 am
There is something weird with the location API, it needs an array element 1 for the address. Eileen has spotted this, and it needs to be investigated. Here are the related posts, it might help?
http://forum.civicrm.org/index.php/topic,15067.0.html
http://forum.civicrm.org/index.php/topic,15202.0.html
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adding / Updating Custom Location

This forum was archived on 2017-11-26.