Сделал сохранение е и обновление id каталогов в таблице. Изменил получение экземпляра и конструктор сервиса настроек
This commit is contained in:
parent
b7c54305bc
commit
c65cf25393
@ -38,7 +38,8 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingService = SettingsService::getInstance([], '');
|
global $PROFILE_ID;
|
||||||
|
$settingService = SettingsService::getInstance([], '', $PROFILE_ID);
|
||||||
$iblockPropertySku = [];
|
$iblockPropertySku = [];
|
||||||
$iblockPropertySkuHl = [];
|
$iblockPropertySkuHl = [];
|
||||||
$iblockPropertyUnitSku = [];
|
$iblockPropertyUnitSku = [];
|
||||||
|
@ -26,7 +26,8 @@ CModule::IncludeModule('intaro.retailcrm');
|
|||||||
//TODO заменить вызов на сервис-локатор, когда он приедет
|
//TODO заменить вызов на сервис-локатор, когда он приедет
|
||||||
$settingsService = SettingsService::getInstance(
|
$settingsService = SettingsService::getInstance(
|
||||||
$arOldSetupVars ?? [],
|
$arOldSetupVars ?? [],
|
||||||
$ACTION
|
$ACTION,
|
||||||
|
$PROFILE_ID
|
||||||
);
|
);
|
||||||
|
|
||||||
$isSetupModulePage = $settingsService->isSetupModulePage();
|
$isSetupModulePage = $settingsService->isSetupModulePage();
|
||||||
@ -473,10 +474,10 @@ if ($STEP === 1) {
|
|||||||
} ?>
|
} ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (!empty($catalogCustomProps)) {
|
$catalogId = $arIBlock['ID'];
|
||||||
$catalogId = $arIBlock['ID'];
|
$catalogCustomProps = $settingsService->customPropList[$catalogId];
|
||||||
$catalogCustomProps = $settingsService->customPropList[$catalogId];
|
|
||||||
|
|
||||||
|
if (!empty($catalogCustomProps)) {
|
||||||
foreach ($catalogCustomProps as $catalogCustomPropCode => $catalogCustomPropValue) { ?>
|
foreach ($catalogCustomProps as $catalogCustomPropCode => $catalogCustomPropValue) { ?>
|
||||||
<tr class="adm-list-table-row custom-property-row">
|
<tr class="adm-list-table-row custom-property-row">
|
||||||
<td class="adm-list-table-cell custom-property-title">
|
<td class="adm-list-table-cell custom-property-title">
|
||||||
|
@ -31,15 +31,16 @@ class CustomExportProps extends Controller
|
|||||||
|
|
||||||
public function saveAction()
|
public function saveAction()
|
||||||
{
|
{
|
||||||
$settingsService = SettingsService::getInstance(
|
|
||||||
[],
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
$requestData = $this->getRequestData();
|
$requestData = $this->getRequestData();
|
||||||
$props = $requestData['properties'];
|
$props = $requestData['properties'];
|
||||||
$profileId = $requestData['profileId'];
|
$profileId = $requestData['profileId'];
|
||||||
|
|
||||||
|
$settingsService = SettingsService::getInstance(
|
||||||
|
[],
|
||||||
|
null,
|
||||||
|
$profileId
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($props as $catalogId => $propsArray) {
|
foreach ($props as $catalogId => $propsArray) {
|
||||||
$catalogCustomProps = [];
|
$catalogCustomProps = [];
|
||||||
foreach ($propsArray as $property) {
|
foreach ($propsArray as $property) {
|
||||||
@ -49,22 +50,23 @@ class CustomExportProps extends Controller
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
$settingsService
|
$settingsService
|
||||||
->setCatalogCustomPropsOptionName($profileId)
|
->setCatalogCustomPropsOptionName($catalogId)
|
||||||
->saveCustomProps($catalogId, $catalogCustomProps);
|
->saveCustomProps($catalogId, $catalogCustomProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAction()
|
public function deleteAction()
|
||||||
{
|
{
|
||||||
$settingsService = SettingsService::getInstance(
|
|
||||||
[],
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
$requestData = $this->getRequestData();
|
$requestData = $this->getRequestData();
|
||||||
$props = $requestData['properties'];
|
$props = $requestData['properties'];
|
||||||
$profileId = $requestData['profileId'];
|
$profileId = $requestData['profileId'];
|
||||||
|
|
||||||
|
$settingsService = SettingsService::getInstance(
|
||||||
|
[],
|
||||||
|
null,
|
||||||
|
$profileId
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($props as $catalogId => $propsArray) {
|
foreach ($props as $catalogId => $propsArray) {
|
||||||
$catalogCustomProps = [];
|
$catalogCustomProps = [];
|
||||||
foreach ($propsArray as $property) {
|
foreach ($propsArray as $property) {
|
||||||
|
@ -131,7 +131,7 @@ class SettingsService
|
|||||||
* @param array $arOldSetupVars
|
* @param array $arOldSetupVars
|
||||||
* @param string|null $action
|
* @param string|null $action
|
||||||
*/
|
*/
|
||||||
private function __construct(array $arOldSetupVars, ?string $action)
|
private function __construct(array $arOldSetupVars, ?string $action, string $profileId)
|
||||||
{
|
{
|
||||||
$this->arOldSetupVars = $arOldSetupVars;
|
$this->arOldSetupVars = $arOldSetupVars;
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
@ -147,8 +147,9 @@ class SettingsService
|
|||||||
$this->getPriceTypes();
|
$this->getPriceTypes();
|
||||||
$this->getVatRates();
|
$this->getVatRates();
|
||||||
|
|
||||||
$this->exportProfileId = $this->getExportProfileId();
|
$this->exportProfileId = $profileId;
|
||||||
$this->profileCatalogsOptionName = $this->getProfileCatalogsOptionName();
|
$this->setProfileCatalogsOptionName();
|
||||||
|
$this->deleteEmptyProfileCatalogs();
|
||||||
|
|
||||||
$this->customPropList = $this->getNewProps();
|
$this->customPropList = $this->getNewProps();
|
||||||
$this->defaultPropList = $this->getIblockPropsPreset();
|
$this->defaultPropList = $this->getIblockPropsPreset();
|
||||||
@ -161,10 +162,10 @@ class SettingsService
|
|||||||
*
|
*
|
||||||
* @return \Intaro\RetailCrm\Icml\SettingsService|null
|
* @return \Intaro\RetailCrm\Icml\SettingsService|null
|
||||||
*/
|
*/
|
||||||
public static function getInstance(array $arOldSetupVars, ?string $action): ?SettingsService
|
public static function getInstance(array $arOldSetupVars, ?string $action, ?string $profileId): ?SettingsService
|
||||||
{
|
{
|
||||||
if (is_null(self::$instance)) {
|
if (is_null(self::$instance)) {
|
||||||
self::$instance = new self($arOldSetupVars, $action);
|
self::$instance = new self($arOldSetupVars, $action, $profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
@ -792,7 +793,7 @@ class SettingsService
|
|||||||
public function setCatalogCustomPropsOptionName(string $catalogId): self
|
public function setCatalogCustomPropsOptionName(string $catalogId): self
|
||||||
{
|
{
|
||||||
$this->catalogCustomPropsOptionName = sprintf(
|
$this->catalogCustomPropsOptionName = sprintf(
|
||||||
'customProps_exportProfileId_%s_catalogId_%s',
|
'exportCustomProps_ProfileId_%s_catalogId_%s',
|
||||||
$this->exportProfileId,
|
$this->exportProfileId,
|
||||||
$catalogId
|
$catalogId
|
||||||
);
|
);
|
||||||
@ -800,19 +801,12 @@ class SettingsService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getExportProfileId(): string
|
private function setProfileCatalogsOptionName(): void
|
||||||
{
|
{
|
||||||
global $PROFILE_ID;
|
$this->profileCatalogsOptionName = sprintf('exportProfileId_%s_catalogs', $this->exportProfileId);
|
||||||
|
|
||||||
return $PROFILE_ID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProfileCatalogsOptionName(): string
|
private function getCustomProps(): ?array
|
||||||
{
|
|
||||||
return sprintf('exportProfile_%s_catalogs', $this->exportProfileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCustomProps(): ?array
|
|
||||||
{
|
{
|
||||||
$props = unserialize(COption::GetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName));
|
$props = unserialize(COption::GetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName));
|
||||||
|
|
||||||
@ -832,24 +826,23 @@ class SettingsService
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (empty($updatedCatalogProps)) {
|
if (empty($updatedCatalogProps)) {
|
||||||
COption::RemoveOption(self::MODULE_ID, $this->catalogCustomPropsOptionName);
|
$this->deleteOptionEntry($this->catalogCustomPropsOptionName);
|
||||||
COption::RemoveOption(self::MODULE_ID, $this->profileCatalogsOptionName);
|
$this->deleteProfileCatalog($catalogId);
|
||||||
} else {
|
} else {
|
||||||
$this->updateProfileCatalogs($catalogId);
|
$this->updateCustomProps($updatedCatalogProps);
|
||||||
$this->updateCustomPropsOptionEntry($updatedCatalogProps);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateCustomPropsOptionEntry(array $updatedProps)
|
private function updateCustomProps(array $updatedProps)
|
||||||
{
|
{
|
||||||
COption::SetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName, '');
|
$serializedProps = serialize($updatedProps);
|
||||||
$this->setCustomPropsOptionEntry($updatedProps);
|
$this->updateOptionEntry($this->catalogCustomPropsOptionName, $serializedProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setCustomPropsOptionEntry(array $props)
|
private function setCustomProps(array $props)
|
||||||
{
|
{
|
||||||
$propsString = serialize($props);
|
$propsString = serialize($props);
|
||||||
COption::SetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName, $propsString);
|
$this->setOptionEntry($this->catalogCustomPropsOptionName, $propsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCustomProps(string $catalogId, array $newProps): void
|
public function saveCustomProps(string $catalogId, array $newProps): void
|
||||||
@ -857,12 +850,12 @@ class SettingsService
|
|||||||
$currentProps = $this->getCustomProps();
|
$currentProps = $this->getCustomProps();
|
||||||
|
|
||||||
if (is_null($currentProps)) {
|
if (is_null($currentProps)) {
|
||||||
$this->setCustomPropsOptionEntry($newProps);
|
$this->setProfileCatalog($catalogId);
|
||||||
$this->setProfileCatalogs($catalogId);
|
$this->setCustomProps($newProps);
|
||||||
} else {
|
} else {
|
||||||
$updatedProps = array_merge($currentProps, $newProps);
|
$updatedProps = array_merge($currentProps, $newProps);
|
||||||
$this->updateCustomPropsOptionEntry($updatedProps);
|
|
||||||
$this->updateProfileCatalogs($catalogId);
|
$this->updateProfileCatalogs($catalogId);
|
||||||
|
$this->updateCustomProps($updatedProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,18 +870,57 @@ class SettingsService
|
|||||||
return $catalogs;
|
return $catalogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setProfileCatalogs(string $catalogId): void
|
private function setProfileCatalog(string $catalogId): void
|
||||||
{
|
{
|
||||||
$catalogs = serialize([$catalogId]);
|
$catalogs = serialize([$catalogId]);
|
||||||
COption::SetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName, $catalogs);
|
$this->setOptionEntry($this->profileCatalogsOptionName, $catalogs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateProfileCatalogs(string $catalogId): void
|
private function updateProfileCatalogs(string $catalogId): void
|
||||||
{
|
{
|
||||||
$currentCatalogs = unserialize(COption::GetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName));
|
$currentCatalogs = $this->getProfileCatalogs();
|
||||||
$updatedCatalogs = serialize([...$currentCatalogs, $catalogId]);
|
|
||||||
|
|
||||||
COption::SetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName, '');
|
if (!in_array($catalogId, $currentCatalogs)) {
|
||||||
COption::SetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName, $updatedCatalogs);
|
$updatedCatalogs = serialize(array_merge($currentCatalogs, [$catalogId]));
|
||||||
|
$this->updateOptionEntry($this->profileCatalogsOptionName, $updatedCatalogs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteProfileCatalog(string $catalogId): void
|
||||||
|
{
|
||||||
|
$currentCatalogs = $this->getProfileCatalogs();
|
||||||
|
$catalogIdIndex = array_search($catalogId, $currentCatalogs);
|
||||||
|
|
||||||
|
if ($catalogIdIndex !== false) {
|
||||||
|
unset($currentCatalogs[$catalogIdIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updatedCatalogs = serialize($currentCatalogs);
|
||||||
|
$this->updateOptionEntry($this->profileCatalogsOptionName, $updatedCatalogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteEmptyProfileCatalogs(): void
|
||||||
|
{
|
||||||
|
$currentCatalogs = $this->getProfileCatalogs();
|
||||||
|
|
||||||
|
if (is_null($currentCatalogs)) {
|
||||||
|
$this->deleteOptionEntry($this->profileCatalogsOptionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setOptionEntry(string $name, string $value)
|
||||||
|
{
|
||||||
|
$setResult = COption::SetOptionString(self::MODULE_ID, $name, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateOptionEntry(string $name, string $value)
|
||||||
|
{
|
||||||
|
COption::SetOptionString(self::MODULE_ID, $name, '');
|
||||||
|
COption::SetOptionString(self::MODULE_ID, $name, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteOptionEntry(string $name)
|
||||||
|
{
|
||||||
|
COption::RemoveOption(self::MODULE_ID, $name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,8 +115,8 @@ class XmlOfferBuilder
|
|||||||
public function __construct(XmlSetup $setup, array $measure, ?string $serverName)
|
public function __construct(XmlSetup $setup, array $measure, ?string $serverName)
|
||||||
{
|
{
|
||||||
$this->setup = $setup;
|
$this->setup = $setup;
|
||||||
|
$this->setSettingsService();
|
||||||
$this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice();
|
$this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice();
|
||||||
$this->settingsService = SettingsService::getInstance([], '');
|
|
||||||
$this->vatRates = $this->settingsService->vatRates;
|
$this->vatRates = $this->settingsService->vatRates;
|
||||||
$this->measures = $this->prepareMeasures($measure);
|
$this->measures = $this->prepareMeasures($measure);
|
||||||
$this->serverName = $serverName;
|
$this->serverName = $serverName;
|
||||||
@ -141,6 +141,12 @@ class XmlOfferBuilder
|
|||||||
return $this->xmlOffer;
|
return $this->xmlOffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setSettingsService(): void
|
||||||
|
{
|
||||||
|
global $PROFILE_ID;
|
||||||
|
$this->settingsService = SettingsService::getInstance([], '', $PROFILE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $categories
|
* @param array $categories
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user