From 30ef0ebf8a704607e2bfd9545ded6e587dcf10e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A7=D0=B0=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2?= <45812598+Chazovs@users.noreply.github.com> Date: Wed, 8 Sep 2021 10:05:09 +0300 Subject: [PATCH] ICML simple product props (#207) --- intaro.retailcrm/.settings.php | 12 + .../general/RetailcrmConfigProvider.php | 30 + intaro.retailcrm/export/export_run.php | 24 +- intaro.retailcrm/export/export_setup.php | 1470 ++++++++--------- intaro.retailcrm/install/index.php | 175 +- intaro.retailcrm/install/step5.php | 702 +------- .../lang/en/export_setup_templ.php | 125 -- .../lang/en/icml_export_setup.php | 4 +- .../lang/ru/export_setup_templ.php | 125 -- .../lang/ru/icml_export_setup.php | 6 +- intaro.retailcrm/lib/controller/icml.php | 50 + intaro.retailcrm/lib/icml/icmldirector.php | 1 + intaro.retailcrm/lib/icml/settingsservice.php | 714 ++++++++ .../lib/icml/xmlofferdirector.php | 27 +- .../lib/lang/en/icml/settingsservice.php | 48 + .../lib/lang/ru/icml/settingsservice.php | 53 + .../lib/repository/hlrepository.php | 4 +- intaro.retailcrm/lib/service/hl.php | 92 +- intaro.retailcrm/updater.php | 154 +- 19 files changed, 1967 insertions(+), 1849 deletions(-) create mode 100644 intaro.retailcrm/.settings.php delete mode 100644 intaro.retailcrm/lang/en/export_setup_templ.php delete mode 100644 intaro.retailcrm/lang/ru/export_setup_templ.php create mode 100644 intaro.retailcrm/lib/controller/icml.php create mode 100644 intaro.retailcrm/lib/icml/settingsservice.php create mode 100644 intaro.retailcrm/lib/lang/en/icml/settingsservice.php create mode 100644 intaro.retailcrm/lib/lang/ru/icml/settingsservice.php diff --git a/intaro.retailcrm/.settings.php b/intaro.retailcrm/.settings.php new file mode 100644 index 00000000..f28c8a92 --- /dev/null +++ b/intaro.retailcrm/.settings.php @@ -0,0 +1,12 @@ + [ + 'value' => [ + 'namespaces' => [ + '\\Intaro\\RetailCrm\\Controller' => 'api' + ], + ], + 'readonly' => true, + ] +]; diff --git a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php index 492d6601..34823b70 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php +++ b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php @@ -270,6 +270,36 @@ class RetailcrmConfigProvider return static::setOption(RetailcrmConstants::CRM_USERS_MAP, serialize($userMap)); } + /** + * @param $profileId + * + * @return false|string|null + */ + public static function getCrmBasePrice($profileId) + { + return self::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId, 1); + } + + public static function setProfileBasePrice($profileId, $priceTypes): void + { + self::setOption( + RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId, + htmlspecialchars(trim($priceTypes)) + ); + } + + /** + * @return string + */ + public static function getDefaultIcmlPath(): string + { + return (COption::GetOptionString( + 'catalog', + 'export_default_path', + '/bitrix/catalog_export/')) + . 'retailcrm.xml'; + } + /** * setOnlineConsultantScript * diff --git a/intaro.retailcrm/export/export_run.php b/intaro.retailcrm/export/export_run.php index 844ec7d5..17384d20 100644 --- a/intaro.retailcrm/export/export_run.php +++ b/intaro.retailcrm/export/export_run.php @@ -7,6 +7,8 @@ use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupProps; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupPropsCategories; use Intaro\RetailCrm\Repository\CatalogRepository; +/** @var $SETUP_FILE_NAME */ + if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/export_run.php')) { require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/export_run.php'); } else { @@ -54,7 +56,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp $iblockPropertyUnitProduct = []; foreach ($iblockProperties as $prop) { - $skuUnitProps = ('IBLOCK_PROPERTY_UNIT_SKU' . "_" . $prop); + $skuUnitProps = ('iblockPropertyUnitSku_' . $prop); $skuUnitProps = $$skuUnitProps; if (is_array($skuUnitProps)) { @@ -63,7 +65,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp } } - $skuProps = ('IBLOCK_PROPERTY_SKU' . "_" . $prop); + $skuProps = ('iblockPropertySku_' . $prop); $skuProps = $$skuProps; if (is_array($skuProps)) { foreach ($skuProps as $iblock => $val) { @@ -84,7 +86,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp } } - $productUnitProps = "IBLOCK_PROPERTY_UNIT_PRODUCT" . "_" . $prop; + $productUnitProps = 'iblockPropertyUnitProduct_' . $prop; $productUnitProps = $$productUnitProps; if (is_array($productUnitProps)) { foreach ($productUnitProps as $iblock => $val) { @@ -92,7 +94,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp } } - $productProps = "IBLOCK_PROPERTY_PRODUCT" . "_" . $prop; + $productProps = "iblockPropertyProduct_" . $prop; $productProps = $$productProps; if (is_array($productProps)) { foreach ($productProps as $iblock => $val) { @@ -116,16 +118,16 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp $productPictures = []; - if (is_array($IBLOCK_PROPERTY_PRODUCT_picture)) { - foreach ($IBLOCK_PROPERTY_PRODUCT_picture as $key => $value) { + if (is_array($iblockPropertyProduct_picture)) { + foreach ($iblockPropertyProduct_picture as $key => $value) { $productPictures[$key] = $value; } } $skuPictures = []; - if (is_array($IBLOCK_PROPERTY_SKU_picture)) { - foreach ($IBLOCK_PROPERTY_SKU_picture as $key => $value) { + if (is_array($iblockPropertySku_picture)) { + foreach ($iblockPropertySku_picture as $key => $value) { $skuPictures[$key] = $value; } } @@ -142,10 +144,10 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp $fileSetup = new XmlSetup($xmlProps); $fileSetup->profileId = $profile_id; - $fileSetup->iblocksForExport = $IBLOCK_EXPORT; - $fileSetup->maxOffersValue = $MAX_OFFERS_VALUE ?? null; + $fileSetup->iblocksForExport = $iblockExport; + $fileSetup->maxOffersValue = $maxOffersValue ?? null; $fileSetup->filePath = $SETUP_FILE_NAME; - $fileSetup->loadPurchasePrice = $LOAD_PURCHASE_PRICE === 'Y'; + $fileSetup->loadPurchasePrice = $loadPurchasePrice === 'Y'; $fileSetup->basePriceId = CatalogRepository::getBasePriceId($fileSetup->profileId); $logger = Logger::getInstance('/bitrix/catalog_export/'); diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php index fc545a0a..9ee49c77 100644 --- a/intaro.retailcrm/export/export_setup.php +++ b/intaro.retailcrm/export/export_setup.php @@ -1,842 +1,782 @@ -isSetupModulePage(); + +if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/export_setup.php')) { + require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/export_setup.php'); + + return; +} + +if (!check_bitrix_sessid()) { + return; +} + +__IncludeLang(GetLangFileName( + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/intaro.retailcrm/lang/', + '/icml_export_setup.php') +); + +$basePriceId = RetailcrmConfigProvider::getCrmBasePrice($_REQUEST['PROFILE_ID']); +$priceTypes = $settingsService->priceTypes; +$iblockFieldsName = $settingsService->getIblockFieldsNames(); +$iblockPropertiesHint = $settingsService->getHintProps(); +$units = $settingsService->getUnitsNames(); +$hintUnit = $settingsService->getHintUnit(); +$SETUP_FILE_NAME = $settingsService->setupFileName; +$SETUP_PROFILE_NAME = $settingsService->setupProfileName; + +//highloadblock +if (CModule::IncludeModule('highloadblock')) { + $hlblockModule = true; + $hlBlockList = $settingsService->getHlBlockList(); +} + +if (($ACTION === 'EXPORT' || $ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_COPY') && $STEP === 1) { + $iblockProperties = $settingsService->getIblockPropsPreset(); + $loadPurchasePrice = $settingsService->loadPurchasePrice; + $iblockExport = $settingsService->iblockExport; + + if ($iblockExport) { + $maxOffersValue = $settingsService->getSingleSetting('maxOffersValue'); + } + + $settingsService->setProps(); + + $iblockPropertySku = $settingsService->iblockPropertySku; + $iblockPropertyUnitSku = $settingsService->iblockPropertyUnitSku; + $iblockPropertyProduct = $settingsService->iblockPropertyProduct; + $iblockPropertyUnitProduct = $settingsService->iblockPropertyUnitProduct; + + $boolAll = false; + $intCountChecked = 0; + $intCountAvailIBlock = 0; +} + +if (!isset($iblockExport) || !is_array($iblockExport)) { + $iblockExport = []; +} + +[$arIBlockList, $intCountChecked, $intCountAvailIBlock, $isExportIblock] + = $settingsService->getSettingsForIblocks(); + +if (count($iblockExport) !== 0) { + if ($intCountChecked === $intCountAvailIBlock) { + $boolAll = true; + } } else { - if (isset($_POST['ajax']) && $_POST['ajax'] == '1') { - CModule::IncludeModule('highloadblock'); - $rsData = HighloadBlockTable::getList(['filter' => ['TABLE_NAME' => $_POST['table']]]); - $hlblockArr = $rsData->Fetch(); - $hlblock = HighloadBlockTable::getById($hlblockArr["ID"])->fetch(); - $entity = HighloadBlockTable::compileEntity($hlblock); - $hbFields = $entity->getFields(); - $hlblockList['table'] = $hlblockArr["TABLE_NAME"]; + $intCountChecked = $intCountAvailIBlock; + $boolAll = true; +} - foreach ($hbFields as $hbFieldCode => $hbField) { - $hlblockList['fields'][] = $hbFieldCode; - } +//Проверка на ошибки +$STEP = $settingsService->returnIfErrors($STEP, $SETUP_FILE_NAME, $SETUP_PROFILE_NAME); - $APPLICATION->RestartBuffer(); - header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); - die(json_encode($hlblockList)); - } - - $iblockProperties = array( - "article" => "article", - "manufacturer" => "manufacturer", - "color" =>"color", - "size" => "size", - "weight" => "weight", - "length" => "length", - "width" => "width", - "height" => "height", - "picture" => "picture" - ); - - if (!check_bitrix_sessid()) { - return; - } - - __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/intaro.retailcrm/lang/", "/icml_export_setup.php")); - - $MODULE_ID = 'intaro.retailcrm'; - $CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; - $basePriceId = COption::GetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE . '_' . $_REQUEST['PROFILE_ID'], 1); - - $arResult['PRICE_TYPES'] = array(); - $dbPriceType = CCatalogGroup::GetList( - array("SORT" => "ASC"), array(), array(), array(), array("ID", "NAME", "BASE") - ); - - while ($arPriceType = $dbPriceType->Fetch()) { - $arResult['PRICE_TYPES'][$arPriceType['ID']] = $arPriceType; - } - - //highloadblock - if (CModule::IncludeModule('highloadblock')) { - $hlblockModule = true; - $hlblockList = array(); - $hlblockListDb = HighloadBlockTable::getList(); - - while ($hlblockArr = $hlblockListDb->Fetch()) { - $hlblock = HighloadBlockTable::getById($hlblockArr["ID"])->fetch(); - $entity = HighloadBlockTable::compileEntity($hlblock); - $hbFields = $entity->getFields(); - $hlblockList[$hlblockArr["TABLE_NAME"]]['LABEL'] = $hlblockArr["NAME"]; - - foreach ($hbFields as $hbFieldCode => $hbField) { - $hlblockList[$hlblockArr["TABLE_NAME"]]['FIELDS'][] = $hbFieldCode; - } - } - } - - if (($ACTION == 'EXPORT' || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) { - if (isset($arOldSetupVars['SETUP_FILE_NAME'])) - $SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME']; - if (isset($arOldSetupVars['LOAD_PURCHASE_PRICE'])) - $LOAD_PURCHASE_PRICE = $arOldSetupVars['LOAD_PURCHASE_PRICE']; - if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) - $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; - if (isset($arOldSetupVars['IBLOCK_EXPORT'])) - $IBLOCK_EXPORT = $arOldSetupVars['IBLOCK_EXPORT']; - if (isset($arOldSetupVars['IBLOCK_EXPORT'])) - $MAX_OFFERS_VALUE = $arOldSetupVars['MAX_OFFERS_VALUE']; - $IBLOCK_PROPERTY_SKU = []; - $IBLOCK_PROPERTY_UNIT_SKU = []; - foreach ($iblockProperties as $prop) { - foreach ($arOldSetupVars['IBLOCK_PROPERTY_SKU' . '_' . $prop] as $iblock => $val) { - $IBLOCK_PROPERTY_SKU[$iblock][$prop] = $val; - } - foreach ($arOldSetupVars['IBLOCK_PROPERTY_UNIT_SKU' . '_' . $prop] as $iblock => $val) { - $IBLOCK_PROPERTY_UNIT_SKU[$iblock][$prop] = $val; - } - } - - $IBLOCK_PROPERTY_PRODUCT = []; - $IBLOCK_PROPERTY_UNIT_PRODUCT = []; - foreach ($iblockProperties as $prop) { - foreach ($arOldSetupVars['IBLOCK_PROPERTY_PRODUCT' . '_' . $prop] as $iblock => $val) { - $IBLOCK_PROPERTY_PRODUCT[$iblock][$prop] = $val; - } - foreach ($arOldSetupVars['IBLOCK_PROPERTY_UNIT_PRODUCT' . '_' . $prop] as $iblock => $val) { - $IBLOCK_PROPERTY_UNIT_PRODUCT[$iblock][$prop] = $val; - } - } - } - - if ($STEP > 1) - { - - if (strlen($SETUP_FILE_NAME)<=0) - { - $arSetupErrors[] = GetMessage("CET_ERROR_NO_FILENAME"); - } - elseif ($APPLICATION->GetFileAccessPermission($SETUP_FILE_NAME) < "W") - { - $arSetupErrors[] = str_replace("#FILE#", $SETUP_FILE_NAME, GetMessage('CET_YAND_RUN_ERR_SETUP_FILE_ACCESS_DENIED')); - } - - if (($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && strlen($SETUP_PROFILE_NAME)<=0) - { - $arSetupErrors[] = GetMessage("CET_ERROR_NO_PROFILE_NAME"); - } - - if (!empty($arSetupErrors)) - { - $STEP = 1; - } - } - - if (!empty($arSetupErrors)) - echo ShowError(implode('
', $arSetupErrors)); - - - if ($STEP==1) { +//Отображение формы +if ($STEP === 1) { ?> - - -
- GetCurPage()?>"> + - -

-

- GetMessage("PROPERTY_ARTICLE_HEADER_NAME"), - "manufacturer" => GetMessage("PROPERTY_MANUFACTURER_HEADER_NAME"), - "color" => GetMessage("PROPERTY_COLOR_HEADER_NAME"), - "size" => GetMessage("PROPERTY_SIZE_HEADER_NAME"), - "weight" => GetMessage("PROPERTY_WEIGHT_HEADER_NAME"), - "length" => GetMessage("PROPERTY_LENGTH_HEADER_NAME"), - "width" => GetMessage("PROPERTY_WIDTH_HEADER_NAME"), - "height" => GetMessage("PROPERTY_HEIGHT_HEADER_NAME"), - "picture" => GetMessage("PROPERTY_PICTURE_HEADER_NAME") - ); - - $iblockFieldsName = Array( - "weight" => Array("code" => "catalog_weight" , "name" => GetMessage("SELECT_WEIGHT_PROPERTY_NAME"), 'unit' => 'mass'), - "length" => Array("code" => "catalog_length" , "name" => GetMessage("SELECT_LENGTH_PROPERTY_NAME"), 'unit' => 'length'), - "width" => Array("code" => "catalog_width" , "name" => GetMessage("SELECT_WIDTH_PROPERTY_NAME"), 'unit' => 'length'), - "height" => Array("code" => "catalog_height" , "name" => GetMessage("SELECT_HEIGHT_PROPERTY_NAME"), 'unit' => 'length'), - ); - - $iblockPropertiesHint = Array( - "article" => Array("ARTICLE", "ART", "ARTNUMBER", "ARTICUL", "ARTIKUL"), - "manufacturer" => Array("MANUFACTURER", "PROISVODITEL", "PROISVOD", "PROISV"), - "color" => Array("COLOR", "CVET"), - "size" => Array("SIZE", "RAZMER"), - "weight" => Array("WEIGHT", "VES", "VEC"), - "length" => Array("LENGTH", "DLINA"), - "width" => Array("WIDTH", "SHIRINA"), - "height" => Array("HEIGHT", "VISOTA"), - "picture" => Array("PICTURE", "PICTURE") - ); - - $units = Array( - 'length' => Array( - 'mm' => GetMessage("UNIT_MEASUREMENT_MM"), - 'cm' => GetMessage("UNIT_MEASUREMENT_CM"), - 'm' => GetMessage("UNIT_MEASUREMENT_M"), - ), - 'mass' => Array( - 'mg' => GetMessage("UNIT_MEASUREMENT_MG"), - 'g' => GetMessage("UNIT_MEASUREMENT_G"), - 'kg' => GetMessage("UNIT_MEASUREMENT_KG"), - ) - ); - - $hintUnit = Array( - 'length' => 'mm', - 'mass' => 'g' - ); - - $boolAll = false; - $intCountChecked = 0; - $intCountAvailIBlock = 0; - $arIBlockList = array(); - $db_res = CIBlock::GetList(Array("IBLOCK_TYPE"=>"ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W')); - - while ($iblock = $db_res->Fetch()) - { - if ($arCatalog = CCatalog::GetByIDExt($iblock["ID"])) - { - if($arCatalog['CATALOG_TYPE'] == "D" || $arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") - { - $propertiesSKU = null; - if ($arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") - { - $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock["ID"]); - - $db_properties = CIBlock::GetProperties($iblockOffer['IBLOCK_ID'], Array()); - while($prop = $db_properties->Fetch()) - $propertiesSKU[] = $prop; - - $oldPropertySKU = null; - if (isset($IBLOCK_PROPERTY_SKU[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertySKU[$key] = $IBLOCK_PROPERTY_SKU[$iblock['ID']][$key]; - } - } - - $oldPropertyUnitSKU = null; - if (isset($IBLOCK_PROPERTY_UNIT_SKU[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertyUnitSKU[$key] = $IBLOCK_PROPERTY_UNIT_SKU[$iblock['ID']][$key]; - } - } - } - - $propertiesProduct = null; - $db_properties = CIBlock::GetProperties($iblock['ID'], Array()); - while($prop = $db_properties->Fetch()) - $propertiesProduct[] = $prop; - - $oldPropertyProduct = null; - if (isset($IBLOCK_PROPERTY_PRODUCT[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertyProduct[$key] = $IBLOCK_PROPERTY_PRODUCT[$iblock['ID']][$key]; - } - } - - $oldPropertyUnitProduct = null; - if (isset($IBLOCK_PROPERTY_UNIT_PRODUCT[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertyUnitProduct[$key] = $IBLOCK_PROPERTY_UNIT_PRODUCT[$iblock['ID']][$key]; - } - } - - $arSiteList = array(); - $rsSites = CIBlock::GetSite($iblock["ID"]); - while ($arSite = $rsSites->Fetch()) - { - $arSiteList[] = $arSite["SITE_ID"]; - } - - if (count($IBLOCK_EXPORT) != 0) - $boolExport = (in_array($iblock['ID'], $IBLOCK_EXPORT)); - else - $boolExport = true; - - $arIBlockList[] = array( - 'ID' => $iblock['ID'], - 'NAME' => $iblock['NAME'], - 'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'], - 'IBLOCK_EXPORT' => $boolExport, - 'PROPERTIES_SKU' => $propertiesSKU, - 'PROPERTIES_PRODUCT' => $propertiesProduct, - 'OLD_PROPERTY_SKU_SELECT' => $oldPropertySKU, - 'OLD_PROPERTY_UNIT_SKU_SELECT' => $oldPropertyUnitSKU, - 'OLD_PROPERTY_PRODUCT_SELECT' => $oldPropertyProduct, - 'OLD_PROPERTY_UNIT_PRODUCT_SELECT' => $oldPropertyUnitProduct, - 'SITE_LIST' => '('.implode(' ',$arSiteList).')', - ); - - if ($boolExport) - $intCountChecked++; - $intCountAvailIBlock++; - } - } - } - if (count($IBLOCK_EXPORT) != 0) { - if ($intCountChecked == $intCountAvailIBlock) - $boolAll = true; - } else { - $intCountChecked = $intCountAvailIBlock; - $boolAll = true; + + - - +

+

+ > + onclick="checkAll(this,);" + >

- - $arIBlock):?> -
+
- - ]" - id="IBLOCK_EXPORT" - value="" - - onclick="checkOne(this,);" - > -
-
-
"> - > - +
+ + + + + onclick="checkOne(this,);" + > +
+
+
+
+ > + - + - + - - + + - $property): ?> - + getIblockPropsNames() as $propertyKey => $property) { + $productSelected = false; ?> - + + + + if ($settingsService->isOptionHasPreset($propertyKey)) { + ?> + + + + isHlSelected( + $propertyKey, + $arIBlock['ID'], + $productHlTableName, + '_product' + ) + ) {?> + + + + + + - - + + + +
-
+
-
+
+ +
-
+
+ +
- + - - - - - - - - - - - - + + + - - + - +
+
+
+
+
+ +
+ +
+

+

+

+   + > +


+ +

+
+
+
+
+
+   + +
+ +
+ - - - -
-
+   +


+ +

+


+ +

+


+ + + + + + + + +
+
+ +
+
+
+ + + + + + + + +
- - - - -
- -

- -

- -
-
- -   - > - -
-
-
- -   - - -
-
-
- - -

- -
-
-
- - - -

- -
-
-
- - - - - - - - - $hlblock) { - $vals .= ',highloadblock' . $hlblockTable . '_' . $val; - } - - foreach ($hlblockList as $hlblockTable => $hlblock) { - $vals .= ',highloadblock_product' . $hlblockTable . '_' . $val; - } + + + diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index d9ca2f79..960cab1b 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -6,13 +6,17 @@ * Class name: intaro_retailcrm */ global $MESS; + +use Bitrix\Highloadblock\HighloadBlockTable; use Bitrix\Main\Context; +use Bitrix\Sale\EventActions; use Intaro\RetailCrm\Icml\IcmlDirector; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetup; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupProps; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetupPropsCategories; use Intaro\RetailCrm\Repository\CatalogRepository; use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder; +use RetailCrm\ApiClient; use RetailCrm\Exception\CurlException; use RetailCrm\Response\ApiResponse; @@ -138,7 +142,9 @@ class intaro_retailcrm extends CModule include($this->INSTALL_PATH . '/../classes/general/RCrmActions.php'); include($this->INSTALL_PATH . '/../classes/general/user/RetailCrmUser.php'); include($this->INSTALL_PATH . '/../classes/general/events/RetailCrmEvent.php'); + include($this->INSTALL_PATH . '/../classes/general/RetailcrmConfigProvider.php'); include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/offerparam.php'); + include($this->INSTALL_PATH . '/../lib/icml/settingsservice.php'); include($this->INSTALL_PATH . '/../lib/component/agent.php'); include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/selectparams.php'); include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/unit.php'); @@ -346,7 +352,7 @@ class intaro_retailcrm extends CModule return; } - $this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); + $this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); COption::SetOptionString($this->MODULE_ID, $this->CRM_SITES_LIST, serialize($siteCode)); } else { $api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION])); @@ -380,7 +386,7 @@ class intaro_retailcrm extends CModule return; } - $this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); + $this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host); COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key); COption::SetOptionString($this->MODULE_ID, $this->CRM_SITES_LIST, serialize(array())); @@ -473,7 +479,7 @@ class intaro_retailcrm extends CModule // api load $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); - $this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); + $this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); //bitrix orderTypesList $arResult['arSites'] = RCrmActions::SitesList(); @@ -714,10 +720,10 @@ class intaro_retailcrm extends CModule && $_POST['ajax'] == 1 ) { CModule::IncludeModule('highloadblock'); - $rsData = \Bitrix\Highloadblock\HighloadBlockTable::getList(array('filter' => array('TABLE_NAME' => $_POST['table']))); + $rsData = HighloadBlockTable::getList(array('filter' => array('TABLE_NAME' => $_POST['table']))); $hlblockArr = $rsData->Fetch(); - $hlblock = \Bitrix\Highloadblock\HighloadBlockTable::getById($hlblockArr["ID"])->fetch(); - $entity = \Bitrix\Highloadblock\HighloadBlockTable::compileEntity($hlblock); + $hlblock = HighloadBlockTable::getById($hlblockArr["ID"])->fetch(); + $entity = HighloadBlockTable::compileEntity($hlblock); $hbFields = $entity->getFields(); $hlblockList['table'] = $hlblockArr["TABLE_NAME"]; @@ -741,7 +747,7 @@ class intaro_retailcrm extends CModule $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); - $api = new \RetailCrm\ApiClient($api_host, $api_key); + $api = new ApiClient($api_host, $api_key); $customerH = self::historyLoad($api, 'customersHistory'); COption::SetOptionString($this->MODULE_ID, $this->CRM_CUSTOMER_HISTORY, $customerH); @@ -839,10 +845,10 @@ class intaro_retailcrm extends CModule ); } - if (!isset($_POST['IBLOCK_EXPORT'])) { + if (!isset($_POST['iblockExport'])) { $arResult['errCode'] = 'ERR_FIELDS_IBLOCK'; } else { - $iblocks = $_POST['IBLOCK_EXPORT']; + $iblocks = $_POST['iblockExport']; } $hlblockModule = false; @@ -850,11 +856,11 @@ class intaro_retailcrm extends CModule if (CModule::IncludeModule('highloadblock')) { $hlblockModule = true; $hlblockList = array(); - $hlblockListDb = \Bitrix\Highloadblock\HighloadBlockTable::getList(); + $hlblockListDb = HighloadBlockTable::getList(); while ($hlblockArr = $hlblockListDb->Fetch()) { - $hlblock = \Bitrix\Highloadblock\HighloadBlockTable::getById($hlblockArr["ID"])->fetch(); - $entity = \Bitrix\Highloadblock\HighloadBlockTable::compileEntity($hlblock); + $hlblock = HighloadBlockTable::getById($hlblockArr["ID"])->fetch(); + $entity = HighloadBlockTable::compileEntity($hlblock); $hbFields = $entity->getFields(); $hlblockList[$hlblockArr["TABLE_NAME"]]['LABEL'] = $hlblockArr["NAME"]; @@ -875,16 +881,16 @@ class intaro_retailcrm extends CModule "height" => "height", "picture" => "picture", ); - - $propertiesSKU = array(); - $propertiesUnitSKU = array(); - $propertiesHbSKU = array(); - + + $propertiesSKU = []; + $propertiesUnitSKU = []; + $propertiesHbSKU = []; + foreach ($iblockProperties as $prop) { - foreach ($_POST['IBLOCK_PROPERTY_SKU'. '_' . $prop] as $iblock => $val) { + foreach ($_POST['iblockPropertySku'. '_' . $prop] as $iblock => $val) { $propertiesSKU[$iblock][$prop] = $val; } - foreach ($_POST['IBLOCK_PROPERTY_UNIT_SKU'. '_' . $prop] as $iblock => $val) { + foreach ($_POST['iblockPropertyUnitSku'. '_' . $prop] as $iblock => $val) { $propertiesUnitSKU[$iblock][$prop] = $val; } @@ -897,15 +903,15 @@ class intaro_retailcrm extends CModule } } - $propertiesProduct = array(); - $propertiesUnitProduct = array(); - $propertiesHbProduct = array(); + $propertiesProduct = []; + $propertiesUnitProduct = []; + $propertiesHbProduct = []; foreach ($iblockProperties as $prop) { - foreach ($_POST['IBLOCK_PROPERTY_PRODUCT'. '_' . $prop] as $iblock => $val) { + foreach ($_POST['iblockPropertyProduct'. '_' . $prop] as $iblock => $val) { $propertiesProduct[$iblock][$prop] = $val; } - foreach ($_POST['IBLOCK_PROPERTY_UNIT_PRODUCT'. '_' . $prop] as $iblock => $val) { + foreach ($_POST['iblockPropertyUnitProduct'. '_' . $prop] as $iblock => $val) { $propertiesUnitProduct[$iblock][$prop] = $val; } @@ -930,14 +936,14 @@ class intaro_retailcrm extends CModule $typeLoading = $_POST['TYPE_LOADING']; } - if (!isset($_POST['MAX_OFFERS_VALUE'])) { + if (!isset($_POST['maxOffersValue'])) { $maxOffers = null; } else { - $maxOffers = (int) $_POST['MAX_OFFERS_VALUE']; + $maxOffers = (int) $_POST['maxOffersValue']; } if (!isset($_POST['SETUP_PROFILE_NAME'])) { - $profileName = ""; + $profileName = ''; } else { $profileName = $_POST['SETUP_PROFILE_NAME']; } @@ -946,22 +952,24 @@ class intaro_retailcrm extends CModule $arResult['errCode'] = 'ERR_FIELDS_PROFILE'; } - if ($filename == "") { + if ($filename === '') { $arResult['errCode'] = 'ERR_FIELDS_FILE'; } if (isset($arResult['errCode']) && $arResult['errCode']) { - $arOldValues = array( - 'IBLOCK_EXPORT' => $iblocks, - 'IBLOCK_PROPERTY_SKU' => $propertiesSKU, - 'IBLOCK_PROPERTY_UNIT_SKU' => $propertiesUnitSKU, - 'IBLOCK_PROPERTY_PRODUCT' => $propertiesProduct, - 'IBLOCK_PROPERTY_UNIT_PRODUCT' => $propertiesUnitProduct, + $arOldValues = [ + 'iblockExport' => $iblocks, + 'iblockPropertySku' => $propertiesSKU, + 'iblockPropertyUnitSku' => $propertiesUnitSKU, + 'iblockPropertyProduct' => $propertiesProduct, + 'iblockPropertyUnitProduct' => $propertiesUnitProduct, 'SETUP_FILE_NAME' => $filename, 'SETUP_PROFILE_NAME' => $profileName, - 'MAX_OFFERS_VALUE' => $maxOffers - ); + 'maxOffersValue' => $maxOffers, + ]; + global $oldValues; + $oldValues = $arOldValues; $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step5.php' @@ -973,7 +981,7 @@ class intaro_retailcrm extends CModule RegisterModule($this->MODULE_ID); RegisterModuleDependences("sale", "OnOrderUpdate", $this->MODULE_ID, "RetailCrmEvent", "onUpdateOrder"); RegisterModuleDependences("main", "OnAfterUserUpdate", $this->MODULE_ID, "RetailCrmEvent", "OnAfterUserUpdate"); - RegisterModuleDependences("sale", \Bitrix\Sale\EventActions::EVENT_ON_ORDER_SAVED, $this->MODULE_ID, "RetailCrmEvent", "orderSave"); + RegisterModuleDependences("sale", EventActions::EVENT_ON_ORDER_SAVED, $this->MODULE_ID, "RetailCrmEvent", "orderSave"); RegisterModuleDependences("sale", "OnSaleOrderDeleted", $this->MODULE_ID, "RetailCrmEvent", "orderDelete"); RegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave"); RegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $this->MODULE_ID, "RetailCrmEvent", "paymentDelete"); @@ -1014,13 +1022,16 @@ class intaro_retailcrm extends CModule } } - + + $setupVars = $this->getProfileSetupVars( $iblocks, - $propertiesProduct, - $propertiesUnitProduct, - $propertiesSKU, - $propertiesUnitSKU, + [ + 'iblockPropertySku' => $propertiesSKU, + 'iblockPropertyUnitSku' => $propertiesUnitSKU, + 'iblockPropertyProduct' => $propertiesProduct, + 'iblockPropertyUnitProduct' => $propertiesUnitProduct, + ], $propertiesHbSKU, $propertiesHbProduct, $filename, @@ -1166,7 +1177,7 @@ class intaro_retailcrm extends CModule $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); $api_version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0); - $this->RETAIL_CRM_API = new \RetailCrm\ApiClient($api_host, $api_key); + $this->RETAIL_CRM_API = new ApiClient($api_host, $api_key); RCrmActions::sendConfiguration($this->RETAIL_CRM_API, $api_version); @@ -1202,7 +1213,7 @@ class intaro_retailcrm extends CModule include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v5.php'); } - $retail_crm_api = new \RetailCrm\ApiClient($api_host, $api_key); + $retail_crm_api = new ApiClient($api_host, $api_key); CAgent::RemoveAgent("RCrmActions::orderAgent();", $this->MODULE_ID); CAgent::RemoveAgent("RetailCrmInventories::inventoriesUpload();", $this->MODULE_ID); @@ -1256,7 +1267,7 @@ class intaro_retailcrm extends CModule if (CModule::IncludeModule('sale')) { UnRegisterModuleDependences( "sale", - \Bitrix\Sale\EventActions::EVENT_ON_ORDER_SAVED, + EventActions::EVENT_ON_ORDER_SAVED, $this->MODULE_ID, "RetailCrmEvent", "orderSave" @@ -1313,8 +1324,9 @@ class intaro_retailcrm extends CModule function DeleteFiles() { - $rsSites = CSite::GetList($by, $sort, array('DEF' => 'Y')); - $defaultSite = array(); + $rsSites = CSite::GetList($by, $sort, ['DEF' => 'Y']); + $defaultSite = []; + while ($ar = $rsSites->Fetch()) { $defaultSite = $ar; break; @@ -1328,45 +1340,54 @@ class intaro_retailcrm extends CModule function getProfileSetupVars( $iblocks, - $propertiesProduct, - $propertiesUnitProduct, - $propertiesSKU, - $propertiesUnitSKU, + $simpleProps, $propertiesHbSKU, $propertiesHbProduct, $filename, $maxOffers - ) { - $strVars = ""; - foreach ($iblocks as $key => $val) - $strVars .= 'IBLOCK_EXPORT[' . $key . ']=' . $val . '&'; - foreach ($propertiesSKU as $iblock => $arr) - foreach ($arr as $id => $val) - $strVars .= 'IBLOCK_PROPERTY_SKU_' . $id . '[' . $iblock . ']=' . $val . '&'; - foreach ($propertiesUnitSKU as $iblock => $arr) - foreach ($arr as $id => $val) - $strVars .= 'IBLOCK_PROPERTY_UNIT_SKU_' . $id . '[' . $iblock . ']=' . $val . '&'; - foreach ($propertiesProduct as $iblock => $arr) - foreach ($arr as $id => $val) - $strVars .= 'IBLOCK_PROPERTY_PRODUCT_' . $id . '[' . $iblock . ']=' . $val . '&'; - foreach ($propertiesUnitProduct as $iblock => $arr) - foreach ($arr as $id => $val) - $strVars .= 'IBLOCK_PROPERTY_UNIT_PRODUCT_' . $id . '[' . $iblock . ']=' . $val . '&'; - if ($propertiesHbSKU) { - foreach ($propertiesHbSKU as $table => $arr) - foreach ($arr as $iblock => $val) - foreach ($val as $id => $value) - $strVars .= 'highloadblock' . $table . '_' . $id . '[' . $iblock . ']=' . $value . '&'; + ): string { + $strVars = ''; + + foreach ($iblocks as $key => $val) { + $strVars .= 'iblockExport[' . $key . ']=' . $val . '&'; } + + foreach ($simpleProps as $propType => $props) { + $strVars = $this->addToStrVars($strVars, $propType, $props); + } + + if ($propertiesHbSKU) { + foreach ($propertiesHbSKU as $table => $arr) { + $strVars = $this->addToStrVars($strVars, 'highloadblock' . $table, $arr); + } + } + if ($propertiesHbProduct) { - foreach ($propertiesHbProduct as $table => $arr) - foreach ($arr as $iblock => $val) - foreach ($val as $id => $value) - $strVars .= 'highloadblock_product' . $table . '_' . $id . '[' . $iblock . ']=' . $value . '&'; + foreach ($propertiesHbProduct as $table => $arr) { + $strVars = $this->addToStrVars($strVars, 'highloadblock_product' . $table, $arr); + } } $strVars .= 'SETUP_FILE_NAME=' . urlencode($filename); - $strVars .= '&MAX_OFFERS_VALUE=' . urlencode($maxOffers); + $strVars .= '&maxOffersValue=' . urlencode($maxOffers); + + return $strVars; + } + + /** + * @param string $strVars + * @param string $propType + * @param array $props + * + * @return string + */ + public function addToStrVars(string $strVars, string $propType, array $props): string + { + foreach ($props as $iblock => $arr) { + foreach ($arr as $id => $val) { + $strVars .= $propType . '_' . $id . '[' . $iblock . ']=' . $val . '&'; + } + } return $strVars; } diff --git a/intaro.retailcrm/install/step5.php b/intaro.retailcrm/install/step5.php index 51c99670..19f2d613 100644 --- a/intaro.retailcrm/install/step5.php +++ b/intaro.retailcrm/install/step5.php @@ -1,698 +1,12 @@ - -if(!check_bitrix_sessid()) return; -IncludeModuleLangFile(__FILE__); -__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.retailcrm/lang/", "/icml_export_setup.php")); -?> -

