hi
I have a custom module (a custom version of person module)
i've added a after_save hook to copy in contacts module the account just created .
so when you insert first_name,last_name and e_mail and clic save in my module you will find the same information on contacts module.
it works fine except that the email_address table is filled after the hook ,so i can't duplicate the e-mail address.
if then I modify the account and save it again my code work correctly(because email_addresses table is already filled) and the e_mail field in contacts is filled right
here the hook
function crea(&$bean, $event, $arguments)
{
if (empty($bean->fetched_row['id']) )
{
//save new contact if this is the first time you save the account
$query="INSERT INTO contacts (id,last_name,first_name) VALUES ('$bean->id','$bean->last_name','$bean->first_name')";
$result = $bean->db->query($query);
}
//delete old e_mail relation (enable e_mail modification)
$query="DELETE FROM email_addr_bean_rel WHERE bean_id='$bean->id' AND bean_module='Contacts' AND primary_address=1";
$result = $bean->db->query($query);
//find if the person have a mail
$query="SELECT email_address_id FROM email_addr_bean_rel WHERE bean_id='{$bean->id}' AND bean_module='STU_Persone' AND primary_address=1";
$result = $bean->db->query($query, true);
if ($bean->db->getRowCount($result) > 0)
{
//create new relation form mail to contacts:
$row =$bean->db->fetchByAssoc($result);
$mail=$row['email_address_id'];
$query="INSERT INTO email_addr_bean_rel (id , email_address_id , bean_id , bean_module , primary_address ) VALUES( UUID(),'$mail','$bean->id','Contacts',1)";
$result = $bean->db->query($query);
}
so the question is :
how can i execute my hook after the eamil_address isertion?


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks