diff --git a/package.json b/package.json index 9ac0fe804..8c17aa123 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build:widget:chat-bubble": "NEXT_PUBLIC_DASHBOARD_URL=https://app.chaindesk.ai npx parcel build widgets/chat-bubble.tsx", "build:widget:chat-bubble:dev": "NEXT_PUBLIC_DASHBOARD_URL=http://localhost:3000 npx parcel build widgets/chat-bubble.tsx", "publish:package:chat-bubble": "npm run build:widget:chat-bubble && cp dist/chat-bubble* packages/chat-bubble/ && cd packages/chat-bubble && npm version patch && npm publish --access public", + "build:widget:prestashop": "cd widgets/prestashop && bash build.sh", "prisma:generate": "prisma generate", "prisma:migrate:dev": "dotenv -e .env.local -- prisma migrate dev", "prisma:migrate:prod": "dotenv -e .env.local -- prisma migrate deploy", diff --git a/pages/api/integrations/[name]/config-update.ts b/pages/api/integrations/[name]/config-update.ts index 992246093..9966e0f35 100644 --- a/pages/api/integrations/[name]/config-update.ts +++ b/pages/api/integrations/[name]/config-update.ts @@ -23,7 +23,7 @@ export const updateIntegrationConfig = async ( ) => { const session = req.session; const data = req.body as z.infer; - const name = req.query.name as 'wordpress' | 'shopify'; + const name = req.query.name as 'wordpress' | 'shopify' | 'prestashop'; const agent = await prisma.agent.findUnique({ where: { diff --git a/widgets/prestashop/.gitignore b/widgets/prestashop/.gitignore new file mode 100644 index 000000000..150c45692 --- /dev/null +++ b/widgets/prestashop/.gitignore @@ -0,0 +1 @@ +chaindesk.zip diff --git a/widgets/prestashop/build.sh b/widgets/prestashop/build.sh new file mode 100755 index 000000000..9e995b19f --- /dev/null +++ b/widgets/prestashop/build.sh @@ -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 \ No newline at end of file diff --git a/widgets/prestashop/chaindesk.php b/widgets/prestashop/chaindesk.php new file mode 100644 index 000000000..646a6c7d6 --- /dev/null +++ b/widgets/prestashop/chaindesk.php @@ -0,0 +1,103 @@ +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 = ''; + + $output .= ''; + + return $output; + } + } +} \ No newline at end of file diff --git a/widgets/prestashop/controllers/admin/AdminChainDeskController.php b/widgets/prestashop/controllers/admin/AdminChainDeskController.php new file mode 100644 index 000000000..a84ee8427 --- /dev/null +++ b/widgets/prestashop/controllers/admin/AdminChainDeskController.php @@ -0,0 +1,63 @@ +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; + } +} \ No newline at end of file diff --git a/widgets/prestashop/controllers/admin/index.php b/widgets/prestashop/controllers/admin/index.php new file mode 100644 index 000000000..1e5b19722 --- /dev/null +++ b/widgets/prestashop/controllers/admin/index.php @@ -0,0 +1 @@ +?> \ No newline at end of file diff --git a/widgets/prestashop/controllers/index.php b/widgets/prestashop/controllers/index.php new file mode 100644 index 000000000..1e5b19722 --- /dev/null +++ b/widgets/prestashop/controllers/index.php @@ -0,0 +1 @@ +?> \ No newline at end of file diff --git a/widgets/prestashop/docker-compose.yml b/widgets/prestashop/docker-compose.yml new file mode 100644 index 000000000..a308c8b90 --- /dev/null +++ b/widgets/prestashop/docker-compose.yml @@ -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: diff --git a/widgets/prestashop/index.php b/widgets/prestashop/index.php new file mode 100644 index 000000000..1e5b19722 --- /dev/null +++ b/widgets/prestashop/index.php @@ -0,0 +1 @@ +?> \ No newline at end of file diff --git a/widgets/prestashop/logo.png b/widgets/prestashop/logo.png new file mode 100644 index 000000000..9ee985d5b Binary files /dev/null and b/widgets/prestashop/logo.png differ diff --git a/widgets/prestashop/views/index.php b/widgets/prestashop/views/index.php new file mode 100644 index 000000000..e69de29bb diff --git a/widgets/prestashop/views/templates/admin/chaindesk.tpl b/widgets/prestashop/views/templates/admin/chaindesk.tpl new file mode 100644 index 000000000..08721467c --- /dev/null +++ b/widgets/prestashop/views/templates/admin/chaindesk.tpl @@ -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} +
+
+

{l s='Connected with Chaindesk.' d='chaindesk'}

+

{l s='You can now use Chaindesk from your homepage.' d='chaindesk'}

+ {l s='Reconfigure' d='chaindesk'} +
+{else} +
+

{l s='Connect with Chaindesk.ai' d='chaindesk'}

+

{l s='This link will redirect you to Chaindesk and configure your PrestaShop.' d='chaindesk'}

+ {l s='Connect with Chaindesk' d='chaindesk'} +
+
+{/if} diff --git a/widgets/prestashop/views/templates/admin/index.php b/widgets/prestashop/views/templates/admin/index.php new file mode 100644 index 000000000..e69de29bb diff --git a/widgets/prestashop/views/templates/index.php b/widgets/prestashop/views/templates/index.php new file mode 100644 index 000000000..e69de29bb