Two-way synchronization of Joomla users and amoCRM contacts

WT Amo CRM library - Documentation
Category: Libraries

How to create a Joomla user profile for all contacts in amoCRM. How to create a contact in amoCRM for Joomla users when registering on the site.

The WT AmoCRM library includes the User - WT AmoCRM user sync plugin, which offers basic integration scenarios between Joomla and AmoCRM in both directions.

Integrating two different systems is a complex process that requires considering numerous nuances and the specific logic of a particular business. Therefore, the details of each specific integration can sometimes vary significantly. In some cases, it might be easier to create several custom plugins to address your specific tasks. This plugin is not an absolutely universal tool and may not fully meet your requirements.

Enable the User - WT AmoCRM user sync plugin in the System - Manage - Plugins section. You can find the plugin by searching for the term amo or by using filters (search parameters).

How to find the Joomla AmoCRM integration plugin
How to find the Joomla AmoCRM integration plugin

Creating AmoCRM contacts upon Joomla user registration or creation

Data source: Joomla. Data destination: AmoCRM.

Plugin settings:

Create contact in AmoCRM?
Yes or No. When a Joomla user is created or registers independently, a contact will be created in AmoCRM.
Contact Tags
A dropdown list with tags loaded from AmoCRM. If selected, new contacts will be assigned the selected AmoCRM tags.
Selecting an AmoCRM tag for a contact when creating a Joomla user
Selecting an AmoCRM tag for a contact when creating a Joomla user
Update contact data in AmoCRM when updated in Joomla?
Yes or No. If Joomla user data is changed, should the data in the linked AmoCRM contact be updated?
Field for Joomla user link
For an AmoCRM contact, you can create a field of type link to store a link to the Joomla user profile. This is convenient for quick navigation between the Joomla and AmoCRM interfaces.
Joomla profile field in the AmoCRM contact interface
Joomla profile field in the AmoCRM contact interface
A tab named "AmoCRM" is added to the Joomla user edit page, where you can find a direct link to this user's contact in AmoCRM.
Link to AmoCRM contact in the Joomla user profile
Link to AmoCRM contact in the Joomla user profile

Configuring mapping between Joomla user fields and AmoCRM contact fields

Configure the mapping between AmoCRM contact fields and Joomla user fields. You can store field data in the params property of the user object (for developers) or in custom fields.

These settings are also used when processing incoming webhooks from AmoCRM and by the CLI contact import plugin Console - WT Import AmoCRM contacts.

Mapping AmoCRM and Joomla data fields
Mapping AmoCRM and Joomla data fields

What is the difference between custom fields and the $user['params'] property?

The main difference is the storage location of the data and the possibilities for editing and cleaning them.

Storing data in Joomla custom fields for users

Joomla Custom Fields are created manually in the admin panel beforehand. After that, you select which AmoCRM contact property should be placed into which Joomla user field. Technically, field values are stored in a separate table in the database: #__field_values. Joomla fields use ACL (Access Control List) - access level groups. This means you can control the visibility of data received from AmoCRM for different access levels. You can change them by editing the user.

In code, FieldsHelper is used to get the field data for a user.

<?php
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
 /**
     * @param   string             $context              The context of the content passed to the helper
     * @param   object|array|null  $item                 The item being edited in the form
     * @param   int|bool           $prepareValue         (if int is display event): 1 - AfterTitle, 2 - BeforeDisplay, 3 - AfterDisplay, 0 - OFF
     * @param   ?array             $valuesToOverride     The values to override
     * @param   bool               $includeSubformFields Should I include fields marked as Only Use In Subform?
     *
     * @return  array
     */
$fields = FieldsHelper::getFields('com_users.user', ['id' => $urser_id], true);

// Joomla uses Symfony vardamper
dump($fields );

Less obvious drawbacks: Since FieldsHelper uses ACL, it requires a session to determine the current user. In some cases (external requests without cookies, for example) a session is not created, and it becomes impossible to get a field via FieldsHelper.

Storing data in the $user['params'] property of the user object.

params is a column in the #__users table in Joomla where you can store your required data in json format. The advantage of this approach is that you don't need to use FieldsHelper to get the AmoCRM contact data. Every time you get a user object, you already have this data immediately. This is very convenient in cases of large and long loops where you don't need to make a separate database query for each iteration or build additional JOINs in SQL queries. Considering that FieldsHelper uses ACL, this adds several more JOINs and additional queries to the tables storing access rights.

In your code, you get the user and simply access their params property. Note that params is a json string, which you can convert into a Registry object for convenience. However, you can access a "ready" property via the method getParam($key, $default_value);

<?php
use Joomla\CMS\Factory;
use Joomla\CMS\User\User;

$app = Factory::getApplication();
$user = $app->getIdentity();

// Similarly
$user_id = 17;
$user = new User($user_id );

$telegram = $user->getParam('amocrm.telegram', null);

Drawbacks of this approach: This data is not available anywhere in the admin panel in the standard implementation. You can only manage this data in code.

The choice of storage location for each AmoCRM contact property directly depends on the features of your integration and the nuances of working with the data.

 

To be continued...

WebTolk Joomla Extensions

96 Extensions
12 Categories
492 Versions released
563144 Downloads
Cart
Cart is empty