I think maybe I was unclear that this was taking place across 2 separate servers and using premium sync. My original question, basically was there an easy way to retrieve the company id of the most recent record.
I hope this helps someone in the future. It is a joomla plugin that takes the user input of a registration form, creates a company then creates a user within that company. This uses the premium sync module, allowing this to take place on different servers. It works great for my client in that they are able to have multiple websites with separate registrations all feeding into a single Epesi installation. It's not the cleanest code, yet, but works great.
class plgUserEpesiSync extends JPlugin {
function onUserAfterSave($data, $isNew, $result, $msg) {
if (!class_exists ('ShopFunctions')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php');
}
$country = ShopFunctions::getCountryByID($data['virtuemart_country_id'], $fld = 'country_2_code');
$state = ShopFunctions::getStateByID($data['virtuemart_state_id'], $fld = 'state_2_code');
$companyInfo = array('login' => 'admin',
'password' => 'password',
'module_id' => 'company',
'record_id' => 'NEW',
'f_company_name' => $data['company'],
'f_phone' => $data['phone_1'],
'f_fax' => $data['fax'],
'f_email' => $data['email'],
'f_web_address' => $data['website'],
'f_group' => $data['business_type'],
'f_address_1' => $data['address_1'],
'f_city' => $data['city'],
'f_country' => $country,
'f_zone' => $state,
'f_postal_code' => $data['zip'],
'f_tax_id' => $data['tax_id'],
'f_account_manager' => $data['account_manager'],
'f_industry' => '__'.$industry,
'f_fte_type' => 'justncase'
);
$lastSync = array('login' => 'admin',
'password' => 'password',
'module_id' => 'company',
'last_sync_date' => date("Y-m-d H:i:s", (time()-(0*0*0*0)))
);
if ($isNew) {
file_get_contents('http://fteinc.us/modules/Premium/Sync/save_record.php?'.http_build_query($companyInfo));
$get_company_id = file_get_contents('http://fteinc.us/modules/Premium/Sync/get_records.php?'.http_build_query($lastSync));
$xml = new SimpleXMLElement($get_company_id);
$company_id = $xml->record[0]->id;
if ($company_id) {
$contactInfo = array('login' => 'admin',
'password' => 'password',
'module_id' => 'contact',
'record_id' => 'NEW',
'f_company_name' => intval($company_id),
'f_last_name' => $data['last_name'],
'f_first_name' => $data['first_name'],
'f_address_1' => $data['address_1'],
'f_city' => $data['city'],
'f_country' => $country,
'f_zone' => $state,
'f_postal_code' => $data['zip'],
'f_group' => '__custm__',
'f_title' => $data['business_title'],
'f_work_phone' => $data['phone_1'],
'f_mobile_phone' => $data['phone_2'],
'f_fax' => $data['fax'],
'f_email' => $data['email']
);
file_get_contents('http://fteinc.us/modules/Premium/Sync/save_record.php?'.http_build_query($contactInfo));
}
}
}
}