The Perfex SaaS module offers extensive extendability, providing the flexibility to customize SaaS functionalities without directly modifying the core SaaS code. This approach ensures seamless integration with future updates.
Developing a module or extension is streamlined and requires an understanding of module development within Perfex CRM. Please refer to Perfex CRM module development comprehensive guide available here: Perfex CRM Module Development Guide.
Additionally, below are specific hooks and essential tips to aid in creating modules (extensions) for the SaaS module.
Available hooks within the Perfex SaaS Module #
Action Hooks:
hooks()->do_action('perfex_saas_loaded');
hooks()->do_action('perfex_saas_before_installer_run', $clean);
hooks()->do_action('perfex_saas_after_installer_run', $clean);
hooks()->do_action('perfex_saas_before_uninstaller_run', $clean);
hooks()->do_action('perfex_saas_after_uninstall_run', $clean);
hooks()->do_action('perfex_saas_after_client_create_instance', $_id);
hooks()->do_action('perfex_saas_module_tenant_deployed', ['tenant' => $company, 'invoice' => $invoice]);
hooks()->do_action('perfex_saas_module_tenant_deploy_failed', $company);
hooks()->do_action('perfex_saas_module_tenant_removed', $company);
hooks()->do_action('perfex_saas_module_tenant_removal_failed', $company);
hooks()->do_action('perfex_saas_module_tenant_created_or_updated', $_id);
hooks()->do_action('perfex_saas_after_package_update', $package);
hooks()->do_action('perfex_saas_after_package_clone', ['id' => $id, 'new_clone_id' => $clone_id]);
Filter Hooks:
hooks()->apply_filters('perfex_saas_create_instance_data', $data);
hooks()->apply_filters('perfex_saas_module_maybe_create_tenant_dsn', ['dsn' => $selected_pool, 'tenant' => $company, 'invoice' => $invoice]);
hooks()->apply_filters('modules_to_load', $activated_modules);
hooks()->apply_filters('perfex_saas_module_db_schemes', $schemes);
hooks()->apply_filters('perfex_saas_module_db_schemes_alt', $schemes);
hooks()->apply_filters('perfex_saas_module_tenant_data_payload', ['data' => $data, 'tenant' => $company, 'invoice' => $invoice]);
hooks()->apply_filters('perfex_saas_create_instance_data', $data);
hooks()->apply_filters('perfex_saas_module_maybe_create_tenant_dsn', ['dsn' => $selected_pool, 'tenant' => $company, 'invoice' => $invoice]);
hooks()->apply_filters('modules_to_load', $activated_modules);
hooks()->apply_filters('perfex_saas_module_db_schemes', $schemes);
hooks()->apply_filters('perfex_saas_module_db_schemes_alt', $schemes);
hooks()->apply_filters('perfex_saas_module_tenant_data_payload', ['data' => $data, 'tenant' => $company, 'invoice' => $invoice, 'error' => '']); // Set error to non empty value to prevent update/creating of the tenant.
// Below to modify My account menu when using single portal mode
hooks()->apply_filters('perfex_saas_tenant_account_menu', $child_menu_items);
// Below filter allow you to include file(s) after the SaaS module is initiated. See modules/perfex_saas/hooks/*
hooks()->apply_filters('perfex_saas_extra_hook_files',$feature_hook_files);
hooks()->apply_filters('perfex_saas_system_remote_extensions', $data['remote_modules']);
hooks()->apply_filters('perfex_saas_system_remote_extension_url', ['url' => $defaultRemoteFileUrl, 'purchase_code' => $purchase_code, 'module' => $module]);
// Below filter allow you to intercept tenant error message screen. You can check for the tag for relative control. You can always use perfex_saas_tenant() to get the active tenant and invoice details i.e perfex_saas_tenant()->package_invoice. Ensure the return array has 'show_error' set to false to prevent the error from showing. Leave as true to allow the error execution. You can also customize the error headings and message using this filter hook.
hooks()->apply_filters('perfex_saas_show_tenant_error', ['show_error' => true, 'tag' => $tag, 'heading' => $heading, 'message' => $message, 'error_code' => $error_code, 'template' => $template]);
// Deployment seeding custom query - Allow providing full queries for seeding using dsn
hooks()->apply_filters('perfex_saas_dsn_setup_source_dsn_queries', $hooks_payload);
// Return empty from below filter for fully controll deployment from dsn
hooks()->apply_filters('perfex_saas_before_tenant_seeding_from_dsn', $hooks_payload);
// Filter to notify about the queries that will be used for seeding the tenant when seeding from dsn
hooks()->apply_filters('perfex_saas_tenant_seeding_queries', $hooks_payload);
// Add extra menu to the 'My account' menu list when using single portal mode.
hooks()->apply_filters('perfex_saas_tenant_account_menu', $child_menu_items);
Do not forget to always return the passed parament by default for every filter.
Sample modules #
Kindly download the Affiliate and Super assistant module as sample. You can share them with the developer to have better understanding on how to develop extra extension for the Perfex SaaS module
Edge cases #
Certain modules necessitate functionalities during the initial system load or require application across all tenants, whether associated with tenant packages or not. For instance, scenarios where you aim to consistently load a module and govern access logic through it. In such cases, registering the module as a global module becomes essential. This is exemplified in the scenario of the SaaS Super Assistant module, where we want to check if the logged in staff in a tenant is an assistant and marked as assistant in the super admin.
To register an extension as global one, kindly use :
perfex_saas_register_global_extension($module_name);
i.e
perfex_saas_register_global_extension('saas_super_assistant');
After registering the module as a perfex saas extension, you can add a file name modulename_perfex_saas.php (e.g modules/wallet/wallet_perfex_saas) where all saas related function can be implement. When this file is not present, the SaaS module the load the default module entry file modulename.php i.e modules/wallet/wallet.php
Kindly see the sample module for more details.
When deactivating the module, you unregister the module as shown below:
perfex_saas_unregister_global_extension($module_name);
i.e
perfex_saas_unregister_global_extension('saas_super_assistant');
Kindly check the sample modules for better understanding.
Do not hesitate to reach out to us through support@perfextosaas.com for additional hooks.