-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:138-prestashop-integration (#140)
- Loading branch information
Showing
15 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chaindesk.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
rm -rf chaindesk chaindesk.zip && \ | ||
mkdir -p chaindesk && \ | ||
cp -r chaindesk.php controllers docker-compose.yml entrypoint.sh index.php logo.png views chaindesk && \ | ||
zip -r chaindesk.zip chaindesk && \ | ||
rm -rf chaindesk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
/** | ||
* chaindesk.php | ||
* | ||
* This file is the main entry point for the ChainDesk module in PrestaShop. | ||
* It initializes and configures the module. | ||
* | ||
* @author chaindesk | ||
* @copyright chaindesk | ||
* @license MIT License | ||
*/ | ||
|
||
if (!defined('_PS_VERSION_')) { | ||
exit; | ||
} | ||
|
||
class Chaindesk extends Module | ||
{ | ||
public function __construct() | ||
{ | ||
$this->name = 'chaindesk'; | ||
$this->tab = 'front_office_features'; | ||
$this->version = '1.0.0'; | ||
$this->author = 'chaindesk'; | ||
$this->need_instance = 0; | ||
$this->ps_versions_compliancy = [ | ||
'min' => '1.7.0.0', | ||
'max' => '8.99.99', | ||
]; | ||
$this->bootstrap = true; | ||
|
||
parent::__construct(); | ||
|
||
$this->displayName = $this->l('chaindesk'); | ||
$this->description = $this->l('chaindesk.'); | ||
|
||
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); | ||
|
||
if (!Configuration::get('MYMODULE_NAME')) { | ||
$this->warning = $this->l('No name provided'); | ||
} | ||
} | ||
|
||
public function install() | ||
{ | ||
if (Shop::isFeatureActive()) { | ||
Shop::setContext(Shop::CONTEXT_ALL); | ||
} | ||
|
||
return parent::install() && | ||
$this->registerHooks() && | ||
$this->installTab() && | ||
Configuration::updateValue('MYMODULE_NAME', 'chaindesk'); | ||
} | ||
|
||
private function registerHooks() | ||
{ | ||
return $this->registerHook('displayHeader') && $this->registerHook('hookHeader'); | ||
} | ||
|
||
public function installTab() | ||
{ | ||
$tab = new Tab(); | ||
$tab->active = 1; | ||
$tab->class_name = 'AdminChainDesk'; | ||
|
||
// Add a blank line before the following line to adhere to the rule | ||
$tab->name = []; | ||
|
||
foreach (Language::getLanguages(true) as $lang) { | ||
$tab->name[$lang['id_lang']] = 'Chaindesk'; | ||
} | ||
|
||
$tab->id_parent = (int) Tab::getIdFromClassName('AdminAdmin'); | ||
$tab->module = $this->name; | ||
return $tab->add(); | ||
} | ||
|
||
public function uninstall() | ||
{ | ||
return parent::uninstall(); | ||
} | ||
|
||
public function hookHeader() | ||
{ | ||
// Sanitize and validate the agent ID. | ||
$agentId = Configuration::get('CHAINDESK_AGENT_ID'); | ||
$agentId = Tools::safeOutput($agentId); | ||
|
||
if (!empty($agentId) && !Tools::isSubmit('chaindesk_script_enqueued')) { | ||
$output = '<script | ||
data-cfasync="false" | ||
data-name="databerry-chat-bubble" | ||
id="' . $agentId . '" | ||
src="https://cdn.jsdelivr.net/npm/@databerry/chat-bubble@latest" | ||
></script>'; | ||
|
||
$output .= '<script>var chaindesk_script_enqueued = true;</script>'; | ||
|
||
return $output; | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
widgets/prestashop/controllers/admin/AdminChainDeskController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* AdminChainDeskController.php | ||
* | ||
* This file contains the AdminChainDeskController class, which is responsible for handling | ||
* administrative functions related to the ChainDesk module in PrestaShop. | ||
* | ||
* @author chaindesk | ||
* @copyright chaindesk | ||
* @license MIT License | ||
*/ | ||
|
||
if (!defined('_PS_VERSION_')) { | ||
exit; | ||
} | ||
|
||
class AdminChainDeskController extends ModuleAdminController | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function initContent() | ||
{ | ||
$agentId = $this->getAgentIdFromUrl(); | ||
|
||
$this->assignTemplateData($agentId); | ||
|
||
$this->content .= $this->context->smarty->fetch( | ||
$this->getTemplatePath() . 'chaindesk.tpl' | ||
); | ||
|
||
parent::initContent(); | ||
} | ||
|
||
private function getAgentIdFromUrl() | ||
{ | ||
if (Tools::getIsset('agentId')) { | ||
$sanitizedAgentId = pSQL(Tools::getValue('agentId')); | ||
Configuration::updateValue('CHAINDESK_AGENT_ID', $sanitizedAgentId); | ||
return $sanitizedAgentId; | ||
} | ||
|
||
return Configuration::get('CHAINDESK_AGENT_ID'); | ||
} | ||
|
||
private function assignTemplateData($agentId) | ||
{ | ||
$this->context->smarty->assign([ | ||
'add_to_chaindesk_link' => $this->generateChainDeskLink(), | ||
'agentId' => $agentId, | ||
]); | ||
} | ||
|
||
private function generateChainDeskLink() | ||
{ | ||
$agentId = Configuration::get('CHAINDESK_AGENT_ID'); | ||
$http_callback = Tools::getShopDomainSsl(true, true) . $_SERVER['REQUEST_URI']; | ||
$base_url = 'https://app.chaindesk.ai'; // Use single quotes for simple strings | ||
return $base_url . '/integrations/prestashop/config?callback=' . urlencode($http_callback) . '&siteurl=' . urlencode(Tools::getShopDomainSsl(true, true)) . '&agentId=' . $agentId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
version: "3.1" | ||
services: | ||
mysql: | ||
container_name: chaindesk_prestashop_db | ||
image: mysql:5.7 | ||
volumes: | ||
- db:/var/lib/mysql | ||
restart: unless-stopped | ||
environment: | ||
MYSQL_ROOT_PASSWORD: admin | ||
MYSQL_DATABASE: prestashop | ||
networks: | ||
- prestashop_network | ||
prestashop: | ||
container_name: prestashop | ||
image: prestashop/prestashop | ||
restart: unless-stopped | ||
depends_on: | ||
- mysql | ||
ports: | ||
- 8080:80 | ||
environment: | ||
DB_SERVER: chaindesk_prestashop_db | ||
DB_NAME: prestashop | ||
DB_USER: root | ||
DB_PASSWD: admin | ||
volumes: | ||
- prestashop:/var/www/html | ||
- .:/var/www/html/modules/chaindesk | ||
networks: | ||
- prestashop_network | ||
volumes: | ||
db: | ||
prestashop: | ||
networks: | ||
prestashop_network: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
?> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{* | ||
* chaindesk.tpl | ||
* | ||
* This template file is used for displaying Chaindesk-related content in PrestaShop's admin area. | ||
* | ||
* @author chaindesk | ||
* @copyright chaindesk | ||
* @license MIT License | ||
*} | ||
|
||
{if $agentId} | ||
<div class="bootstrap container"> | ||
<div class="alert alert-success text-center mt-2"> | ||
<h2>{l s='Connected with Chaindesk.' d='chaindesk'}</h2> | ||
<p>{l s='You can now use Chaindesk from your homepage.' d='chaindesk'}</p> | ||
<a href="{$add_to_chaindesk_link}" class="btn btn-primary pointer ">{l s='Reconfigure' d='chaindesk'}</a> | ||
</div> | ||
{else} | ||
<div class="alert alert-info"> | ||
<h2>{l s='Connect with Chaindesk.ai' d='chaindesk'}</h2> | ||
<p>{l s='This link will redirect you to Chaindesk and configure your PrestaShop.' d='chaindesk'}</p> | ||
<a href="{$add_to_chaindesk_link}" class="btn btn-primary">{l s='Connect with Chaindesk' d='chaindesk'}</a> | ||
</div> | ||
</div> | ||
{/if} |
Empty file.
Empty file.
0e0320d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dashboard – ./
dashboard-nu-tawny.vercel.app
*.chaindesk.chat
databerry.chat
*.chaindesk.ai
www.chaindesk.ai
app.chaindesk.ai
*.databerry.ai
databerry.ai
chaindesk.ai
www.chatbotgpt.ai
chaindesk.chat
www.databerry.ai
app.databerry.ai
bestaichatbot.org
dashboard-git-main-databerry.vercel.app
dashboard-databerry.vercel.app
www.bestaichatbot.org