Skip to content

Commit

Permalink
Merge pull request #10 from Invertus/master
Browse files Browse the repository at this point in the history
Compatibility with PS8
  • Loading branch information
vorcigernix authored Sep 25, 2023
2 parents 43478d0 + 5b4fe7a commit 52ebce8
Show file tree
Hide file tree
Showing 118 changed files with 497 additions and 2,502 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
vendor
config*.xml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion smartsupp/classes/index.php → classes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Smartsupp Live Chat
* Plugin URI: http://www.smartsupp.com
* Description: Adds Smartsupp Live Chat code to PrestaShop.
* Version: 2.1.9
* Version: 2.2.0
* Author: Smartsupp
* Author URI: http://www.smartsupp.com
* Text Domain: smartsupp
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Smartsupp Live Chat
* Plugin URI: http://www.smartsupp.com
* Description: Adds Smartsupp Live Chat code to PrestaShop.
* Version: 2.1.9
* Version: 2.2.0
* Text Domain: smartsupp
* Author: Smartsupp
* Author URI: http://www.smartsupp.com
Expand All @@ -23,54 +23,73 @@

class AdminSmartsuppAjaxController extends ModuleAdminController
{
const FILE_NAME = 'AdminSmartsuppAjaxController';
public $ssl = true;
private $partnerKey = 'h4w6t8hln9';
private $response = [];

public function init()
{
$api = new Api();

switch (Tools::getValue('action')) {
case 'login':
$response = $api->login(array(
$this->response = $api->login([
'email' => Tools::getValue('email'),
'password' => Tools::getValue('password'),
'platform' => 'Prestashop ' . _PS_VERSION_,
));

Configuration::updateValue('SMARTSUPP_KEY', $response['account']['key']);
Configuration::updateValue('SMARTSUPP_EMAIL', Tools::getValue('email'));
]);
$this->updateCredentials();
break;
case 'create':
$response = $api->create(array(
$this->response = $api->create([
'email' => Tools::getValue('email'),
'password' => Tools::getValue('password'),
'partnerKey' => $this->partnerKey,
'consentTerms' => 1,
'platform' => 'Prestashop ' . _PS_VERSION_,
));

Configuration::updateValue('SMARTSUPP_KEY', $response['account']['key']);
Configuration::updateValue('SMARTSUPP_EMAIL', Tools::getValue('email'));
]);
$this->updateCredentials();
break;
case 'deactivate':
Configuration::updateValue('SMARTSUPP_KEY', '');
Configuration::updateValue('SMARTSUPP_EMAIL', '');
break;
}

if (isset($response) && isset($response['error'])) {
Configuration::updateValue('SMARTSUPP_KEY', '');
Configuration::updateValue('SMARTSUPP_EMAIL', '');
}

header('Content-Type: application/json');
die(Tools::jsonEncode(array(
'key' => Configuration::get('SMARTSUPP_KEY'),
'email' => Configuration::get('SMARTSUPP_EMAIL'),
'error' => $response['error'],
'message' => $response['message'],
'hint' => $response['hint']
)));

$responseData = [
'key' => Configuration::get('SMARTSUPP_KEY'),
'email' => Configuration::get('SMARTSUPP_EMAIL'),
'error' => isset($this->response['error']) ? $this->response['error'] : null,
'message' => isset($this->response['message']) ? $this->response['message'] : null,
];

$responseData = array_filter($responseData, function ($val) {
return $val !== null;
});

die(json_encode($responseData));
}


/**
* @return void
*/
private function updateCredentials()
{
if (isset($this->response['account']['key'])) {
Configuration::updateValue('SMARTSUPP_KEY', $this->response['account']['key']);
Configuration::updateValue('SMARTSUPP_EMAIL', Tools::getValue('email'));

return;
}

$this->response['error'] = isset($this->response['error']) ? $this->response['error'] : $this->module->l('Unknown Error Occurred', self::FILE_NAME);
$this->response['message'] = isset($this->response['message']) ? $this->response['message'] : $this->module->l('Unknown Error Occurred', self::FILE_NAME);

Configuration::updateValue('SMARTSUPP_KEY', '');
Configuration::updateValue('SMARTSUPP_EMAIL', '');
}
}
2 changes: 1 addition & 1 deletion smartsupp/index.php → controllers/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Smartsupp Live Chat
* Plugin URI: http://www.smartsupp.com
* Description: Adds Smartsupp Live Chat code to PrestaShop.
* Version: 2.1.9
* Version: 2.2.0
* Author: Smartsupp
* Author URI: http://www.smartsupp.com
* Text Domain: smartsupp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Smartsupp Live Chat
* Plugin URI: http://www.smartsupp.com
* Description: Adds Smartsupp Live Chat code to PrestaShop.
* Version: 2.1.9
* Version: 2.2.0
* Author: Smartsupp
* Author URI: http://www.smartsupp.com
* Text Domain: smartsupp
Expand Down
2 changes: 1 addition & 1 deletion smartsupp/controllers/index.php → index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Smartsupp Live Chat
* Plugin URI: http://www.smartsupp.com
* Description: Adds Smartsupp Live Chat code to PrestaShop.
* Version: 2.1.9
* Version: 2.2.0
* Author: Smartsupp
* Author URI: http://www.smartsupp.com
* Text Domain: smartsupp
Expand Down
File renamed without changes
File renamed without changes
86 changes: 60 additions & 26 deletions smartsupp/smartsupp.php → smartsupp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
* Plugin Name: Smartsupp Live Chat
* Plugin URI: http://www.smartsupp.com
* Description: Adds Smartsupp Live Chat code to PrestaShop.
* Version: 2.1.9
* Version: 2.2.0
* Author: Smartsupp
* Author URI: http://www.smartsupp.com
* Text Domain: smartsupp
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/

