Difference between revisions of "Provisioning Modules and Addons Developer Migration Guide"

From WHMCS Documentation

(Created page with "WHMCS 7.2 introduces the ability to associate Product Add-ons with Provisioning Modules. For many provisioning modules, this won't require any changes at all. For some modul...")
 
 
Line 1: Line 1:
WHMCS 7.2 introduces the ability to associate Product Add-ons with Provisioning Modules.
+
In WHMCS 7.2 and later, you can associate [[Product Addons|product addons]] with provisioning modules.  
  
For many provisioning modules, this won't require any changes at all.  For some modules, some small changes may be required.
+
This may require small changes to modules for which any of the following statements are true:
  
The following document describes these changes.
+
* It performs database updates to the <tt>tblhosting</tt> table, which stores service information.
 +
* It uses custom database tables or tracks relationships based on the service ID.
 +
* It uses custom fields.
  
==Will I need to make changes?==
+
==Database Changes==
  
You will almost certainly need to make changes if your module does any 1 or more of the following:
+
Prior to WHMCS 7.2, whenever you invoked a module action, it was for a product or service in the <tt>tblhosting</tt> database table and you would always receive a <tt>serviceid</tt> value. In WHMCS 7.2 and later, module actions may also be for addons and you may receive an <tt>addonId</tt> value that contains the addon's ID (<tt>tblhostingaddons.id</tt>).
  
* Performs database updates to tblhosting (the table used to store services information)
+
There are two ways to determine whether the module action will act on an addon or a product or service:
* Uses custom database tables or tracks relationships based on the service id
 
* Makes use of custom fields
 
  
==Detailed Information==
+
# Check for the existence of an <tt>addonId</tt> value. If one is defined, the module action is acting on a product addon.
 
+
# Assert the type of the provided model:<source lang="php">
===Database Changes===
 
 
 
Whereas previously it was safe to assume that any time a module action was invoked, it was being invoked for a product/service which lived in the ''tblhosting'' database table and that you would always receive a ''serviceid'', that is no longer the case.
 
 
 
Now the module actions can be invoked for add-ons too, and in those cases, you will receive all the same module parameters as before but with the addition of '''addonId''' which will contain the ID of the add-on for which the module action has been invoked for (tblhostingaddons.id).
 
 
 
There are two ways to determine the type of product being acted upon:
 
 
 
# You can check for the existence of ''addonId''. If defined, the module action has been invoked for a product addon.
 
# You can assert the type of the model provided to you:
 
 
 
<source lang="php">
 
 
if ($params['model'] instanceof \WHMCS\Service\Service) {
 
if ($params['model'] instanceof \WHMCS\Service\Service) {
 
     // Method was invoked for a Service
 
     // Method was invoked for a Service
Line 34: Line 22:
 
</source>
 
</source>
  
===Custom Fields===
+
==Custom Fields==
 
 
Many provisioning modules often require storing of additional information relating to a product. For this, you use custom fields. Custom fields were not previously available for Product Addons, but along with the introduction of module support in WHMCS 7.2, we also introduced support for custom fields.
 
  
To make it easier to work with custom fields, and to aide module developers, WHMCS 7.2 introduces the concept of [[Service Properties]].
+
In WHMCS 7.2, we also introduced support for [[Custom Fields|custom fields]] for product addons. This allows you to store additional product-related information that many provisioning modules require.
  
A Service Property is a key/value pair relating to a given instance of a product or add-on. Stored in custom fields, service properties allow module developers to interact with custom fields in a simple programmatic way that is consistent for both products and add-ons.
+
To make it easier to work with these custom fields, WHMCS 7.2 also introduced [[Service Properties]]. A Service Property is a key/value pair in a custom field that relates to an instance of a product or addon. Service Properties allow module developers to interact with custom fields in a simple programmatic way that is consistent for both products and addons.
  
If you store any values into custom fields as part of your module code, relating it to the serviceid for which the action is being performed, you likely need to make some changes. You can read more about how to work with the new [[Service Properties]] functionality here.
+
If you store any values in custom fields as part of your module code, relating it to the <tt>serviceid</tt> value for which the action is being performed, see [[Service Properties]] for information about additional changes you may need to make.

Latest revision as of 21:01, 28 April 2022

In WHMCS 7.2 and later, you can associate product addons with provisioning modules.

This may require small changes to modules for which any of the following statements are true:

  • It performs database updates to the tblhosting table, which stores service information.
  • It uses custom database tables or tracks relationships based on the service ID.
  • It uses custom fields.

Database Changes

Prior to WHMCS 7.2, whenever you invoked a module action, it was for a product or service in the tblhosting database table and you would always receive a serviceid value. In WHMCS 7.2 and later, module actions may also be for addons and you may receive an addonId value that contains the addon's ID (tblhostingaddons.id).

There are two ways to determine whether the module action will act on an addon or a product or service:

  1. Check for the existence of an addonId value. If one is defined, the module action is acting on a product addon.
  2. Assert the type of the provided model:
    if ($params['model'] instanceof \WHMCS\Service\Service) {
        // Method was invoked for a Service
    } elseif ($params['model'] instanceof \WHMCS\Service\Addon) {
        // Method was invoked for an Add-on
    }

Custom Fields

In WHMCS 7.2, we also introduced support for custom fields for product addons. This allows you to store additional product-related information that many provisioning modules require.

To make it easier to work with these custom fields, WHMCS 7.2 also introduced Service Properties. A Service Property is a key/value pair in a custom field that relates to an instance of a product or addon. Service Properties allow module developers to interact with custom fields in a simple programmatic way that is consistent for both products and addons.

If you store any values in custom fields as part of your module code, relating it to the serviceid value for which the action is being performed, see Service Properties for information about additional changes you may need to make.