- - - -
-

-

- GetMessage("PROPERTY_ARTICLE_HEADER_NAME"), - "manufacturer" => GetMessage("PROPERTY_MANUFACTURER_HEADER_NAME"), - "color" => GetMessage("PROPERTY_COLOR_HEADER_NAME"), - "size" => GetMessage("PROPERTY_SIZE_HEADER_NAME"), - "weight" => GetMessage("PROPERTY_WEIGHT_HEADER_NAME"), - "length" => GetMessage("PROPERTY_LENGTH_HEADER_NAME"), - "width" => GetMessage("PROPERTY_WIDTH_HEADER_NAME"), - "height" => GetMessage("PROPERTY_HEIGHT_HEADER_NAME"), - "picture" => GetMessage("PROPERTY_PICTURE_HEADER_NAME"), - ); - - $iblockFieldsName = Array( - "weight" => Array("code" => "catalog_size" , "name" => GetMessage("SELECT_WEIGHT_PROPERTY_NAME"), 'unit' => 'mass'), - "length" => Array("code" => "catalog_length" , "name" => GetMessage("SELECT_LENGTH_PROPERTY_NAME"), 'unit' => 'length'), - "width" => Array("code" => "catalog_width" , "name" => GetMessage("SELECT_WIDTH_PROPERTY_NAME"), 'unit' => 'length'), - "height" => Array("code" => "catalog_height" , "name" => GetMessage("SELECT_HEIGHT_PROPERTY_NAME"), 'unit' => 'length'), - ); - - $iblockPropertiesHint = Array( - "article" => Array("ARTICLE", "ART", "ARTNUMBER", "ARTICUL", "ARTIKUL"), - "manufacturer" => Array("MANUFACTURER", "PROISVODITEL", "PROISVOD", "PROISV"), - "color" => Array("COLOR", "CVET"), - "size" => Array("SIZE", "RAZMER"), - "weight" => Array("WEIGHT", "VES", "VEC"), - "length" => Array("LENGTH", "DLINA"), - "width" => Array("WIDTH", "SHIRINA"), - "height" => Array("HEIGHT", "VISOTA"), - "picture" => Array("PICTURE", "PICTURE"), - ); - - $units = Array( - 'length' => Array( - 'mm' => GetMessage("UNIT_MEASUREMENT_MM"), - 'cm' => GetMessage("UNIT_MEASUREMENT_CM"), - 'm' => GetMessage("UNIT_MEASUREMENT_M"), - ), - 'mass' => Array( - 'mg' => GetMessage("UNIT_MEASUREMENT_MG"), - 'g' => GetMessage("UNIT_MEASUREMENT_G"), - 'kg' => GetMessage("UNIT_MEASUREMENT_KG"), - ) - ); - - $hintUnit = Array( - 'length' => 'mm', - 'mass' => 'g' - ); - - $boolAll = false; - $intCountChecked = 0; - $intCountAvailIBlock = 0; - $arIBlockList = array(); - $db_res = CIBlock::GetList(Array("IBLOCK_TYPE"=>"ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W')); - while ($iblock = $db_res->Fetch()) - { - if ($arCatalog = CCatalog::GetByIDExt($iblock["ID"])) - { - if($arCatalog['CATALOG_TYPE'] == "D" || $arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") - { - $propertiesSKU = null; - if ($arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") - { - $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock["ID"]); - - $db_properties = CIBlock::GetProperties($iblockOffer['IBLOCK_ID'], Array()); - while($prop = $db_properties->Fetch()) - $propertiesSKU[] = $prop; - - $oldPropertySKU = null; - if (isset($IBLOCK_PROPERTY_SKU[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertySKU[$key] = $IBLOCK_PROPERTY_SKU[$iblock['ID']][$key]; - } - } - $oldPropertyUnitSKU = null; - if (isset($IBLOCK_PROPERTY_UNIT_SKU[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertyUnitSKU[$key] = $IBLOCK_PROPERTY_UNIT_SKU[$iblock['ID']][$key]; - } - } - } - - - $propertiesProduct = null; - $db_properties = CIBlock::GetProperties($iblock['ID'], Array()); - while($prop = $db_properties->Fetch()) - $propertiesProduct[] = $prop; - - $oldPropertyProduct = null; - if (isset($IBLOCK_PROPERTY_PRODUCT[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertyProduct[$key] = $IBLOCK_PROPERTY_PRODUCT[$iblock['ID']][$key]; - } - } - - $oldPropertyUnitProduct = null; - if (isset($IBLOCK_PROPERTY_UNIT_PRODUCT[$iblock['ID']])) { - foreach ($iblockPropertiesName as $key => $prop) { - $oldPropertyUnitProduct[$key] = $IBLOCK_PROPERTY_UNIT_PRODUCT[$iblock['ID']][$key]; - } - } - - $arSiteList = array(); - $rsSites = CIBlock::GetSite($iblock["ID"]); - while ($arSite = $rsSites->Fetch()) - { - $arSiteList[] = $arSite["SITE_ID"]; - } - - if (count($IBLOCK_EXPORT) != 0) - $boolExport = (in_array($iblock['ID'], $IBLOCK_EXPORT)); - else - $boolExport = true; - - $arIBlockList[] = array( - 'ID' => $iblock['ID'], - 'NAME' => $iblock['NAME'], - 'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'], - 'IBLOCK_EXPORT' => $boolExport, - 'PROPERTIES_SKU' => $propertiesSKU, - 'PROPERTIES_PRODUCT' => $propertiesProduct, - 'OLD_PROPERTY_SKU_SELECT' => $oldPropertySKU, - 'OLD_PROPERTY_UNIT_SKU_SELECT' => $oldPropertyUnitSKU, - 'OLD_PROPERTY_PRODUCT_SELECT' => $oldPropertyProduct, - 'OLD_PROPERTY_UNIT_PRODUCT_SELECT' => $oldPropertyUnitProduct, - 'SITE_LIST' => '('.implode(' ',$arSiteList).')', - ); - - if ($boolExport) - $intCountChecked++; - $intCountAvailIBlock++; - } - } - } - if (count($IBLOCK_EXPORT) != 0) { - if ($intCountChecked == $intCountAvailIBlock) - $boolAll = true; - } else { - $intCountChecked = $intCountAvailIBlock; - $boolAll = true; - } - - ?> - - - > -
-
-
- - $arIBlock):?> -
-
- - ]" - id="IBLOCK_EXPORT" - value="" - - onclick="checkOne(this,);" - > -
-
-
"> - > - - - - - - - - - - - - $property): ?> - - - - - - - - - - - - -
-
-
-
-
-
-
- - - - - - - - - - - - - -
-
-
-
-
- -
- - -
- - -

- -
-
-
- -
-  

- -
-
-
-
- -

-
-
-
-
-
-   - -
- -
-   - -
-
-
- -
-   - " - size="30"> -
-
-
-
- - - - - - - - - - - - - -
-
- " - class="adm-btn-save"> -
-
- " class="adm-btn-save"> -
-
-
diff --git a/intaro.retailcrm/lang/en/export_setup_templ.php b/intaro.retailcrm/lang/en/export_setup_templ.php deleted file mode 100644 index 6d8e63f2..00000000 --- a/intaro.retailcrm/lang/en/export_setup_templ.php +++ /dev/null @@ -1,125 +0,0 @@ -Default path for the exported files in module settings."; -$MESS["CAT_ADM_CSV_EXP_TAB1"] = "Info block"; -$MESS["CAT_ADM_CSV_EXP_TAB1_TITLE"] = "Select info block for export"; -$MESS["CAT_ADM_CSV_EXP_TAB2"] = "Export parameters"; -$MESS["CAT_ADM_CSV_EXP_TAB2_TITLE"] = "Export parameters settings"; -$MESS["CAT_ADM_CSV_EXP_TAB3"] = "Result"; -$MESS["CAT_ADM_CSV_EXP_TAB3_TITLE"] = "Export result"; -$MESS["CAT_ADM_CSV_EXP_IBLOCK_ID"] = "Info block"; -$MESS["CAT_ADM_CSV_EXP_ADD_SETTINGS"] = "Additional settings"; -$MESS["CAT_ADM_CSV_EXP_EXPORT_FILES"] = "Export files"; -$MESS["CAT_ADM_CSV_EXP_TIME_STEP"] = "Step execution time"; -$MESS["CAT_ADM_CSV_EXP_TIME_STEP_COMMENT"] = "0 - load all at once
positive value - number of seconds to complete a single step"; -$MESS["CAT_ADM_CSV_EXP_SEP_ELEMENTS"] = "Fields and properties of elements"; -$MESS["CAT_ADM_CSV_EXP_SEP_SECTIONS"] = "Sections fields"; -$MESS["CAT_ADM_CSV_EXP_SEP_SECTIONS_EXT"] = "Fields and custom properties of sections"; -$MESS["CAT_ADM_CSV_EXP_SEP_PRODUCT"] = "Product properties"; -$MESS["CAT_ADM_CSV_EXP_SEP_PRICES"] = "Prices"; -$MESS["CAT_ADM_CSV_EXP_SEP_SKU"] = "Fields and properties of trade offers"; -$MESS["CAT_ADM_CSV_EXP_DESCR_SECT_PROP"] = "Custom property"; -$MESS["CAT_ADM_CSV_EXP_SECTION_LEVEL"] = "Level group #LEVEL#"; -$MESS["CATI_FI_PRICE_TYPE2"] = "Price type \"#TYPE#\""; -$MESS["CATI_FI_PRICE_TYPE3"] = "Price type \"#NAME#\" (#TYPE#)"; -$MESS["CATI_FI_PRICE_CURRENCY"] = "in currency #CURRENCY#"; diff --git a/intaro.retailcrm/lang/en/icml_export_setup.php b/intaro.retailcrm/lang/en/icml_export_setup.php index 31844baf..64a41ca9 100644 --- a/intaro.retailcrm/lang/en/icml_export_setup.php +++ b/intaro.retailcrm/lang/en/icml_export_setup.php @@ -9,8 +9,8 @@ $MESS["FILENAME"] = "Specify data file name:"; $MESS["LOAD_PURCHASE_PRICE"] = "Export purchase price"; $MESS["PROPERTY"] = "Property that contains product article"; $MESS["ALL_CATALOG"] = "All catalogs"; -$MESS["CET_EXPORT"] = "Export"; -$MESS["CET_SAVE"] = "Save"; +$MESS["EXPORT"] = "Export"; +$MESS["SAVE"] = "Save"; $MESS["ERROR_IBLOCK_MODULE"] = "Module Info blocks not installed"; $MESS["ERROR_IBLOCK_CATALOG"] = "Module Catalog not installed"; $MESS["ERROR_IBLOCK_INTAROCRM"] = "Module RetailCRM not installed"; diff --git a/intaro.retailcrm/lang/ru/export_setup_templ.php b/intaro.retailcrm/lang/ru/export_setup_templ.php deleted file mode 100644 index 5f6d578a..00000000 --- a/intaro.retailcrm/lang/ru/export_setup_templ.php +++ /dev/null @@ -1,125 +0,0 @@ -Путь по умолчанию для экспортируемых файлов настроек модуля."; -$MESS["CAT_ADM_CSV_EXP_TAB1"] = "Инфоблок"; -$MESS["CAT_ADM_CSV_EXP_TAB1_TITLE"] = "Выбор информационного блока для экспорта"; -$MESS["CAT_ADM_CSV_EXP_TAB2"] = "Параметры экспорта"; -$MESS["CAT_ADM_CSV_EXP_TAB2_TITLE"] = "Настройка параметров экспорта"; -$MESS["CAT_ADM_CSV_EXP_TAB3"] = "Результат"; -$MESS["CAT_ADM_CSV_EXP_TAB3_TITLE"] = "Результат экспорта"; -$MESS["CAT_ADM_CSV_EXP_IBLOCK_ID"] = "Инфоблок"; -$MESS["CAT_ADM_CSV_EXP_ADD_SETTINGS"] = "Дополнительные настройки"; -$MESS["CAT_ADM_CSV_EXP_EXPORT_FILES"] = "Выгружать файлы"; -$MESS["CAT_ADM_CSV_EXP_TIME_STEP"] = "Время выполнения шага"; -$MESS["CAT_ADM_CSV_EXP_TIME_STEP_COMMENT"] = "0 - загрузить все сразу
положительное значение - число секунд на выполнение одного шага"; -$MESS["CAT_ADM_CSV_EXP_SEP_ELEMENTS"] = "Поля и свойства элементов"; -$MESS["CAT_ADM_CSV_EXP_SEP_SECTIONS"] = "Поля разделов"; -$MESS["CAT_ADM_CSV_EXP_SEP_SECTIONS_EXT"] = "Поля и пользовательские свойства разделов"; -$MESS["CAT_ADM_CSV_EXP_SEP_PRODUCT"] = "Свойства товара"; -$MESS["CAT_ADM_CSV_EXP_SEP_PRICES"] = "Цены"; -$MESS["CAT_ADM_CSV_EXP_SEP_SKU"] = "Поля и свойства торговых предложений"; -$MESS["CAT_ADM_CSV_EXP_DESCR_SECT_PROP"] = "Пользовательское свойство"; -$MESS["CAT_ADM_CSV_EXP_SECTION_LEVEL"] = "Раздел уровня #LEVEL#"; -$MESS["CATI_FI_PRICE_TYPE2"] = "Цена типа \"#TYPE#\""; -$MESS["CATI_FI_PRICE_TYPE3"] = "Цена типа \"#NAME#\" (#TYPE#)"; -$MESS["CATI_FI_PRICE_CURRENCY"] = "в валюте #CURRENCY#"; diff --git a/intaro.retailcrm/lang/ru/icml_export_setup.php b/intaro.retailcrm/lang/ru/icml_export_setup.php index e58de29b..a1c66d57 100644 --- a/intaro.retailcrm/lang/ru/icml_export_setup.php +++ b/intaro.retailcrm/lang/ru/icml_export_setup.php @@ -1,4 +1,4 @@ - + * @license MIT + * @link http://retailcrm.ru + * @see http://retailcrm.ru/docs + */ + +namespace Intaro\RetailCrm\Controller; + +use Bitrix\Main\Engine\Controller; +use CModule; +use Intaro\RetailCrm\Service\Hl; + +/** + * Class Order + * + * @package Intaro\RetailCrm\Controller\Loyalty + */ +class Icml extends Controller +{ + /** + * @param string|null $tableName + * + * @return array + */ + public function getHlTableAction(?string $tableName): array + { + $hlBlockList = []; + + CModule::IncludeModule('highloadblock'); + $entity = Hl::getBaseEntityByTableName($tableName ?? null); + + if ($entity) { + $hbFields = $entity->getFields(); + $hlBlockList['table'] = $entity->getDBTableName(); + + foreach ($hbFields as $hbFieldCode => $hbField) { + $hlBlockList['fields'][] = $hbFieldCode; + } + + return $hlBlockList; + } + } +} diff --git a/intaro.retailcrm/lib/icml/icmldirector.php b/intaro.retailcrm/lib/icml/icmldirector.php index e38265cd..17f81ba2 100644 --- a/intaro.retailcrm/lib/icml/icmldirector.php +++ b/intaro.retailcrm/lib/icml/icmldirector.php @@ -182,6 +182,7 @@ class IcmlDirector $this->setup->properties->sku->names[$productIblockId], $this->setup->basePriceId ); + $this->writeOffersAsOffersInXml($paramsForProduct, $paramsForOffer, $catalogIblockInfo); } diff --git a/intaro.retailcrm/lib/icml/settingsservice.php b/intaro.retailcrm/lib/icml/settingsservice.php new file mode 100644 index 00000000..95a89e43 --- /dev/null +++ b/intaro.retailcrm/lib/icml/settingsservice.php @@ -0,0 +1,714 @@ +arOldSetupVars = $arOldSetupVars; + $this->action = $action; + $this->iblockExport = $this->getSingleSetting('iblockExport'); + $this->loadPurchasePrice = $this->getSingleSetting('loadPurchasePrice'); + $oldSetup = $this->getSingleSetting('SETUP_FILE_NAME'); + $defaultFilePath = RetailcrmConfigProvider::getDefaultIcmlPath(); + $this->setupFileName = htmlspecialcharsbx($oldSetup ?? $defaultFilePath); + $this->setupProfileName + = $this->getSingleSetting('SETUP_PROFILE_NAME') ?? GetMessage('PROFILE_NAME_EXAMPLE'); + + $this->getPriceTypes(); + } + + /** + * @param array $arOldSetupVars + * @param string|null $action + * + * @return \Intaro\RetailCrm\Icml\SettingsService|null + */ + static public function getInstance(array $arOldSetupVars, ?string $action): ?SettingsService + { + if(is_null(self::$instance)) + { + self::$instance = new self($arOldSetupVars, $action); + } + return self::$instance; + } + + public function getPriceTypes() + { + $dbPriceType = CCatalogGroup::GetList(['SORT' => 'ASC'], [], [], [], ['ID', 'NAME', 'BASE']); + + while ($arPriceType = $dbPriceType->Fetch()) { + $this->priceTypes[$arPriceType['ID']] = $arPriceType; + } + } + + /** + * @param string $selected + * @param string $key + * @param int $iblockId + * @param string $field + * @param string $fieldGroup + * + * @return string + */ + public function getHlOptionStatus(string $selected, string $key, int $iblockId, string $field, string $fieldGroup): string + { + if ($this->arOldSetupVars[$fieldGroup . $selected . '_' . $key][$iblockId] === $field) { + return ' selected'; + } + + return ''; + } + + /** + * @param string $key + * @param int $iblockId + * @param string $tableName + * @param string $catalogType + * + * @return bool + */ + public function isHlSelected( + string $key, + int $iblockId, + string $tableName = '', + string $catalogType = '' + ): bool { + return isset( + $tableName, + $this->arOldSetupVars['highloadblock' . $catalogType . $tableName . '_' .$key][$iblockId] + ); + } + + /** + * @param string $key + * + * @return bool + */ + public function isOptionHasPreset(string $key): bool + { + return version_compare(SM_VERSION, '14.0.0', '>=') + && array_key_exists($key, $this->getIblockFieldsNames()); + } + + /** + * @return bool + */ + public function isSetupModulePage(): bool + { + global $APPLICATION; + + return $APPLICATION->GetCurPage() === '/bitrix/admin/partner_modules.php'; + } + + /** + * @param array $properties + * @param string $propName + */ + private function setProperties(array &$properties, string $propName): void + { + foreach ($this->arOldSetupVars[$propName] as $iblock => $val) { + $properties[$iblock][$propName] = $val; + } + } + + /** + * @return mixed|string + */ + public function getSingleSetting(string $settingName) + { + return $this->arOldSetupVars[$settingName] ?? null; + } + + /** + * @return string[] + */ + public function getIblockPropsPreset(): array + { + return [ + 'article' => 'article', + 'manufacturer' => 'manufacturer', + 'color' => 'color', + 'size' => 'size', + 'weight' => 'weight', + 'length' => 'length', + 'width' => 'width', + 'height' => 'height', + 'picture' => 'picture', + ]; + } + + /** + * @return array + */ + public function getHintProps(): array + { + return [ + 'article' => ['ARTICLE', 'ART', 'ARTNUMBER', 'ARTICUL', 'ARTIKUL'], + 'manufacturer' => ['MANUFACTURER', 'PROISVODITEL', 'PROISVOD', 'PROISV'], + 'color' => ['COLOR', 'CVET'], + 'size' => ['SIZE', 'RAZMER'], + 'weight' => ['WEIGHT', 'VES', 'VEC'], + 'length' => ['LENGTH', 'DLINA'], + 'width' => ['WIDTH', 'SHIRINA'], + 'height' => ['HEIGHT', 'VISOTA'], + 'picture' => ['PICTURE', 'PICTURE'], + ]; + } + + /** + * @return array + */ + public function getIblockPropsNames(): array + { + return [ + 'article' => GetMessage('PROPERTY_ARTICLE_HEADER_NAME'), + 'manufacturer' => GetMessage('PROPERTY_MANUFACTURER_HEADER_NAME'), + 'color' => GetMessage('PROPERTY_COLOR_HEADER_NAME'), + 'size' => GetMessage('PROPERTY_SIZE_HEADER_NAME'), + 'weight' => GetMessage('PROPERTY_WEIGHT_HEADER_NAME'), + 'length' => GetMessage('PROPERTY_LENGTH_HEADER_NAME'), + 'width' => GetMessage('PROPERTY_WIDTH_HEADER_NAME'), + 'height' => GetMessage('PROPERTY_HEIGHT_HEADER_NAME'), + 'picture' => GetMessage('PROPERTY_PICTURE_HEADER_NAME'), + ]; + } + + /** + * @return array[] + */ + public function getIblockFieldsNames(): array + { + return [ + 'weight' => [ + 'CODE' => 'catalog_weight', + 'name' => GetMessage('SELECT_WEIGHT_PROPERTY_NAME'), + 'unit' => 'mass', + ], + 'length' => [ + 'CODE' => 'catalog_length', + 'name' => GetMessage('SELECT_LENGTH_PROPERTY_NAME'), + 'unit' => 'length', + ], + 'width' => [ + 'CODE' => 'catalog_width', + 'name' => GetMessage('SELECT_WIDTH_PROPERTY_NAME'), + 'unit' => 'length', + ], + 'height' => [ + 'CODE' => 'catalog_height', + 'name' => GetMessage('SELECT_HEIGHT_PROPERTY_NAME'), + 'unit' => 'length', + ], + ]; + } + + /** + * @return array[] + */ + public function getUnitsNames(): array + { + return [ + 'length' => [ + 'mm' => GetMessage('UNIT_MEASUREMENT_MM'), + 'cm' => GetMessage('UNIT_MEASUREMENT_CM'), + 'm' => GetMessage('UNIT_MEASUREMENT_M'), + ], + 'mass' => [ + 'mg' => GetMessage('UNIT_MEASUREMENT_MG'), + 'g' => GetMessage('UNIT_MEASUREMENT_G'), + 'kg' => GetMessage('UNIT_MEASUREMENT_KG'), + ], + ]; + } + + /** + * @return string[] + */ + public function getHintUnit(): array + { + return [ + 'length' => 'mm', + 'mass' => 'g', + ]; + } + + public function setProps(): void + { + foreach ($this->getIblockPropsPreset() as $prop) { + $this->setProperties($this->iblockPropertySku, 'iblockPropertySku_' . $prop); + $this->setProperties($this->iblockPropertyUnitSku, 'iblockPropertyUnitSku_' . $prop); + $this->setProperties($this->iblockPropertyProduct, 'iblockPropertyProduct_' . $prop); + $this->setProperties($this->iblockPropertyUnitProduct, 'iblockPropertyUnitProduct_' . $prop); + } + } + + /** + * @param string|null $setupFileName + * @param string $setupProfileName + * + * @return array + */ + private function checkFileAndProfile(?string $setupFileName, string $setupProfileName): array + { + global $APPLICATION; + + $arSetupErrors = []; + + if (strlen($setupFileName) <= 0) { + $arSetupErrors[] = GetMessage('ERROR_NO_FILENAME'); + } elseif ($APPLICATION->GetFileAccessPermission($setupFileName) < 'W') { + $arSetupErrors[] = str_replace('#FILE#', $setupFileName, + GetMessage('FILE_ACCESS_DENIED')); + } + + $isValidAction = ( + $this->action === 'EXPORT_SETUP' + || $this->action === 'EXPORT_EDIT' + || $this->action === 'EXPORT_COPY' + ); + + if ($isValidAction && strlen($setupProfileName) <= 0) { + $arSetupErrors[] = GetMessage('ERROR_NO_PROFILE_NAME'); + } + + return $arSetupErrors; + } + + /** + * @return array + * @throws \Bitrix\Main\ArgumentException + * @throws \Bitrix\Main\LoaderException + * @throws \Bitrix\Main\ObjectPropertyException + * @throws \Bitrix\Main\SystemException + */ + public function getHlBlockList(): array + { + $hlBlockList = []; + $hlblockListDb = HighloadBlockTable::getList(); + + while ($hlblockArr = $hlblockListDb->Fetch()) { + $entity = Hl::getBaseEntityByHlId($hlblockArr['ID']); + $hbFields = $entity->getFields(); + $hlBlockList[$hlblockArr['TABLE_NAME']]['LABEL'] = $hlblockArr['NAME']; + + foreach ($hbFields as $hbFieldCode => $hbField) { + $hlBlockList[$hlblockArr['TABLE_NAME']]['FIELDS'][] = $hbFieldCode; + } + } + + return $hlBlockList; + } + + /** + * @param array $iblockProperties + * @param bool $hlblockModule + * @param array $hlBlockList + * + * @return string + */ + public function getSetupFieldsString(array $iblockProperties, bool $hlblockModule, array $hlBlockList): string + { + $values = 'loadPurchasePrice,SETUP_FILE_NAME,iblockExport,maxOffersValue'; + + foreach ($iblockProperties as $val) { + $values .= ',iblockPropertySku_' . $val + . ',iblockPropertyUnitSku_' . $val + . ',iblockPropertyProduct_' . $val + . ',iblockPropertyUnitProduct_' . $val; + + if ($hlblockModule === true && $val !== 'picture') { + foreach ($hlBlockList as $hlblockTable => $hlblock) { + $values .= ',highloadblock' . $hlblockTable . '_' . $val; + $values .= ',highloadblock_product' . $hlblockTable . '_' . $val; + } + } + } + + return $values; + } + + /** + * @param array $prop + * + * @return string|null + */ + public function getHlTableName(array $prop): ?string + { + if ($prop['USER_TYPE'] === 'directory') { + return $prop['USER_TYPE_SETTINGS']['TABLE_NAME']; + } + + return null; + } + + + /** + * @param array $prop + * @param array|null $oldSelect + * @param string $key + * + * @return bool + */ + public function isOptionSelected(array $prop, array $oldSelect, string $key): bool + { + if (count($oldSelect) > 0) { + if ($prop['CODE'] === $oldSelect[$key]) { + return true; + } + } else { + $iblockPropertiesHint = $this->getHintProps(); + + foreach ($iblockPropertiesHint[$key] as $hint) { + if ($prop['CODE'] === $hint) { + return true; + } + } + } + + return false; + } + + /** + * @param array $prop + * @param bool $isProduct + * + * @return string + */ + public function getOptionClass(array $prop, bool $isProduct): string + { + $productMarker = $isProduct ? '-product' : ''; + + if ($prop['USER_TYPE'] === 'directory') { + return 'class="highloadblock' . $productMarker .'" id="' + . $prop['USER_TYPE_SETTINGS']['TABLE_NAME'] + . '"'; + } + + return 'class="not-highloadblock"'; + } + + /** + * @param array $unitSelect + * @param string|null $keyUnit + * @param string|null $key + * @param string|null $unitTypeName + * + * @return string + */ + public function getUnitOptionStatus(array $unitSelect, ?string $keyUnit, ?string $key, ?string $unitTypeName): string + { + if (count($unitSelect) > 0) { + if ($keyUnit === $unitSelect[$key]) { + return ' selected'; + } + } else { + $hintUnit = $this->getHintUnit(); + + if ($keyUnit === $hintUnit[$unitTypeName]) { + return ' selected'; + } + } + + return ''; + } + + /** + * @param int $iblockId + * + * @return array + */ + public function getSiteList(int $iblockId): array + { + $siteList = []; + + $rsSites = CIBlock::GetSite($iblockId); + + while ($arSite = $rsSites->Fetch()) { + $siteList[] = $arSite['SITE_ID']; + } + + return $siteList; + } + + /** + * @param int $iblockId + * + * @return array|null + */ + private function getSkuProps(int $iblockId): ?array + { + $propertiesSKU = null; + + $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblockId); + + if ($iblockOffer !== false) { + $dbSkuProperties = CIBlock::GetProperties($iblockOffer['IBLOCK_ID'], []); + + while ($prop = $dbSkuProperties->Fetch()) { + $propertiesSKU[] = $prop; + } + } + + return $propertiesSKU; + } + + /** + * Возвращает уже выбранные свойства + * + * @param array|null $oldValues + * @param int $iblockId + * @param string $keyGroup + * + * @return array + */ + private function getOldProps(?array $oldValues, int $iblockId, string $keyGroup = ''): array + { + $props = []; + + if (isset($oldValues[$iblockId])) { + foreach ($this->getIblockPropsNames() as $key => $prop) { + $fullKey = $keyGroup . '_' . $key; + $props[$key] = $oldValues[$iblockId][$fullKey]; + } + } + + return $props; + } + + /** + * @param array $arCatalog + * + * @return bool + */ + private function isCorrectCatalogType(array $arCatalog): bool + { + return $arCatalog['CATALOG_TYPE'] === 'D' + || $arCatalog['CATALOG_TYPE'] === 'X' + || $arCatalog['CATALOG_TYPE'] === 'P'; + } + + /** + * @param int $iblockId + * + * @return array + */ + public function getProductProps(int $iblockId): array + { + $propertiesProduct = null; + + $iblockResult = CIBlock::GetProperties($iblockId, []); + + while ($prop = $iblockResult->Fetch()) { + $propertiesProduct[] = $prop; + } + + return $propertiesProduct; + } + + /** + * @param $iblockId + * @param $iblockExport + * + * @return bool + */ + public function isExport($iblockId, $iblockExport): bool + { + if (count($iblockExport) !== 0) { + return (in_array($iblockId, $iblockExport)); + } + + return true; + } + + /** + * @param int $step + * @param string|null $fileName + * @param string|null $profileName + * + * @return int + */ + public function returnIfErrors(int $step, ?string $fileName, ?string $profileName): int + { + if ($step === 2) { + $arSetupErrors = $this->checkFileAndProfile( + $fileName ?? null, + $profileName ?? null + ); + + if (count($arSetupErrors) > 0) { + ShowError(implode('
', $arSetupErrors)); + + return 1; + } + } + + return $step; + } + + /** + * @return array + */ + public function getSettingsForIblocks(): array + { + $arIBlockList = []; + $intCountChecked = 0; + $intCountAvailIBlock = 0; + + $dbRes = CIBlock::GetList( + ['IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'], + ['CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'W'] + ); + + while ($iblock = $dbRes->Fetch()) { + $arCatalog = CCatalog::GetByIDExt($iblock['ID']); + + if (!$arCatalog || !$this->isCorrectCatalogType($arCatalog)) { + continue; + } + + if ( + $arCatalog['CATALOG_TYPE'] === self::CATALOG_WITH_SKU + || $arCatalog['CATALOG_TYPE'] === self::INFOBLOCK_WITH_SKU + ) { + $propertiesSKU = $this->getSkuProps($iblock['ID']); + $oldPropertySKU = $this->getOldProps( + $this->iblockPropertySku, + $iblock['ID'], + 'iblockPropertySku' + ); + $oldPropertyUnitSKU = $this->getOldProps( + $this->iblockPropertyUnitSku, + $iblock['ID'], + 'iblockPropertyUnitSku' + ); + } + + $arIBlockList[] = [ + 'ID' => $iblock['ID'], + 'NAME' => $iblock['NAME'], + 'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'], + 'iblockExport' => $this->isExport($iblock['ID'], $this->iblockExport), + 'PROPERTIES_SKU' => $propertiesSKU ?? null, + 'OLD_PROPERTY_SKU_SELECT' => $oldPropertySKU ?? [], + 'OLD_PROPERTY_UNIT_SKU_SELECT' => $oldPropertyUnitSKU ?? [], + 'PROPERTIES_PRODUCT' => $this->getProductProps($iblock['ID']), + 'OLD_PROPERTY_PRODUCT_SELECT' => $this->getOldProps( + $this->iblockPropertyProduct, + $iblock['ID'], + 'iblockPropertyProduct' + ), + 'OLD_PROPERTY_UNIT_PRODUCT_SELECT' => $this->getOldProps( + $this->iblockPropertyUnitProduct, + $iblock['ID'], + 'iblockPropertyUnitProduct' + ), + 'SITE_LIST' => '(' . implode(' ', $this->getSiteList($iblock['ID'])) . ')', + ]; + + if ($arIBlockList['iblockExport']) { + $intCountChecked++; + } + + $intCountAvailIBlock++; + + unset($propertiesSKU, $oldPropertySKU, $oldPropertyUnitSKU); + } + + return [$arIBlockList, $intCountChecked, $intCountAvailIBlock, $arIBlockList['iblockExport'] ?? false]; + } +} diff --git a/intaro.retailcrm/lib/icml/xmlofferdirector.php b/intaro.retailcrm/lib/icml/xmlofferdirector.php index bd41ca14..2e49c06e 100644 --- a/intaro.retailcrm/lib/icml/xmlofferdirector.php +++ b/intaro.retailcrm/lib/icml/xmlofferdirector.php @@ -106,7 +106,7 @@ class XmlOfferDirector { foreach ($xmlOffers as $offer) { $offer->productId = $product->id; - $offer->params = array_merge($offer->params, $product->params); + $offer->params = $this->mergeParams($offer->params, $product->params); $offer->unitCode = $offer->unitCode === null ? null : $offer->unitCode->merge($product->unitCode); $offer->vatRate = $offer->vatRate === 'none' ? $product->vatRate : $offer->vatRate; $offer->vendor = $offer->mergeValues($product->vendor, $offer->vendor); @@ -203,4 +203,29 @@ class XmlOfferDirector ->getProductPicture($product, $pictureProperty ?? '') ); } + + /** + * @param array $offerParams + * @param array $productParams + */ + private function mergeParams(array $offerParams, array $productParams): array + { + $offerCodes = []; + + /** @var \Intaro\RetailCrm\Model\Bitrix\Xml\OfferParam $offerParam */ + foreach ($offerParams as $offerParam) { + $offerCodes[] = $offerParam->code; + } + + /** @var \Intaro\RetailCrm\Model\Bitrix\Xml\OfferParam $productParam */ + foreach ($productParams as $productParam) { + if (in_array($productParam->code, $offerCodes, true)) { + continue; + } + + $offerParams[] = $productParam; + } + + return $offerParams; + } } diff --git a/intaro.retailcrm/lib/lang/en/icml/settingsservice.php b/intaro.retailcrm/lib/lang/en/icml/settingsservice.php new file mode 100644 index 00000000..64a41ca9 --- /dev/null +++ b/intaro.retailcrm/lib/lang/en/icml/settingsservice.php @@ -0,0 +1,48 @@ +getMessage()); + Logger::getInstance()->write($exception->getMessage(), 'repositoryErrors'); + return null; } } diff --git a/intaro.retailcrm/lib/service/hl.php b/intaro.retailcrm/lib/service/hl.php index 5c4eefac..9723820b 100644 --- a/intaro.retailcrm/lib/service/hl.php +++ b/intaro.retailcrm/lib/service/hl.php @@ -3,6 +3,7 @@ namespace Intaro\RetailCrm\Service; use Bitrix\Main\ArgumentException; +use Bitrix\Main\Entity\Base; use Bitrix\Main\Entity\DataManager; use Bitrix\Main\Loader; use Bitrix\Highloadblock as Highloadblock; @@ -22,55 +23,90 @@ class Hl /** * Получение DataManager класса управления HLBlock * - * @param int $HlBlockId + * @param int $hlBlockId + * * @return \Bitrix\Main\Entity\DataManager|null * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\LoaderException * @throws \Bitrix\Main\ObjectPropertyException * @throws \Bitrix\Main\SystemException */ - public static function getHlClassById(int $HlBlockId): ?DataManager + public static function getHlClassById(int $hlBlockId): ?DataManager + { + $entity = self::getBaseEntityByHlId($hlBlockId); + + return $entity->getDataClass(); + } + + + /** + * @param int $HlBlockId + * + * @return \Bitrix\Main\Entity\Base|null + * @throws \Bitrix\Main\ArgumentException + * @throws \Bitrix\Main\LoaderException + * @throws \Bitrix\Main\ObjectPropertyException + * @throws \Bitrix\Main\SystemException + */ + public static function getBaseEntityByHlId(int $HlBlockId): ?Base { Loader::includeModule('highloadblock'); - + $hlblock = Highloadblock\HighloadBlockTable::getById($HlBlockId)->fetch(); - + if (!$hlblock) { return null; } - - $entity = Highloadblock\HighloadBlockTable::compileEntity($hlblock); - - return $entity->getDataClass(); + + return Highloadblock\HighloadBlockTable::compileEntity($hlblock); } - + + /** + * @param string|null $tableName + * + * @return \Bitrix\Main\Entity\Base|null + */ + public static function getBaseEntityByTableName(?string $tableName): ?Base + { + if (!$tableName) { + return null; + } + + try { + Loader::includeModule('highloadblock'); + + $hlblock = Highloadblock\HighloadBlockTable::query() + ->addSelect('*') + ->where('TABLE_NAME', '=', $tableName) + ->exec() + ->fetch(); + + if (!$hlblock) { + return null; + } + + return Highloadblock\HighloadBlockTable::compileEntity($hlblock); + } catch (ObjectPropertyException | ArgumentException | SystemException | LoaderException $exception) { + AddMessage2Log($exception->getMessage()); + + return null; + } + } + /** * Получение DataManager класса управления HLBlock по названию таблицы * * @param string $name - * @return \Bitrix\Main\Entity\DataManager|string|null + * @return \Bitrix\Main\Entity\DataManager|null|string */ public static function getHlClassByTableName(string $name) { - try { - Loader::includeModule('highloadblock'); - - $hlblock = Highloadblock\HighloadBlockTable::query() - ->addSelect('*') - ->where('TABLE_NAME', '=', $name) - ->exec() - ->fetch(); - - if (!$hlblock) { - return null; - } - - $entity = Highloadblock\HighloadBlockTable::compileEntity($hlblock); - + $entity = self::getBaseEntityByTableName($name); + + if ($entity instanceof Base) { return $entity->getDataClass(); - } catch (ObjectPropertyException | ArgumentException | SystemException | LoaderException $exception) { - AddMessage2Log($exception->getMessage()); - return null; } + + return null; } } diff --git a/intaro.retailcrm/updater.php b/intaro.retailcrm/updater.php index b4609f67..45d0d2f7 100644 --- a/intaro.retailcrm/updater.php +++ b/intaro.retailcrm/updater.php @@ -1,29 +1,149 @@ addSelect('*') + ->where('FILE_NAME', 'retailcrm') + ->fetchObject(); + + replaceExportVars($exportSystem); } -$rcrmCurrentUpdateFile = __DIR__ . '/update/' . sprintf('updater-%s.php', $arModuleVersion['VERSION']); +/** + * @throws \Bitrix\Main\SystemException + * @throws \Bitrix\Main\ArgumentException + */ +function replaceExportVars(EntityObject $exportSystem) +{ + $replaceableVars = [ + ['search' => 'IBLOCK_EXPORT', 'replace' => 'iblockExport'], + ['search' => 'IBLOCK_PROPERTY_SKU', 'replace' => 'iblockPropertySku'], + ['search' => 'IBLOCK_PROPERTY_UNIT_SKU', 'replace' => 'iblockPropertyUnitSku'], + ['search' => 'IBLOCK_PROPERTY_PRODUCT', 'replace' => 'iblockPropertyProduct'], + ['search' => 'IBLOCK_PROPERTY_UNIT_PRODUCT', 'replace' => 'iblockPropertyUnitProduct'], + ['search' => 'MAX_OFFERS_VALUE', 'replace' => 'maxOffersValue'], + ]; + $setupVars = $exportSystem->get('SETUP_VARS'); + $newSetupVars = str_replace( + array_column($replaceableVars,'search'), + array_column($replaceableVars, 'replace'), + $setupVars + ); + + $exportSystem->set('SETUP_VARS', $newSetupVars); + $exportSystem->save(); +} -if (file_exists($rcrmCurrentUpdateFile)) { - include_once $rcrmCurrentUpdateFile; - $functionName = 'update_' . str_replace('.', '_', $arModuleVersion['VERSION']); - if (function_exists($functionName)) { - $functionName(); +class UpdaterRetailExportTable extends Main\Entity\DataManager +{ + /** + * Returns DB table name for entity. + * + * @return string + */ + public static function getTableName(): string + { + return 'b_catalog_export'; + } + + /** + * Returns entity map definition. + * + * @return array + */ + public static function getMap(): array + { + return [ + 'ID' => [ + 'data_type' => 'integer', + 'primary' => true, + 'autocomplete' => true, + 'title' => Loc::getMessage('EXPORT_ENTITY_ID_FIELD'), + ], + 'FILE_NAME' => [ + 'data_type' => 'string', + 'required' => true, + 'validation' => [__CLASS__, 'validateFileName'], + 'title' => Loc::getMessage('EXPORT_ENTITY_FILE_NAME_FIELD'), + ], + 'NAME' => [ + 'data_type' => 'string', + 'required' => true, + 'validation' => [__CLASS__, 'validateName'], + 'title' => Loc::getMessage('EXPORT_ENTITY_NAME_FIELD'), + ], + 'DEFAULT_PROFILE' => [ + 'data_type' => 'boolean', + 'values' => ['N', 'Y'], + 'title' => Loc::getMessage('EXPORT_ENTITY_DEFAULT_PROFILE_FIELD'), + ], + 'IN_MENU' => [ + 'data_type' => 'boolean', + 'values' => ['N', 'Y'], + 'title' => Loc::getMessage('EXPORT_ENTITY_IN_MENU_FIELD'), + ], + 'IN_AGENT' => [ + 'data_type' => 'boolean', + 'values' => ['N', 'Y'], + 'title' => Loc::getMessage('EXPORT_ENTITY_IN_AGENT_FIELD'), + ], + 'IN_CRON' => [ + 'data_type' => 'boolean', + 'values' => ['N', 'Y'], + 'title' => Loc::getMessage('EXPORT_ENTITY_IN_CRON_FIELD'), + ], + 'SETUP_VARS' => [ + 'data_type' => 'text', + 'title' => Loc::getMessage('EXPORT_ENTITY_SETUP_VARS_FIELD'), + ], + 'LAST_USE' => [ + 'data_type' => 'datetime', + 'title' => Loc::getMessage('EXPORT_ENTITY_LAST_USE_FIELD'), + ], + 'IS_EXPORT' => [ + 'data_type' => 'boolean', + 'values' => ['N', 'Y'], + 'title' => Loc::getMessage('EXPORT_ENTITY_IS_EXPORT_FIELD'), + ], + 'NEED_EDIT' => [ + 'data_type' => 'boolean', + 'values' => ['N', 'Y'], + 'title' => Loc::getMessage('EXPORT_ENTITY_NEED_EDIT_FIELD'), + ], + 'TIMESTAMP_X' => [ + 'data_type' => 'datetime', + 'title' => Loc::getMessage('EXPORT_ENTITY_TIMESTAMP_X_FIELD'), + ], + 'MODIFIED_BY' => [ + 'data_type' => 'integer', + 'title' => Loc::getMessage('EXPORT_ENTITY_MODIFIED_BY_FIELD'), + ], + 'DATE_CREATE' => [ + 'data_type' => 'datetime', + 'title' => Loc::getMessage('EXPORT_ENTITY_DATE_CREATE_FIELD'), + ], + 'CREATED_BY' => [ + 'data_type' => 'integer', + 'title' => Loc::getMessage('EXPORT_ENTITY_CREATED_BY_FIELD'), + ], + ]; } }