Updated frontend to use Vuex store for settings and references. Some refactoring

This commit is contained in:
max-baranikov 2022-06-20 16:03:31 +03:00 committed by GitHub
parent dde673bf3b
commit 68e1e50797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 292 additions and 154 deletions

View file

@ -1,3 +1,9 @@
## v3.4.4
* Улучшена горячая подгрузка данных на странице настроек модуля
* Исправлены ошибки при отсутствующем или невалидном api-ключе
* Рефакторинг контроллера RetailcrmSettingsController. Добавление контроллеров RetailcrmReferencesController и RetailcrmCatalogController
* Рефакторинг frontend части
## v3.4.3
* Добавлена валидация данных для подключения к CRM
* Исправлен пропуск товаров корневой категории при генерации ICML

View file

@ -1 +1 @@
3.4.3
3.4.4

View file

@ -0,0 +1,65 @@
<?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.
*/
require_once dirname(__FILE__) . '/../../bootstrap.php';
class RetailcrmCatalogController extends RetailcrmAdminPostAbstractController
{
protected function postHandler()
{
if (!Tools::getIsset('generate') && !Tools::getIsset('updateUrl')) {
throw new Exception('Invalid request data');
}
$jobName = (Tools::getIsset('generate') ? RetailcrmIcmlEvent::class : RetailcrmIcmlUpdateUrlEvent::class);
$result = RetailcrmJobManager::execManualJob($jobName);
return [
'success' => true,
'result' => $result,
];
}
protected function getHandler()
{
return [
'success' => true,
'catalog' => RetailcrmSettingsHelper::getCatalogInfo(),
];
}
}

View file

@ -0,0 +1,94 @@
<?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.
*/
require_once dirname(__FILE__) . '/../../bootstrap.php';
class RetailcrmReferencesController extends RetailcrmAdminPostAbstractController
{
protected function getHandler()
{
if (Tools::getIsset('delivery') || Tools::getIsset('payment') || Tools::getIsset('status')) {
return $this->getSpecifiedReferences();
}
return [
'success' => true,
'references' => RetailcrmSettingsHelper::getReferences(),
];
}
/**
* @throws Exception
*/
protected function getSpecifiedReferences()
{
$references = [];
$errors = [];
$client = RetailcrmTools::getApiClient();
if (null === $client) {
$errors[] = 'errors.connect';
}
$moduleReferences = new RetailcrmReferences($client);
switch (true) {
case Tools::getIsset('delivery'):
$references['deliveryTypesCRM'] = $moduleReferences->getApiDeliveryTypes();
break;
case Tools::getIsset('payment'):
$references['paymentTypesCRM'] = $moduleReferences->getApiPaymentTypes();
break;
case Tools::getIsset('status'):
$references['statusesCRM'] = $moduleReferences->getApiStatusesWithGroup();
break;
default:
throw new Exception('Invalid request data');
}
return [
'success' => true,
'references' => $references,
'errors' => $errors,
];
}
}

View file

@ -49,33 +49,9 @@ class RetailcrmSettingsController extends RetailcrmAdminPostAbstractController
protected function getHandler()
{
if (null === $this->module->reference) {
return [
'success' => false,
'errorMsg' => 'Set api key & url first',
];
}
$result = [
return [
'success' => true,
'settings' => RetailcrmSettingsHelper::getSettings(),
];
if (Tools::getIsset('catalog')) {
$result['catalog'] = RetailcrmSettingsHelper::getIcmlFileInfo();
}
if (Tools::getIsset('delivery')) {
$result['delivery'] = $this->module->reference->getApiDeliveryTypes(
); // todo replace with helper function
}
if (Tools::getIsset('payment')) {
$result['payment'] = $this->module->reference->getApiPaymentTypes(
); // todo replace with helper function
}
if (Tools::getIsset('status')) {
$result['status'] = $this->module->reference->getApiStatusesWithGroup(
); // todo replace with helper function
}
return $result;
}
}

View file

@ -107,7 +107,7 @@ class RetailcrmExportOrdersHelper
$totalCount = Db::getInstance()->getValue($sqlPagination);
$pagination = [
'totalCount' => $totalCount,
'totalCount' => (int) $totalCount,
'currentPage' => $page,
'totalPageCount' => ceil($totalCount / self::ROWS_PER_PAGE),
];

View file