use Smartsupp\LiveChat\Utility\VersionUtility;

if (!defined('_PS_VERSION_')) {
exit;
}

require dirname(__FILE__) . '/vendor/autoload.php';

class Smartsupp extends Module
{
public function __construct()
{
$this->name = 'smartsupp';
$this->tab = 'advertising_marketing';
$this->version = '2.1.9';
$this->version = '2.2.0';
$this->author = 'Smartsupp';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
Expand All @@ -40,18 +40,20 @@ public function __construct()

parent::__construct();

$this->displayName = $this->l('Smartsupp Live Chat');
$this->description = $this->l('Smartsupp combines live chat and chatbots to save your time.');
$this->displayName = $this->l('Smartsupp Live Chat & AI Chatbots');
$this->description = $this->l('Smartsupp is your personal online shopping assistant, built to increase conversion rates and sales via visitor engagement in real-time, at the right time.');

$confirm = $this->l('Are you sure you want to uninstall Smartsupp Live Chat? ');
$confirm .= $this->l('You will lose all the data related to this module.');

$confirm = 'Are you sure you want to uninstall Smartsupp Live Chat? ';
$confirm .= 'You will lose all the data related to this module.';

$this->confirmUninstall = $this->l($confirm);

if (version_compare(_PS_VERSION_, '1.5', '<')) {
include _PS_MODULE_DIR_ . $this->name . '/backward_compatibility/backward.php';
}

$this->autoload();

if (!Configuration::get('SMARTSUPP_KEY')) {
$this->warning = $this->l('No Smartsupp key provided.');
}
Expand All @@ -73,10 +75,15 @@ public function install()
$tab->id_parent = -1;
$tab->module = $this->name;

if (VersionUtility::isPsVersionGreaterThan('1.6')) {
$this->registerHook('displayBackOfficeHeader');
} else {
$this->registerHook('backOfficeHeader');
}

if (!$tab->add()
|| !parent::install()
|| !$this->registerHook('header')
|| !$this->registerHook('backOfficeHeader')
|| !Configuration::updateValue('SMARTSUPP_KEY', '')
|| !Configuration::updateValue('SMARTSUPP_EMAIL', '')
|| !Configuration::updateValue('SMARTSUPP_CUSTOMER_ID', '1')
Expand All @@ -91,21 +98,36 @@ public function install()
return false;
}

if (VersionUtility::isPsVersionGreaterThan('1.6')) {
$this->registerHook('displayBackOfficeHeader');
} else {
$this->registerHook('backOfficeHeader');
}

return true;
}

public function uninstall()
{
$id_tab = (int) Tab::getIdFromClassName('AdminSmartsuppAjax');
if (VersionUtility::isPsVersionGreaterOrEqualTo('1.7.1')) {
$id_tab = $this->get('prestashop.core.admin.tab.repository')->findOneIdByClassName('AdminSmartsuppAjax');
} else {
$id_tab = (int) Tab::getIdFromClassName('AdminSmartsuppAjax');
}

if ($id_tab) {
$tab = new Tab($id_tab);
$tab->delete();
}

if (VersionUtility::isPsVersionGreaterThan('1.6')) {
$this->unregisterHook('displayBackOfficeHeader');
} else {
$this->unregisterHook('backOfficeHeader');
}

if (!parent::uninstall()
|| !$this->unregisterHook('header')
|| !$this->unregisterHook('backOfficeHeader')
|| !Configuration::deleteByName('SMARTSUPP_KEY')
|| !Configuration::deleteByName('SMARTSUPP_EMAIL')
|| !Configuration::deleteByName('SMARTSUPP_CUSTOMER_ID', '')
Expand Down Expand Up @@ -159,8 +181,8 @@ public function displayForm()

$fields_form = array();

$fields_desc = 'Don\'t put the chat code here - this box is for ';
$fields_desc .= '(optional) advanced customizations via #.';
$fields_desc = $this->l('Don\'t put the chat code here - this box is for ');
$fields_desc .= $this->l('(optional) advanced customizations via ') . '#.';

$fields_form[0]['form'] = array(
'legend' => array(
Expand Down Expand Up @@ -312,20 +334,27 @@ public function hookHeader()
public function hookBackOfficeHeader()
{
$js = '';

if (strcmp(Tools::getValue('configure'), $this->name) === 0) {
$path = $this->_path;
if (version_compare(_PS_VERSION_, '1.6', '>=') == true) {
$this->context->controller->addJquery();
$this->context->controller->addJs($path . 'views/js/smartsupp.js');
$this->context->controller->addCSS($path . 'views/css/smartsupp.css');
if (version_compare(_PS_VERSION_, '1.6', '<') == true) {
$this->context->controller->addCSS($path . 'views/css/smartsupp-nobootstrap.css');
}
} else {
$js .= '<script type="text/javascript" src="'.$path.'views/js/smartsupp.js"></script>';
$js .= '<link rel="stylesheet" href="'.$path.'views/css/smartsupp.css" type="text/css" />';
$js .= '<link rel="stylesheet" href="'.$path.'views/css/smartsupp-nobootstrap.css" type="text/css" />';
}
$js .= '<script type="text/javascript" src="' . $path . 'views/js/smartsupp.js"></script>';
$js .= '<link rel="stylesheet" href="' . $path . 'views/css/smartsupp.css" type="text/css" />';
$js .= '<link rel="stylesheet" href="' . $path . 'views/css/smartsupp-nobootstrap.css" type="text/css" />';
}

return $js;
}

public function hookDisplayBackOfficeHeader()
{
$js = '';

if (strcmp(Tools::getValue('configure'), $this->name) === 0) {
$path = $this->_path;
$this->context->controller->addJquery();
$this->context->controller->addJs($path . 'views/js/smartsupp.js');
$this->context->controller->addCSS($path . 'views/css/smartsupp.css');
$this->context->controller->addCSS($path . 'views/css/smartsupp-nobootstrap.css');
}

return $js;
Expand All @@ -335,4 +364,9 @@ protected function getAdminDir()
{
return basename(_PS_ADMIN_DIR_);
}

private function autoload()
{
include_once "{$this->getLocalPath()}vendor/autoload.php";
}
}
30 changes: 0 additions & 30 deletions smartsupp/translations/index.php

This file was deleted.

7 changes: 0 additions & 7 deletions smartsupp/vendor/autoload.php

This file was deleted.

Loading

0 comments on commit 52ebce8

Please sign in to comment.