返回仪表板

文档

了解如何使用 Asyntai

如何将 Asyntai AI 聊天机器人添加到 OpenCart

OpenCart 网站的分步指南

获取嵌入代码

The Easy Way: Install the Asyntai Extension

We publish a free extension on the OpenCart Marketplace. It puts the chatbot on your storefront and connects your account, and there is no code to copy and no template to edit. It works on OpenCart 3.x and 4.x.

  1. Download Asyntai - AI Chatbot from the OpenCart Marketplace
  2. In your admin panel, go to Extensions → Installer and upload the ZIP file
  3. Go to Extensions → Extensions, choose Modules in the list, find Asyntai AI Chatbot and press the green install button
  4. Press edit, then press Connect to Asyntai. A window opens where you sign in or create an account.

That is all. The chatbot is live on your storefront when the window closes.

Your products, prices and stock

When you connect, the extension also lets Asyntai read your catalogue. Your assistant then answers with the price you charge today and tells shoppers what is in stock, instead of repeating whatever your pages said when they were last read.

Asyntai reads your products through a read-only address on your own store. Every request is signed, and the reply carries the prices a shopper would actually pay, with your tax rules already applied. You can switch this off at any time on the extension's settings screen.

Updating from version 1.0.0? OpenCart clears a module's settings when you uninstall it, so press Connect to Asyntai once after the update. From this version on, updates keep your connection.

Or Add the Code Yourself

Prefer not to install an extension? The rest of this page shows how to add the chatbot by hand. You will not get the catalogue reading this way.

步骤1:获取您的嵌入代码

First, go to your Asyntai Dashboard and scroll down to the "Embed Code" section. Copy your unique embed code which will look like this:

<script>(function(){var l=function(){var s=document.createElement("script");s.src="https://widget.asyntai.com/static/js/chat-widget.js";s.async=true;s.setAttribute("data-asyntai-id","YOUR_WIDGET_ID");document.head.appendChild(s)};if(document.readyState==="complete"){l()}else{window.addEventListener("load",l)}})();</script>

注意: 以上代码仅为示例。您必须从仪表板复制您自己的专属嵌入代码,因为其中包含您的个人小部件 ID。

Step 2: Edit Footer Template

添加聊天机器人最直接的方法是编辑主题的页脚模板:

  1. 通过 FTP 或文件管理器访问您的 OpenCart 文件
  2. 导航到主题的页脚模板:
    • OpenCart 3.x/4.x: catalog/view/theme/YOUR_THEME/template/common/footer.twig
    • OpenCart 2.x: catalog/view/theme/YOUR_THEME/template/common/footer.tpl
  3. 打开页脚文件进行编辑
  4. 找到</body>闭合标签
  5. 将您的Asyntai嵌入代码粘贴到</body>标签之前
  6. 保存文件
  7. 清除 OpenCart 缓存:仪表板 → 蓝色齿轮图标(右上角)→ 刷新或删除 system/storage/cache/ 的内容

提示: 如果您使用的是默认主题,路径为 catalog/view/theme/default/template/common/footer.twig。编辑模板文件前请务必创建备份。

备选方案:使用主题的自定义代码选项

许多现代 OpenCart 主题都包含内置的自定义代码选项:

  1. 登录您的 OpenCart 管理面板
  2. 转到 扩展 → 主题(或 扩展 → 扩展 → 主题
  3. 点击活动主题上的编辑
  4. 查找"自定义代码""页脚脚本""自定义 JavaScript"部分
  5. 粘贴您的Asyntai嵌入代码
  6. 点击"保存"
  7. 清除缓存

注意: 并非所有主题都有此选项。如果您的主题不包含自定义代码字段,请使用模板编辑方法或安装扩展。

备选方案:使用自定义代码扩展

您可以从 OpenCart 市场安装免费扩展来添加自定义脚本:

  1. Go to the OpenCart Marketplace
  2. 搜索"Custom Script""Header Footer Scripts""Custom Code"
  3. 下载并安装合适的扩展
  4. 在管理面板中,转到 扩展 → 扩展 → 模块
  5. 找到并安装自定义代码模块
  6. 配置模块并将您的 Asyntai 嵌入代码粘贴到页脚部分
  7. 保存并清除缓存

重要提示: 建议使用扩展而不是编辑核心文件,因为扩展不会在 OpenCart 更新时被覆盖。热门扩展包括市场上的"Custom Script in Header & Footer"。

备选方案:使用 addScript 方法(面向开发者)

对于开发者,OpenCart 3.x/4.x 提供了以编程方式添加脚本的方法:

  1. 打开 catalog/controller/common/footer.php
  2. $data['scripts'] = $this->document->getScripts('footer'); 之前添加以下行:
    $this->document->addScript('https://asyntai.com/static/js/chat-widget.js', 'footer');
  3. 对于 data 属性,您需要手动修改 footer.twig 来包含它,或在脚本循环之后添加内联 JavaScript

注意: 要使小部件正确使用 data 属性,模板方法更为简单,因为 addScript 方法不直接支持自定义属性。

步骤3:验证安装

保存更改并清除缓存后,在新的浏览器标签页或无痕窗口中访问您的商店。您应该会在右下角看到聊天小部件按钮。点击它以确保它能正常打开和运行。

看不到小部件? 请确保清除 OpenCart 的缓存。转到管理面板,点击右上角的蓝色齿轮图标,然后点击刷新按钮。也请尝试清除浏览器缓存或在无痕窗口中查看。如果您修改了错误的模板文件,请检查您的主题是否使用了您编辑的文件。