Can't create opportunity 'after_save' logic hook

Hello, I’m trying to create a logic hook that would fire after a new opportunity has been created or edited.

I’ve tried to follow tutorial on Logic Hooks in SuiteCRM documentation.

However, my efforts we’re unsuccessful. I haven’t found any traces of logic hook failing or executing both in suitecrm.log file and in my website’s php error log.

SuiteCRM version: 7.11.15

Ok so here are the code files that I’ve added:
custom/modules/Opportunities/Logic_Hooks.php

    <?php

    $hook_version = 1;
    $hook_array = [
        'after_save' => [
            [
                77,
                "afterSaveToKafka",
                "custom/modules/Opportunities/after_save_kafka.php",
                "after_save_kafka",
                "after_save_kafka_method"
            ]
        ]
    ];

    ?>

custom/modules/Opportunities/after_save_kakfa.php:

    <?php

    $GLOBAL['log']->fatal("[Name] hook got included");

    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class after_save_kafka
    {
        function after_save_kafka_method($bean, $event, $arguments)
        {
            $GLOBAL['log']->fatal("[Name] hook got executed!");

            $opportunitiesOBJ = new \stdClass();
            $opportunitiesOBJ->id = $bean->id;
            $opportunitiesOBJ->name = $bean->name;
            $opportunitiesOBJ->date_entered = $bean->date_entered;
            $opportunitiesOBJ->date_modified = $bean->date_modified;
            $opportunitiesOBJ->created_by = $bean->created_by;
            $opportunitiesOBJ->description = $bean->description;
            $opportunitiesOBJ->opportunity_type = $bean->opportunity_type;
            $opportunitiesOBJ->lead_source = $bean->lead_source;
            $opportunitiesOBJ->amount = $bean->amount;
            $opportunitiesOBJ->amount_usdollar = $bean->amount_usdollar;
            $opportunitiesOBJ->probability = $bean->probability;

            $json = json_encode($opportunitiesOBJ);

            $this->sendKafkaTopic("suitecrm_opportunity_update", $json);
        }

        private function sendKafkaTopic($topic, $payload) {
            //some code here.
            //I dont wanna show this because some of the api credentials are here.
        }
    }

    ?>

NOTE: I have performed the Quick Rebuild and Repair step after adding these two files to the website.

Got it solved. The problem was that my Logic_Hook.php was in incorrect place. Docs are structured in a really strange way :thinking:.

Didn’t notice this section. (At the top of the docs it states a bit different path).

3 Likes