Hi,
That's indeed problematic if you want to add stuff in the same row of CB.
I thought that you just needed the id of the user in CB and in that case, it would have been good enough.
Reading what you're saying, if I understand correctly, you get the city/state/country values from the HikaShop user address and store it with the user in CB in your plugin. Wouldn't that be something we could actually do by default in the addAndConfirmUserInCB function of HikaShop ? That way, it would be a nice improvement for everyone.
Moving the synchronization with CB outside of HikaShop and adding it as a plugin is a good idea. We could actually merge it with the CB plugin we have here:
www.hikashop.com/support/documentation/7...mmunity-builder.html
But yes, adding a check in addAndConfirmUserInCB to not add the user if it is already in CB would be a good thing too.
Instead of a REPLACE, we could do first a SELECT based on the user_cms_id and then if no entry was found, we would do an INSERT, and if found, we wouldn't do anything.
Here is the modified function to add the check:
function addAndConfirmUserInCB($newUser, $addressData = null) {
$query = 'SELECT id FROM #__comprofiler WHERE id='.(int)$newUser->user_cms_id;
$this->database->setQuery($query);
$CBID = $this->database->loadResult();
if($CBID){
return true;
}
if(is_null($addressData)) {
$addressClass = hikashop_get('class.address');
$addresses = $addressClass->getByUser($newUser->user_id);
$addressData = reset($addresses);
}
$fields = array(
'cbactivation' => $this->database->Quote(''),
'id' => (int)$newUser->user_cms_id,
'user_id' => (int)$newUser->user_cms_id,
'approved' => 1,
'confirmed' => 1
);
if(!empty($addressData->address_firstname))
$fields['firstname'] = $this->database->Quote($addressData->address_firstname);
if(!empty($addressData->address_middle_name))
$fields['middlename'] = $this->database->Quote($addressData->address_middle_name);
if(!empty($addressData->address_lastname))
$fields['lastname'] = $this->database->Quote($addressData->address_lastname);
$query = 'INSERT INTO #__comprofiler (' . implode(',', array_keys($fields)) . ') VALUES (' . implode(',', $fields) . ')';
$this->database->setQuery($query);
$this->database->query();
return true;
}
Could you test it ?