- $checkBoxCounter = 0;?>
- foreach ($arIBlockList as $key => $arIBlock):?>
-
+
- echo htmlspecialcharsex("[".$arIBlock["IBLOCK_TYPE_ID"]."] ".$arIBlock["NAME"]." ".$arIBlock['SITE_LIST']); ?>
- ]"
- id="IBLOCK_EXPORT=++$checkBoxCounter?>"
- value="=$arIBlock["ID"]?>"
- if ($arIBlock['IBLOCK_EXPORT']) echo " checked"; ?>
- onclick="checkOne(this, echo $intCountAvailIBlock; ?>);"
- >
-
-
-
">
-
>
-
+
+
+ = htmlspecialcharsex('['
+ . $arIBlock['IBLOCK_TYPE_ID']
+ . '] '
+ . $arIBlock['NAME']
+ . ' '
+ . $arIBlock['SITE_LIST']) ?>
+
+
+ onclick="checkOne(this,=$intCountAvailIBlock?>);"
+ >
+
+
+
+
+ >
+
-
-
+
+
- foreach ($iblockPropertiesName as $key => $property): ?>
- $productSelected = false;?>
+ getIblockPropsNames() as $propertyKey => $property) {
+ $productSelected = false; ?>
- echo htmlspecialcharsex($property); ?>
+ =htmlspecialcharsex($property)?>
|
-
- |
+ =$prop['NAME']?>
+
+
+ if ($settingsService->isOptionHasPreset($propertyKey)) {
+ ?>
+
+
+
+ isHlSelected(
+ $propertyKey,
+ $arIBlock['ID'],
+ $productHlTableName,
+ '_product'
+ )
+ ) {?>
+
+
+
+
+
+
+
+ $unitType) { ?>
+
+ $unit): ?>
+
+
+
+
+
+
+
+
"
- name="IBLOCK_PROPERTY_SKU_=$key?>[=$arIBlock["ID"]?>]"
+ id="iblockPropertySku_=$propertyKey?>=$arIBlock['ID']?>"
+ name="iblockPropertySku_=$propertyKey?>[=$arIBlock['ID']?>]"
class="property-export"
- data-type="=$key?>"
+ data-type="=$propertyKey?>"
onchange="propertyChange(this);">
-
- =') && array_key_exists($key, $iblockFieldsName)) :?>
- ">
- foreach ($iblockFieldsName as $keyField => $field): ?>
+
+ isOptionHasPreset($propertyKey)) {
+ ?>
+
+ $field) {
+ if ($keyField === $propertyKey) :?>
+
+
+
+
+
-
- endif; ?>
-
- endforeach;?>
-
- ">
- endif; ?>
-
- foreach ($arIBlock['PROPERTIES_SKU'] as $prop): ?>
-
- endforeach;?>
- if (version_compare(SM_VERSION, '14.0.0', '>=') && array_key_exists($key, $iblockFieldsName)) : ?>
-
- endif; ?>
+ isOptionHasPreset($propertyKey)) {
+ ?>
+
+
- if (isset($selected)
- && isset($arOldSetupVars['highloadblock' . $selected . '_' . $key][$arIBlock['ID']])
- ) : ?>
-
- foreach ($hlblockList[$selected]['FIELDS'] as $field) : ?>
-
- endforeach; ?>
+ isHlSelected(
+ $propertyKey,
+ $arIBlock['ID'],
+ $skuHlTableName
+ )
+ ) { ?>
+
+
+
+
- endif; ?>
-
+
"
- name="IBLOCK_PROPERTY_UNIT_SKU_=$key?>[=$arIBlock["ID"]?>]"
- >
- foreach ($units as $unitTypeName => $unitType): ?>
- if ($unitTypeName == $iblockFieldsName[$key]['unit']): ?>
- foreach ($unitType as $keyUnit => $unit): ?>
-
- endforeach;?>
-
- endforeach;?>
+
-
+
|
-
- endif;?>
+
+
+
+
+
+
+
+
+
+
+
+
+ =GetMessage('SETTINGS_EXPORT')?>
+ =GetMessage('FILENAME')?>
+
+ =GetMessage('LOAD_PURCHASE_PRICE')?>
+ >
+
+
+ =GetMessage('LOAD_PERIOD');?>
+ =GetMessage('NOT_LOADING')?>
+ =GetMessage('CRON_LOADING')?>
+ =GetMessage('AGENT_LOADING')?>
+
+
+ =GetMessage('LOAD_NOW')?>
+
+
+ =GetMessage('LOAD_NOW_MSG')?>
+
+
- endforeach;?>
-
-
-
-
+
=GetMessage('BASE_PRICE')?>
+
+
+
+
+
+
+
+
=GetMessage('OFFERS_VALUE')?>
+
+
+
=GetMessage('PROFILE_NAME')?>
+
+
+ =bitrix_sessid_post()?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- endforeach;?>
-
-
-
-
-
-
=GetMessage("SETTINGS_EXPORT");?>
-
-
=GetMessage("FILENAME");?>
-
-
-
-
-
=GetMessage("LOAD_PURCHASE_PRICE");?>
-
>
-
-
-
-
-
-
=GetMessage("BASE_PRICE");?>
-
-
-
-
-
-
-
-
-
-
-
-
-
=GetMessage("OFFERS_VALUE");?>
-
-
-
-
-
-
-
-
=GetMessage("PROFILE_NAME");?>
-
-
-
-
-
-
-
-
-
- //Следующие переменные должны быть обязательно установлены?>
- =bitrix_sessid_post();?>
-
-
- $vals = "LOAD_PURCHASE_PRICE,SETUP_FILE_NAME,IBLOCK_EXPORT,MAX_OFFERS_VALUE";
- foreach ($iblockProperties as $val) {
- $vals .= ",IBLOCK_PROPERTY_SKU_" . $val;
- $vals .= ",IBLOCK_PROPERTY_UNIT_SKU_" . $val;
- $vals .= ",IBLOCK_PROPERTY_PRODUCT_" . $val;
- $vals .= ",IBLOCK_PROPERTY_UNIT_PRODUCT_" . $val;
-
- if ($hlblockModule === true && $val != 'picture') {
- foreach ($hlblockList as $hlblockTable => $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 @@
-=GetMessage('EXPORT_CATALOGS_INFO')?>
-if(!check_bitrix_sessid()) return;
-IncludeModuleLangFile(__FILE__);
-__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.retailcrm/lang/", "/icml_export_setup.php"));
-?>
-
=GetMessage("EXPORT_CATALOGS_INFO");?>
-
-
-
-
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'),
+ ],
+ ];
}
}