# Connect DIAFAN.CMS

ChatRex answers questions using published products in the selected store section and language: product search, details, availability and storefront links.

!!!info Manual module installation
The connection is available in ChatRex. The module is not yet published in ADDONS; contact ChatRex for the tested package. Installation, updates, removal, reconnection and live bot replies have been verified on a separate DIAFAN.CMS 7.6.5 site running PHP 7.4.
!!!

## Requirements

Use DIAFAN.CMS 7 with its online store module, PHP 7.4, an HTTPS storefront and administrator access. Prepare a site backup, access to hosting cron settings, the store section and language, and the primary currency code, such as `RUB`.

The CMS license and the ChatRex subscription are separate. Listing terms for an extension with an external ChatRex subscription are being clarified with DIAFAN.

## Install the module

The menu names below are translated from the DIAFAN administration interface.

1. Open **Themes and design → Add manually**.
2. Enter a separate name for the ChatRex theme, upload the supplied ZIP, enable application of the theme and save. Keep the backup offered by the installer.
3. Open **Modules and database → Install modules**. Select **ChatRex** and click **Update**. Keep other module selections unchanged and leave demo content disabled.
4. Open **ChatRex**. Select **Store section**, enter **Primary currency (ISO code)** and verify **Public URL for this language**.
5. Click **Get connection code**. Copy the module endpoint and one-time code.

The code expires after ten minutes. To connect another language, first switch the administration language. The module reads the selected section and language; it does not change products, orders or payments.

## Connect ChatRex

1. In [ChatRex](https://app.chatrex.pro), open **Integrations → Connect integration → Data sources → DIAFAN.CMS**.
2. Open the connection setup tab and enter the endpoint and one-time code copied from the module. Your CMS administrator password is not required.
3. Connect the catalog and wait for **Connected**.
4. Check subscription access. ChatRex offers a subscription if there is no active subscription or demo access. Reconnecting preserves an existing subscription.

Generate a new code if it has expired or was used. Disconnect a previous connection before assigning the same section to another integration.

## Background checks

Create a hosting cron job that runs **once a minute**. Copy the command from the ChatRex module settings in DIAFAN and use the full path to `chatrex.cron.php` with the same PHP 7.4 runtime as the site.

The job calls your storefront over HTTPS. The server must reach its public URL and ChatRex. The module periodically checks the catalog and sends change notifications. Bot actions read current store data when called.

## Bot and storefront chat

Create a bot from the DIAFAN.CMS template or add the [four catalog actions](../../actions/integrations/diafan.md) to an existing bot. Select the store connection for each operation and provide delivery, payment, return and unavailable-data instructions.

Connect a ChatRex website chat, add the HTTPS storefront domain to its allowed domains and assign the chat channel to the bot. In the DIAFAN connection's **Website chat** section, select that chat and install the widget.

Add this tag once before `</body>` in your DIAFAN site template:

```html
<insert name="show_widget" module="chatrex">
```

Use your Custom theme and preserve the site's existing layout. Remove any previously embedded ChatRex widget code to avoid loading it twice. Open a public page and send a test product question.

## Update, disconnect and remove

Before updating, back up the CMS database, your Custom theme and `modules/chatrex/config/secret.php` together. Open the existing ChatRex theme under **Themes and design** and upload the replacement ZIP. A normal update preserves the connection and key.

Disconnect in ChatRex or click **Disconnect** in the module to revoke catalog access. If the site is unreachable, also disconnect inside the CMS to remove its widget.

To uninstall, clear only **ChatRex** in **Modules and database** and click **Update**. This removes the module's own data and key, stops loading its widget and notifies ChatRex. CMS products, variants and orders remain. Previous ChatRex conversations are retained.

After reinstalling, set the currency again, generate a new code and reconnect the existing integration. Install the widget again. The old key is invalid.

## Before launch

Check two products, their variants, price, currency, discount, stock and links. Change a test price or stock quantity in the CMS and search again. Saving a DIAFAN product can replace variant IDs: use IDs from fresh results, never hard-code old variants.

When stock tracking is disabled, an exact quantity is unknown. Report only confirmed availability. On unavailable data, offer specialist assistance; a fallback message does not automatically configure an operator handoff.

Help: [support@chatrex.pro](mailto:support@chatrex.pro).
