Added module configuration sending

This commit is contained in:
gleemand 2022-10-18 19:25:01 +02:00 committed by GitHub
parent 383ac58479
commit 683e00e851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 142 additions and 12 deletions

View File

@ -1,3 +1,6 @@
## v3.4.13
* Добавлена передача информации о модуле в CRM при его установке
## v3.4.12
* Исправлена ошибка получения настроек при деактивации модуля
* Оптимизирован процесс генерации Icml файла каталога

View File

@ -1 +1 @@
3.4.12
3.4.13

View File

@ -70,6 +70,11 @@ class RetailcrmSettings
{
if ($this->validator->validate(true)) {
$this->settings->updateValueAll();
if (array_key_exists('apiKey', $this->settings->getChanged())) {
$this->setClientId();
RetailCRM::updateCrmModuleState(Context::getContext()->shop->id);
}
}
$changed = $this->settings->getChanged();
@ -87,6 +92,18 @@ class RetailcrmSettings
];
}
private function setClientId()
{
$context = Context::getContext();
Configuration::updateValue(RetailCRM::CLIENT_ID, hash(
'sha256',
$context->shop->id . Configuration::get('PS_SHOP_DOMAIN')
));
return true;
}
private function updateConsultantCode()
{
$consultantCode = $this->consultantScript->getValue();

View File

@ -48,7 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
class RetailCRM extends Module
{
const VERSION = '3.4.12';
const VERSION = '3.4.13';
const API_URL = 'RETAILCRM_ADDRESS';
const API_KEY = 'RETAILCRM_API_TOKEN';
@ -295,7 +295,7 @@ class RetailCRM extends Module
}
}
public function uninstall()
public static function updateCrmModuleState($idShop, $active = true)
{
$apiUrl = Configuration::get(static::API_URL);
$apiKey = Configuration::get(static::API_KEY);
@ -303,8 +303,25 @@ class RetailCRM extends Module
if (!empty($apiUrl) && !empty($apiKey)) {
$api = new RetailcrmProxy($apiUrl, $apiKey);
$clientId = Configuration::get(static::CLIENT_ID);
$this->integrationModule($api, $clientId, false);
$clientId = Configuration::get(static::CLIENT_ID, null, null, $idShop);
self::integrationModule($api, $clientId, $active);
}
return true;
}
public function uninstall()
{
if (Shop::isFeatureActive()) {
$shops = Shop::getShops();
} else {
$shops[] = Shop::getContext();
}
foreach ($shops as $shop) {
if (isset($shop['id_shop'])) {
self::updateCrmModuleState($shop['id_shop'], false);
}
}
return parent::uninstall()
@ -347,6 +364,10 @@ class RetailCRM extends Module
public function enable($force_all = false)
{
$context = Context::getContext();
self::updateCrmModuleState($context->shop->id);
return parent::enable($force_all)
&& $this->installTab()
;
@ -358,6 +379,10 @@ class RetailCRM extends Module
return false;
}
$context = Shop::getContext();
self::updateCrmModuleState($context->shop->id, false);
$sql = 'SELECT COUNT(`id_shop`) FROM `' . _DB_PREFIX_ . 'module_shop`
WHERE `id_module` = ' . (int) $this->id;
@ -782,13 +807,14 @@ class RetailCRM extends Module
*
* @return bool
*/
private function integrationModule($apiClient, $clientId, $active = true)
public static function integrationModule($apiClient, $clientId, $active = true)
{
$scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$context = Context::getContext();
$logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b845ce986911-prestashop2.svg';
$integrationCode = 'prestashop';
$name = 'PrestaShop';
$accountUrl = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$accountUrl = $context->link->getAdminLink('AdminModules') . '&configure=retailcrm';
$configuration = [
'clientId' => $clientId,
'code' => $integrationCode . '-' . $clientId,

View File

@ -70,11 +70,11 @@ function upgrade_module_3_3_2($module)
}
if ($isMultiStoreActive) {
$oldFile = _PS_ROOT_DIR_ . '/' . 'retailcrm_' . $shop['id_shop'] . '.xml';
$newFile = _PS_ROOT_DIR_ . '/' . 'simla_' . $shop['id_shop'] . '.xml';
$oldFile = _PS_ROOT_DIR_ . '/retailcrm_' . $shop['id_shop'] . '.xml';
$newFile = _PS_ROOT_DIR_ . '/simla_' . $shop['id_shop'] . '.xml';
} else {
$oldFile = _PS_ROOT_DIR_ . '/' . 'retailcrm.xml';
$newFile = _PS_ROOT_DIR_ . '/' . 'simla.xml';
$oldFile = _PS_ROOT_DIR_ . '/retailcrm.xml';
$newFile = _PS_ROOT_DIR_ . '/simla.xml';
}
if (file_exists($oldFile) && !file_exists($newFile)) {

View File

@ -0,0 +1,84 @@
<?php
/**
* MIT License
*
* Copyright (c) 2021 DIGITAL RETAIL TECHNOLOGIES SL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL
* @license https://opensource.org/licenses/MIT The MIT License
*
* Don't forget to prefix your containers with your own identifier
* to avoid any conflicts with others containers.
*/
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Upgrade module to version 3.4.13
*
* @param \RetailCRM $module
*
* @return bool
*/
function upgrade_module_3_4_13($module)
{
if ('retailcrm' != $module->name) {
return false;
}
if (Shop::isFeatureActive()) {
$shops = Shop::getShops();
} else {
$shops[] = ['id_shop' => Shop::getContext()->shop->id];
}
foreach ($shops as $shop) {
if (isset($shop['id_shop'])) {
$idShop = (int) $shop['id_shop'];
if (
!Configuration::hasKey($module::CLIENT_ID, null, null, $idShop)
|| empty(Configuration::get($module::CLIENT_ID, null, null, $idShop))
) {
Configuration::updateValue(
$module::CLIENT_ID,
hash('sha256', $idShop . Configuration::get('PS_SHOP_DOMAIN')),
false,
null,
$idShop
);
}
$module::updateCrmModuleState($idShop);
}
}
return true;
}