Сделал удаление записи свойств из таблицы. Начал делать сохранение и получение id каталогов из таблицы
This commit is contained in:
parent
e71c62b1ab
commit
b7c54305bc
@ -46,7 +46,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
|
|||||||
$iblockPropertyProductHl = [];
|
$iblockPropertyProductHl = [];
|
||||||
$iblockPropertyUnitProduct = [];
|
$iblockPropertyUnitProduct = [];
|
||||||
|
|
||||||
foreach (array_keys($settingService->actrualPropList) as $prop) {
|
foreach (array_keys($settingService->actualPropList) as $prop) {
|
||||||
$skuUnitProps = ('iblockPropertyUnitSku_' . $prop);
|
$skuUnitProps = ('iblockPropertyUnitSku_' . $prop);
|
||||||
$skuUnitProps = $$skuUnitProps;
|
$skuUnitProps = $$skuUnitProps;
|
||||||
|
|
||||||
|
@ -473,6 +473,7 @@ if ($STEP === 1) {
|
|||||||
} ?>
|
} ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
if (!empty($catalogCustomProps)) {
|
||||||
$catalogId = $arIBlock['ID'];
|
$catalogId = $arIBlock['ID'];
|
||||||
$catalogCustomProps = $settingsService->customPropList[$catalogId];
|
$catalogCustomProps = $settingsService->customPropList[$catalogId];
|
||||||
|
|
||||||
@ -555,7 +556,9 @@ if ($STEP === 1) {
|
|||||||
</td>
|
</td>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php } ?>
|
<?php }
|
||||||
|
}
|
||||||
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<button class="adm-btn-save add-custom-row" type="button">Добавить</button>
|
<button class="adm-btn-save add-custom-row" type="button">Добавить</button>
|
||||||
@ -664,7 +667,7 @@ if ($STEP === 1) {
|
|||||||
<input type="hidden" name="STEP" value="<?=$STEP + 1?>">
|
<input type="hidden" name="STEP" value="<?=$STEP + 1?>">
|
||||||
<input type="hidden" name="SETUP_FIELDS_LIST" value="<?=
|
<input type="hidden" name="SETUP_FIELDS_LIST" value="<?=
|
||||||
$settingsService->getSetupFieldsString(
|
$settingsService->getSetupFieldsString(
|
||||||
array_keys($settingsService->actrualPropList) ?? [],
|
array_keys($settingsService->actualPropList) ?? [],
|
||||||
$hlblockModule === true,
|
$hlblockModule === true,
|
||||||
$hlBlockList ?? []
|
$hlBlockList ?? []
|
||||||
)
|
)
|
||||||
@ -944,10 +947,10 @@ if ($STEP === 1) {
|
|||||||
if (promises.length > 0) {
|
if (promises.length > 0) {
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
// formElem.submit();
|
formElem.submit();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// formElem.submit();
|
formElem.submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,7 +48,9 @@ class CustomExportProps extends Controller
|
|||||||
'title' => $property['title']
|
'title' => $property['title']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$settingsService->saveCustomProps($profileId, $catalogId, $catalogCustomProps);
|
$settingsService
|
||||||
|
->setCatalogCustomPropsOptionName($profileId)
|
||||||
|
->saveCustomProps($catalogId, $catalogCustomProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,9 @@ class CustomExportProps extends Controller
|
|||||||
'title' => $property['title']
|
'title' => $property['title']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$settingsService->removeCustomProps($profileId, $catalogId, $catalogCustomProps);
|
$settingsService
|
||||||
|
->setCatalogCustomPropsOptionName($catalogId)
|
||||||
|
->removeCustomProps($catalogCustomProps, $catalogId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,6 +39,12 @@ class SettingsService
|
|||||||
|
|
||||||
private const MODULE_ID = 'intaro.retailcrm';
|
private const MODULE_ID = 'intaro.retailcrm';
|
||||||
|
|
||||||
|
private string $catalogCustomPropsOptionName;
|
||||||
|
|
||||||
|
private string $profileCatalogsOptionName;
|
||||||
|
|
||||||
|
private string $exportProfileId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -105,7 +111,7 @@ class SettingsService
|
|||||||
public $loadNonActivity;
|
public $loadNonActivity;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public $actrualPropList = [];
|
public $actualPropList = [];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public $customPropList = [];
|
public $customPropList = [];
|
||||||
@ -141,9 +147,12 @@ class SettingsService
|
|||||||
$this->getPriceTypes();
|
$this->getPriceTypes();
|
||||||
$this->getVatRates();
|
$this->getVatRates();
|
||||||
|
|
||||||
$this->customPropList = $this->parseNewProps();
|
$this->exportProfileId = $this->getExportProfileId();
|
||||||
|
$this->profileCatalogsOptionName = $this->getProfileCatalogsOptionName();
|
||||||
|
|
||||||
|
$this->customPropList = $this->getNewProps();
|
||||||
$this->defaultPropList = $this->getIblockPropsPreset();
|
$this->defaultPropList = $this->getIblockPropsPreset();
|
||||||
$this->actrualPropList = $this->getActualPropList();
|
$this->actualPropList = $this->getActualPropList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,14 +184,6 @@ class SettingsService
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFrontPropList(): array
|
|
||||||
{
|
|
||||||
$result = [...$this->defaultPropList];
|
|
||||||
$result['customProps'] = $this->customPropList;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPriceTypes()
|
public function getPriceTypes()
|
||||||
{
|
{
|
||||||
$dbPriceType = CCatalogGroup::GetList(['SORT' => 'ASC'], [], [], [], ['ID', 'NAME', 'BASE']);
|
$dbPriceType = CCatalogGroup::GetList(['SORT' => 'ASC'], [], [], [], ['ID', 'NAME', 'BASE']);
|
||||||
@ -299,33 +300,21 @@ class SettingsService
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseNewProps(): array
|
private function getNewProps(): array
|
||||||
{
|
{
|
||||||
global $PROFILE_ID;
|
|
||||||
$currentProfile = $PROFILE_ID;
|
|
||||||
$currentProfileCatalogIds = $this->getProfileCatalogIds();
|
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
|
$currentProfileCatalogIds = $this->getProfileCatalogs();
|
||||||
|
|
||||||
|
if (!is_null($currentProfileCatalogIds)) {
|
||||||
foreach ($currentProfileCatalogIds as $catalogId) {
|
foreach ($currentProfileCatalogIds as $catalogId) {
|
||||||
$catalogCustomProps = $this->getCustomProps($currentProfile, $catalogId);
|
$catalogCustomProps = $this
|
||||||
|
->setCatalogCustomPropsOptionName($catalogId)
|
||||||
|
->getCustomProps();
|
||||||
|
|
||||||
foreach ($catalogCustomProps as $prop) {
|
foreach ($catalogCustomProps as $prop) {
|
||||||
$result[$catalogId][$prop['code']] = $prop['title'];
|
$result[$catalogId][$prop['code']] = $prop['title'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getProfileCatalogIds(): array
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
foreach ($this->arOldSetupVars as $varName => $oldSetupVar) {
|
|
||||||
if (is_array($oldSetupVar) && strpos($varName, 'iblockPropertySku_') !== false) {
|
|
||||||
$result = array_keys($oldSetupVar);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@ -410,7 +399,7 @@ class SettingsService
|
|||||||
|
|
||||||
public function setProps(): void
|
public function setProps(): void
|
||||||
{
|
{
|
||||||
foreach (array_keys($this->actrualPropList) as $prop) {
|
foreach (array_keys($this->actualPropList) as $prop) {
|
||||||
$this->setProperties($this->iblockPropertySku, 'iblockPropertySku_' . $prop);
|
$this->setProperties($this->iblockPropertySku, 'iblockPropertySku_' . $prop);
|
||||||
$this->setProperties($this->iblockPropertyUnitSku, 'iblockPropertyUnitSku_' . $prop);
|
$this->setProperties($this->iblockPropertyUnitSku, 'iblockPropertyUnitSku_' . $prop);
|
||||||
$this->setProperties($this->iblockPropertyProduct, 'iblockPropertyProduct_' . $prop);
|
$this->setProperties($this->iblockPropertyProduct, 'iblockPropertyProduct_' . $prop);
|
||||||
@ -647,7 +636,7 @@ class SettingsService
|
|||||||
$props = [];
|
$props = [];
|
||||||
|
|
||||||
if (isset($oldValues[$iblockId])) {
|
if (isset($oldValues[$iblockId])) {
|
||||||
foreach (array_keys($this->actrualPropList) as $prop) {
|
foreach (array_keys($this->actualPropList) as $prop) {
|
||||||
$fullKey = $keyGroup . '_' . $prop;
|
$fullKey = $keyGroup . '_' . $prop;
|
||||||
$props[$prop] = $oldValues[$iblockId][$fullKey];
|
$props[$prop] = $oldValues[$iblockId][$fullKey];
|
||||||
}
|
}
|
||||||
@ -800,79 +789,106 @@ class SettingsService
|
|||||||
return [$arIBlockList, $intCountChecked, $intCountAvailIBlock, $arIBlockList['iblockExport'] ?? false];
|
return [$arIBlockList, $intCountChecked, $intCountAvailIBlock, $arIBlockList['iblockExport'] ?? false];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCustomPropsOptionName(string $profileId, string $catalogId): string
|
public function setCatalogCustomPropsOptionName(string $catalogId): self
|
||||||
{
|
{
|
||||||
return sprintf(
|
$this->catalogCustomPropsOptionName = sprintf(
|
||||||
'customProps_profileId_%s_catalogId_%s',
|
'customProps_exportProfileId_%s_catalogId_%s',
|
||||||
$profileId,
|
$this->exportProfileId,
|
||||||
$catalogId
|
$catalogId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCustomProps(string $profileId, string $catalogId)
|
private function getExportProfileId(): string
|
||||||
{
|
{
|
||||||
$optionName = $this->getCustomPropsOptionName($profileId, $catalogId);
|
global $PROFILE_ID;
|
||||||
|
|
||||||
return unserialize(COption::GetOptionString(self::MODULE_ID, $optionName));
|
return $PROFILE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeCustomProps(
|
private function getProfileCatalogsOptionName(): string
|
||||||
string $profileId,
|
{
|
||||||
string $catalogId,
|
return sprintf('exportProfile_%s_catalogs', $this->exportProfileId);
|
||||||
array $propsToDelete
|
}
|
||||||
): void {
|
|
||||||
$currentCatalogProps = $this->getCustomProps($profileId, $catalogId);
|
public function getCustomProps(): ?array
|
||||||
|
{
|
||||||
|
$props = unserialize(COption::GetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName));
|
||||||
|
|
||||||
|
if (!$props) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $props;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeCustomProps(array $propsToDelete, string $catalogId): void
|
||||||
|
{
|
||||||
|
$currentCatalogProps = $this->getCustomProps();
|
||||||
$updatedCatalogProps = array_values(array_filter(
|
$updatedCatalogProps = array_values(array_filter(
|
||||||
$currentCatalogProps,
|
$currentCatalogProps,
|
||||||
fn ($currentProp) => !in_array($currentProp, $propsToDelete)
|
fn ($currentProp) => !in_array($currentProp, $propsToDelete)
|
||||||
));
|
));
|
||||||
|
|
||||||
if (empty($updatedCatalogProps)) {
|
if (empty($updatedCatalogProps)) {
|
||||||
$this->removeCustomPropsOptionEntry($profileId, $catalogId);
|
COption::RemoveOption(self::MODULE_ID, $this->catalogCustomPropsOptionName);
|
||||||
|
COption::RemoveOption(self::MODULE_ID, $this->profileCatalogsOptionName);
|
||||||
} else {
|
} else {
|
||||||
$this->updateCustomPropsOptionEntry($profileId, $catalogId, $updatedCatalogProps);
|
$this->updateProfileCatalogs($catalogId);
|
||||||
|
$this->updateCustomPropsOptionEntry($updatedCatalogProps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateCustomPropsOptionEntry(
|
public function updateCustomPropsOptionEntry(array $updatedProps)
|
||||||
string $profileId,
|
|
||||||
string $catalogId,
|
|
||||||
array $updatedProps
|
|
||||||
) {
|
|
||||||
$this->removeCustomPropsOptionEntry($profileId, $catalogId);
|
|
||||||
$this->setCustomPropsOptionEntry($profileId, $catalogId, $updatedProps);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function removeCustomPropsOptionEntry($profileId, $catalogId)
|
|
||||||
{
|
{
|
||||||
$optionName = $this->getCustomPropsOptionName($profileId, $catalogId);
|
COption::SetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName, '');
|
||||||
$delRes = COption::RemoveOption(self::MODULE_ID, $optionName);
|
$this->setCustomPropsOptionEntry($updatedProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setCustomPropsOptionEntry(
|
private function setCustomPropsOptionEntry(array $props)
|
||||||
string $profileId,
|
|
||||||
string $catalogId,
|
|
||||||
array $props
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
$optionName = $this->getCustomPropsOptionName($profileId, $catalogId);
|
|
||||||
$propsString = serialize($props);
|
$propsString = serialize($props);
|
||||||
|
COption::SetOptionString(self::MODULE_ID, $this->catalogCustomPropsOptionName, $propsString);
|
||||||
$setResult = COption::SetOptionString(self::MODULE_ID, $optionName, $propsString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCustomProps(
|
public function saveCustomProps(string $catalogId, array $newProps): void
|
||||||
string $profileId,
|
{
|
||||||
string $catalogId,
|
$currentProps = $this->getCustomProps();
|
||||||
array $newProps
|
|
||||||
): void {
|
|
||||||
$currentProps = $this->getCustomProps($profileId, $catalogId);
|
|
||||||
|
|
||||||
if (empty($currentProps)) {
|
if (is_null($currentProps)) {
|
||||||
$this->setCustomPropsOptionEntry($profileId, $catalogId, $newProps);
|
$this->setCustomPropsOptionEntry($newProps);
|
||||||
|
$this->setProfileCatalogs($catalogId);
|
||||||
} else {
|
} else {
|
||||||
$updatedProps = array_merge($currentProps, $newProps);
|
$updatedProps = array_merge($currentProps, $newProps);
|
||||||
$this->updateCustomPropsOptionEntry($profileId, $catalogId, $updatedProps);
|
$this->updateCustomPropsOptionEntry($updatedProps);
|
||||||
|
$this->updateProfileCatalogs($catalogId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getProfileCatalogs(): ?array
|
||||||
|
{
|
||||||
|
$catalogs = unserialize(COption::GetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName));
|
||||||
|
|
||||||
|
if (!$catalogs) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $catalogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setProfileCatalogs(string $catalogId): void
|
||||||
|
{
|
||||||
|
$catalogs = serialize([$catalogId]);
|
||||||
|
COption::SetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName, $catalogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateProfileCatalogs(string $catalogId): void
|
||||||
|
{
|
||||||
|
$currentCatalogs = unserialize(COption::GetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName));
|
||||||
|
$updatedCatalogs = serialize([...$currentCatalogs, $catalogId]);
|
||||||
|
|
||||||
|
COption::SetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName, '');
|
||||||
|
COption::SetOptionString(self::MODULE_ID, $this->profileCatalogsOptionName, $updatedCatalogs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,7 +479,7 @@ class XmlOfferBuilder
|
|||||||
private function createParamObject(array $params): array
|
private function createParamObject(array $params): array
|
||||||
{
|
{
|
||||||
$offerParams = [];
|
$offerParams = [];
|
||||||
$names = $this->settingsService->actrualPropList;
|
$names = $this->settingsService->actualPropList;
|
||||||
|
|
||||||
foreach ($params as $code => $value) {
|
foreach ($params as $code => $value) {
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class SettingServiceTest extends \BitrixTestCase
|
|||||||
$settingService = SettingsService::getInstance($this->getSetupVars(), "");
|
$settingService = SettingsService::getInstance($this->getSetupVars(), "");
|
||||||
|
|
||||||
$this->assertInstanceOf(SettingsService::class, $settingService);
|
$this->assertInstanceOf(SettingsService::class, $settingService);
|
||||||
$this->assertArrayHasKey('property1', $settingService->actrualPropList);
|
$this->assertArrayHasKey('property1', $settingService->actualPropList);
|
||||||
$this->assertArrayHasKey('property2', $settingService->actrualPropList);
|
$this->assertArrayHasKey('property2', $settingService->actualPropList);
|
||||||
|
|
||||||
return $settingService;
|
return $settingService;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user