AnsweredAssumed Answered

Hook to Opt_out E-Mail in Module Contacts

Question asked by Bernhard Leitgeb on Jan 26, 2017
Latest reply on Jan 27, 2017 by Arald Cousquet

Hello Dear Sugar Community!

 

I want to put all Email-addresses in the module contacts to "opt_out" if the checkbox "inaktiv_c" is checked. 

 

I use a hook, but unfortunately it doesn't work. The hook itself gets triggered, i tried it with error_log. Here is my Code:

 

 

<?php

class Email_Hook
{

    function before_save_method($bean, $event, $arguments)
    {
        if ($bean->inaktiv_c) {

            if (!$bean->load_relationship('email_addresses'))
                return;
            $relatedBeans = $bean->email_addresses->getBeans();
            foreach ($relatedBeans as $relatedBean) {
                $relatedBean->opt_out = 1;
                $relatedBean->save();
            }
        }
    }
}
?>

 

 

Can you tell me what i have done wrong?

 

Thank You!

Outcomes