2024-11-06 19:30:00 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Intaro\RetailCrm\Controller;
|
2024-11-13 20:23:47 +03:00
|
|
|
|
|
2024-11-06 19:30:00 +03:00
|
|
|
|
use Bitrix\Main\Engine\Controller;
|
|
|
|
|
use Bitrix\Main\Result;
|
|
|
|
|
use Bitrix\Main\Error;
|
2024-11-13 20:23:47 +03:00
|
|
|
|
use Bitrix\Main\Application;
|
|
|
|
|
use Intaro\RetailCrm\Icml\SettingsService;
|
2024-11-06 19:30:00 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @category Integration
|
|
|
|
|
* @package Intaro\RetailCrm\Controller
|
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
|
* @license MIT
|
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
|
* @see http://retailcrm.ru/docs
|
|
|
|
|
*/
|
|
|
|
|
class CustomExportProps extends Controller
|
|
|
|
|
{
|
2024-11-13 20:23:47 +03:00
|
|
|
|
private function getRequestData(): array
|
2024-11-06 19:30:00 +03:00
|
|
|
|
{
|
2024-11-13 20:23:47 +03:00
|
|
|
|
$data = $this->getRequest()->getInput();
|
|
|
|
|
|
|
|
|
|
if ($data === null) {
|
2024-11-06 19:30:00 +03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 20:23:47 +03:00
|
|
|
|
return json_decode($data, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveAction()
|
|
|
|
|
{
|
|
|
|
|
$settingsService = SettingsService::getInstance(
|
|
|
|
|
[],
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$requestData = $this->getRequestData();
|
|
|
|
|
$props = $requestData['properties'];
|
2024-11-07 18:30:22 +03:00
|
|
|
|
$profileId = $requestData['profileId'];
|
2024-11-06 19:30:00 +03:00
|
|
|
|
|
2024-11-13 20:23:47 +03:00
|
|
|
|
$dbConnection = Application::getInstance()->getConnection();
|
|
|
|
|
try {
|
|
|
|
|
$dbConnection->startTransaction();
|
|
|
|
|
foreach ($props as $catalogId => $propsArray) {
|
|
|
|
|
$catalogCustomProps = [];
|
|
|
|
|
foreach ($propsArray as $property) {
|
|
|
|
|
$catalogCustomProps[] = [
|
|
|
|
|
'code' => $property['code'],
|
|
|
|
|
'title' => $property['title']
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$settingsService->setCustomProps($profileId, $catalogId, $catalogCustomProps);
|
2024-11-06 19:30:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 20:23:47 +03:00
|
|
|
|
$dbConnection->commitTransaction();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
$dbConnection->rollbackTransaction();
|
2024-11-06 19:30:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteAction()
|
|
|
|
|
{
|
2024-11-13 20:23:47 +03:00
|
|
|
|
$settingsService = SettingsService::getInstance(
|
|
|
|
|
[],
|
|
|
|
|
null
|
|
|
|
|
);
|
2024-11-11 19:36:17 +03:00
|
|
|
|
|
2024-11-13 20:23:47 +03:00
|
|
|
|
$requestData = $this->getRequestData();
|
|
|
|
|
$props = $requestData['properties'];
|
2024-11-11 19:36:17 +03:00
|
|
|
|
$profileId = $requestData['profileId'];
|
|
|
|
|
|
2024-11-13 20:23:47 +03:00
|
|
|
|
$dbConnection = Application::getInstance()->getConnection();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$dbConnection->startTransaction();
|
|
|
|
|
|
|
|
|
|
foreach ($props as $catalogId => $propsArray) {
|
|
|
|
|
$catalogCustomProps = [];
|
|
|
|
|
foreach ($propsArray as $property) {
|
|
|
|
|
$catalogCustomProps[] = [
|
|
|
|
|
'code' => $property['code'],
|
|
|
|
|
'title' => $property['title']
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$settingsService->deleteCustomProps($profileId, $catalogId, $catalogCustomProps);
|
|
|
|
|
// $filePath = sprintf(
|
|
|
|
|
// '%s/%s_profileId_%s_catalogId_%s.txt',
|
|
|
|
|
// $_SERVER['DOCUMENT_ROOT'] . '/local',
|
|
|
|
|
// 'icml_property_retailcrm',
|
|
|
|
|
// $profileId,
|
|
|
|
|
// $catalogId
|
|
|
|
|
// );
|
|
|
|
|
// $fileContent = file_get_contents($filePath);
|
|
|
|
|
//
|
|
|
|
|
// foreach ($propsArray as $property) {
|
|
|
|
|
// $propStringToDelete = PHP_EOL . $property['code'] . ' = ' . $property['title'];
|
|
|
|
|
// $fileContent = str_replace($propStringToDelete, '', $fileContent);
|
|
|
|
|
// }
|
|
|
|
|
// file_put_contents($filePath, $fileContent);
|
|
|
|
|
|
2024-11-11 19:36:17 +03:00
|
|
|
|
}
|
2024-11-13 20:23:47 +03:00
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
$dbConnection->rollbackTransaction();
|
|
|
|
|
// Добавить возврат ответа с ошибкой
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// foreach ($props as $catalogId => $propsArray) {
|
|
|
|
|
// $filePath = sprintf(
|
|
|
|
|
// '%s/%s_profileId_%s_catalogId_%s.txt',
|
|
|
|
|
// $_SERVER['DOCUMENT_ROOT'] . '/local',
|
|
|
|
|
// 'icml_property_retailcrm',
|
|
|
|
|
// $profileId,
|
|
|
|
|
// $catalogId
|
|
|
|
|
// );
|
|
|
|
|
// $fileContent = file_get_contents($filePath);
|
|
|
|
|
//
|
|
|
|
|
// foreach ($propsArray as $property) {
|
|
|
|
|
// $propStringToDelete = PHP_EOL . $property['code'] . ' = ' . $property['title'];
|
|
|
|
|
// $fileContent = str_replace($propStringToDelete, '', $fileContent);
|
|
|
|
|
// }
|
|
|
|
|
// file_put_contents($filePath, $fileContent);
|
|
|
|
|
|
2024-11-11 19:36:17 +03:00
|
|
|
|
}
|
2024-11-06 19:30:00 +03:00
|
|
|
|
}
|