1
0
mirror of synced 2024-12-01 17:56:07 +03:00
bitrix-module/intaro.retailcrm/lib/controller/adminpanel.php
Сергей Чазов 34e8105583
Loyalty (#241)
* Loyalty program
* fix dot bug for shops-exoprt option
* delete credantials request from services
* add CurlException for credentials catch
* add catching CurlException
* edit error msgs
* add supportind double bonuses
* add any step for bonus-input field in sale.order.ajax template
* recalculate bonuses
* fix bonus rounded
* strtoupper for params in icml
* change delivery service code
2022-03-02 15:40:53 +03:00

147 lines
4.2 KiB
PHP

<?php
namespace Intaro\RetailCrm\Controller;
use Bitrix\Main\Engine\ActionFilter\Authentication;
use Bitrix\Main\Engine\Controller;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants;
class AdminPanel extends Controller
{
public function configureActions(): array
{
return [
'createTemplate' => [
'-prefilters' => [
Authentication::class,
],
],
];
}
/**
* @param array $templates
* @param string $donor
* @param string $replaceDefaultTemplate
*
* @return array
*/
public function createTemplateAction(array $templates, string $donor, string $replaceDefaultTemplate = 'N'): array
{
$templateName = $replaceDefaultTemplate === 'Y' ? '.default' : Constants::DEFAULT_LOYALTY_TEMPLATE;
$donor = str_replace(['../', './'], '', $donor);
foreach ($templates as $template) {
$template['location'] = str_replace(['../', './'], '', $template['location']);
$template['name'] = str_replace(['../', './'], '', $template['name']);
$pathFrom = $_SERVER['DOCUMENT_ROOT']
. '/bitrix/modules/'
. Constants::MODULE_ID
. '/install/export/local/components/intaro/' . $donor . '/templates/.default';
$pathTo = $_SERVER['DOCUMENT_ROOT']
. $template['location']
. $template['name']
. '/components/bitrix/'
. $donor
. '/'
. $templateName;
if ($replaceDefaultTemplate === 'Y' && file_exists($pathTo)) {
$backPath = $_SERVER['DOCUMENT_ROOT']
. $template['location']
. $template['name']
. '/components/bitrix/'
. $donor
. '/'
. $templateName.'_backup';
CopyDirFiles(
$pathTo,
$backPath,
true,
true,
false
);
}
$status = CopyDirFiles(
$pathFrom,
$pathTo,
true,
true,
false
);
}
return [
'status' => $status ?? false,
];
}
/**
* @return string[]
* @throws \Bitrix\Main\ArgumentOutOfRangeException
*/
public function LoyaltyProgramToggleAction(): array
{
$status = ConfigProvider::getLoyaltyProgramStatus();
$newStatus = $status !== 'Y' ? 'Y' : 'N';
ConfigProvider::setLoyaltyProgramStatus($newStatus);
return ['newStatus' => $newStatus];
}
/**
* @param $templates
* @param string $defreplace
* @return array
*/
public function createSaleTemplateAction($templates, $defreplace = 'N'): array
{
$templateName = $defreplace === 'Y' ? '.default' : Constants::MODULE_ID;
foreach ($templates as $template) {
$pathFrom = $_SERVER['DOCUMENT_ROOT']
. '/bitrix/modules/'
. Constants::MODULE_ID
. '/install/export/local/components/intaro/sale.order.ajax/templates/.default';
$pathTo = $_SERVER['DOCUMENT_ROOT']
. $template['location']
. $template['name']
. '/components/bitrix/sale.order.ajax/'
. $templateName;
if ($defreplace === 'Y' && file_exists($pathTo)) {
$backPath = $_SERVER['DOCUMENT_ROOT']
. $template['location']
. $template['name']
. '/components/bitrix/sale.order.ajax/'
. $templateName.'_backup';
CopyDirFiles(
$pathTo,
$backPath,
true,
true,
false
);
}
$status = CopyDirFiles(
$pathFrom,
$pathTo,
true,
true,
false
);
}
return [
'status' => $status,
];
}
}