@ -172,7 +172,10 @@ class RetailcrmReferences
$request = $this->api->statusesList();
$requestGroups = $this->api->statusGroupsList();
if (!$request || !$requestGroups) {
if (!($request instanceof RetailcrmApiResponse) || !$request->isSuccessful()
|| !($requestGroups instanceof RetailcrmApiResponse)
|| !$requestGroups->isSuccessful()
) {
return [];
}
@ -229,7 +232,7 @@ class RetailcrmReferences
$crmDeliveryTypes = [];
$request = $this->api->deliveryTypesList();
if (!$request) {
if (!($request instanceof RetailcrmApiResponse) || !$request->isSuccessful()) {
return [];
}
@ -261,7 +264,7 @@ class RetailcrmReferences
$crmStatusTypes = [];
$request = $this->api->statusesList();
if (!$request) {
if (!($request instanceof RetailcrmApiResponse) || !$request->isSuccessful()) {
return [];
}
@ -296,7 +299,7 @@ class RetailcrmReferences
$crmPaymentTypes = [];
$request = $this->api->paymentTypesList();
if (!$request) {
if (!($request instanceof RetailcrmApiResponse) || !$request->isSuccessful()) {
return [];
}

View file

@ -95,7 +95,7 @@ class RetailcrmSettingsHelper
return $fileNames;
}
public static function getIcmlFileInfo()
public static function getCatalogInfo()
{
$icmlInfo = json_decode((string) Configuration::get(RetailcrmCatalogHelper::ICML_INFO_NAME), true);
@ -146,4 +146,33 @@ class RetailcrmSettingsHelper
return $icmlInfo;
}
public static function getSettings()
{
$settings = new RetailcrmSettingsItems();
$result = $settings->getValueStoredAll();
$consultantScript = new RetailcrmSettingsItemHtml('consultantScript', RetailCRM::CONSULTANT_SCRIPT);
$result['consultantScript'] = $consultantScript->getValueStored();
return $result;
}
public static function getReferences()
{
$client = RetailcrmTools::getApiClient();
$moduleReferences = new RetailcrmReferences($client);
return [
'deliveryTypesCMS' => $moduleReferences->getDeliveryTypes(),
'deliveryTypesCRM' => $moduleReferences->getApiDeliveryTypes(),
'paymentTypesCMS' => $moduleReferences->getSystemPaymentModules(),
'paymentTypesCRM' => $moduleReferences->getApiPaymentTypes(),
'statusesCMS' => $moduleReferences->getStatuses(),
'statusesCRM' => $moduleReferences->getApiStatusesWithGroup(),
'cartsDelays' => RetailcrmSettingsHelper::getCartDelays(),
'linkPayments' => RetailcrmTools::getAdminControllerUrl(AdminPaymentPreferencesController::class),
'linkOrders' => RetailcrmTools::getAdminControllerUrl(AdminOrdersController::class),
];
}
}

View file

@ -131,6 +131,17 @@ class RetailcrmSettingsItems
return $this->settings[$key]->getValueStored();
}
public function getValueStoredAll()
{
$result = [];
foreach ($this->settings as $key => $item) {
$result[$key] = $item->getValueStored();
}
return $result;
}
public function getValueWithStored($key)
{
$this->checkKey($key);

View file

@ -38,127 +38,22 @@
class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
{
/**
* @var RetailcrmSettingsItems
*/
private $settings;
/**
* @var RetailcrmSettingsItemHtml
*/
private $consultantScript;
/**
* RetailcrmSettingsTemplate constructor.
*
* @param \Module $module
* @param $smarty
* @param $assets
*/
public function __construct(Module $module, $smarty, $assets)
{
parent::__construct($module, $smarty, $assets);
$this->settings = new RetailcrmSettingsItems();
$this->consultantScript = new RetailcrmSettingsItemHtml('consultantScript', RetailCRM::CONSULTANT_SCRIPT);
}
protected function buildParams()
{
$this->data = [
'assets' => $this->assets,
'appData' => $this->getParams(),
];
}
/**
* Build params for template
*
* @return mixed
*/
protected function getParams()
{
$deliveryTypesCMS = $this->module->reference->getDeliveryTypes();
$paymentTypesCMS = $this->module->reference->getSystemPaymentModules();
$statusesCMS = $this->module->reference->getStatuses();
$deliveryTypesCRM = $this->module->reference->getApiDeliveryTypes();
$paymentTypesCRM = $this->module->reference->getApiPaymentTypes();
$statusesCRM = $this->module->reference->getApiStatusesWithGroup();
return [
'locale' => $this->getCurrentLanguageISO(),
'controller' => [
'settings' => RetailcrmTools::getAdminControllerUrl(RetailcrmSettingsController::class),
'payments' => RetailcrmTools::getAdminControllerUrl(AdminPaymentPreferencesController::class),
'orders' => RetailcrmTools::getAdminControllerUrl(RetailcrmOrdersController::class),
'export' => RetailcrmTools::getAdminControllerUrl(RetailcrmExportController::class),
'link' => RetailcrmTools::getAdminControllerUrl(AdminOrdersController::class),
'jobs' => RetailcrmTools::getAdminControllerUrl(RetailcrmJobsController::class),
'logs' => RetailcrmTools::getAdminControllerUrl(RetailcrmLogsController::class),
],
'main' => [
'connection' => [
'url' => $this->settings->getValueStored('url'),
'apiKey' => $this->settings->getValueStored('apiKey'),
'appData' => [
'locale' => $this->getCurrentLanguageISO(),
'debug' => RetailcrmTools::isDebug(),
'routes' => [
'settings' => RetailcrmTools::getAdminControllerUrl(RetailcrmSettingsController::class),
'references' => RetailcrmTools::getAdminControllerUrl(RetailcrmReferencesController::class),
'catalog' => RetailcrmTools::getAdminControllerUrl(RetailcrmCatalogController::class),
'orders' => RetailcrmTools::getAdminControllerUrl(RetailcrmOrdersController::class),
'export' => RetailcrmTools::getAdminControllerUrl(RetailcrmExportController::class),
'jobs' => RetailcrmTools::getAdminControllerUrl(RetailcrmJobsController::class),
'logs' => RetailcrmTools::getAdminControllerUrl(RetailcrmLogsController::class),
],
'delivery' => [
'setting' => $this->settings->getValueStored('delivery'),
'cms' => $deliveryTypesCMS,
'crm' => $deliveryTypesCRM,
],
'payment' => [
'setting' => $this->settings->getValueStored('payment'),
'cms' => $paymentTypesCMS,
'crm' => $paymentTypesCRM,
],
'status' => [
'setting' => $this->settings->getValueStored('status'),
'cms' => $statusesCMS,
'crm' => $statusesCRM,
],
],
'additional' => [
'settings' => [
'corporate' => $this->settings->getValueStored('enableCorporate'),
'numberSend' => $this->settings->getValueStored('enableOrderNumberSending'),
'numberReceive' => $this->settings->getValueStored('enableOrderNumberReceiving'),
'webJobs' => $this->settings->getValueStored('webJobs'),
'debug' => $this->settings->getValueStored('debugMode'),
],
'history' => [
'enabled' => $this->settings->getValueStored('enableHistoryUploads'),
'deliveryDefault' => $this->settings->getValueStored('deliveryDefault'),
'paymentDefault' => $this->settings->getValueStored('paymentDefault'),
'delivery' => $deliveryTypesCMS,
'payment' => $paymentTypesCMS,
],
'stocks' => [
'enabled' => $this->settings->getValueStored('enableBalancesReceiving'),
'statuses' => $this->settings->getValueStored('outOfStockStatus'),
],
'carts' => [
'synchronizeCartsActive' => $this->settings->getValueStored('synchronizeCartsActive'),
'synchronizedCartStatus' => $this->settings->getValueStored('synchronizedCartStatus'),
'synchronizedCartDelay' => $this->settings->getValueStored('synchronizedCartDelay'),
'delays' => RetailcrmSettingsHelper::getCartDelays(),
],
'collector' => [
'collectorActive' => $this->settings->getValueStored('collectorActive'),
'collectorKey' => $this->settings->getValueStored('collectorKey'),
],
'consultant' => [
'consultantScript' => $this->consultantScript->getValueStored(),
],
],
'catalog' => [
'info' => RetailcrmSettingsHelper::getIcmlFileInfo(),
'generateName' => RetailcrmIcmlEvent::class,
'updateURLName' => RetailcrmIcmlUpdateUrlEvent::class,
],
'advanced' => [
'jobs' => RetailcrmSettingsHelper::getJobsInfo(),
'logs' => RetailcrmSettingsHelper::getLogFilesInfo(),
],
];
}

View file

@ -118,6 +118,8 @@ class RetailCRM extends Module
= [
RetailcrmSettingsLinkController::class,
RetailcrmSettingsController::class,
RetailcrmReferencesController::class,
RetailcrmCatalogController::class,
RetailcrmJobsController::class,
RetailcrmLogsController::class,
RetailcrmOrdersController::class,
@ -148,7 +150,7 @@ class RetailCRM extends Module
{
$this->name = 'retailcrm';
$this->tab = 'export';
$this->version = '3.4.3';
$this->version = '3.4.4';
$this->author = 'DIGITAL RETAIL TECHNOLOGIES SL';
$this->displayName = $this->l('Simla.com');
$this->description = $this->l('Integration module for Simla.com');

View file

@ -0,0 +1,57 @@
<?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.4
*
* @param \RetailCRM $module
*
* @return bool
*/
function upgrade_module_3_4_4($module)
{
if ('retailcrm' != $module->name) {
return false;
}
return $module->installTab();
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long