2013-09-12 17:31:32 +04:00
|
|
|
<?php
|
2021-05-31 16:33:02 +03:00
|
|
|
|
|
|
|
use Bitrix\Highloadblock\HighloadBlockTable;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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');
|
2016-10-04 17:57:39 +03:00
|
|
|
} else {
|
2015-05-18 17:38:06 +03:00
|
|
|
ignore_user_abort(true);
|
|
|
|
set_time_limit(0);
|
2013-09-12 17:31:32 +04:00
|
|
|
|
2015-05-18 17:38:06 +03:00
|
|
|
global $APPLICATION;
|
2018-10-04 16:28:14 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if (
|
|
|
|
!CModule::IncludeModule('iblock')
|
|
|
|
|| !CModule::IncludeModule('catalog')
|
|
|
|
|| !CModule::IncludeModule('intaro.retailcrm')
|
|
|
|
) {
|
|
|
|
return;
|
2015-03-03 16:37:34 +03:00
|
|
|
}
|
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
$hlblockModule = false;
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if (CModule::IncludeModule('highloadblock')) {
|
|
|
|
$hlblockModule = true;
|
2021-05-31 16:33:02 +03:00
|
|
|
$hlblockList = [];
|
|
|
|
$hlblockListDb = HighloadBlockTable::getList();
|
2018-05-23 12:19:59 +03:00
|
|
|
|
|
|
|
while ($hlblockArr = $hlblockListDb->Fetch()) {
|
|
|
|
$hlblockList[$hlblockArr["TABLE_NAME"]] = $hlblockArr;
|
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
}
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockProperties = [
|
|
|
|
'article' => 'article',
|
|
|
|
'manufacturer' => 'manufacturer',
|
|
|
|
'color' => 'color',
|
|
|
|
'weight' => 'weight',
|
|
|
|
'size' => 'size',
|
|
|
|
'length' => 'length',
|
|
|
|
'width' => 'width',
|
|
|
|
'height' => 'height',
|
|
|
|
];
|
|
|
|
|
|
|
|
$iblockPropertySku = [];
|
|
|
|
$iblockPropertySkuHl = [];
|
|
|
|
$iblockPropertyUnitSku = [];
|
|
|
|
$iblockPropertyProduct = [];
|
|
|
|
$iblockPropertyProductHl = [];
|
|
|
|
$iblockPropertyUnitProduct = [];
|
|
|
|
|
2015-05-18 17:38:06 +03:00
|
|
|
foreach ($iblockProperties as $prop) {
|
|
|
|
$skuUnitProps = ('IBLOCK_PROPERTY_UNIT_SKU' . "_" . $prop);
|
|
|
|
$skuUnitProps = $$skuUnitProps;
|
2021-05-31 16:33:02 +03:00
|
|
|
|
2015-05-18 17:38:06 +03:00
|
|
|
if (is_array($skuUnitProps)) {
|
|
|
|
foreach ($skuUnitProps as $iblock => $val) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockPropertyUnitSku[$iblock][$prop] = $val;
|
2015-05-18 17:38:06 +03:00
|
|
|
}
|
2014-01-30 15:54:49 +04:00
|
|
|
}
|
2014-04-15 20:31:11 +04:00
|
|
|
|
2015-05-18 17:38:06 +03:00
|
|
|
$skuProps = ('IBLOCK_PROPERTY_SKU' . "_" . $prop);
|
|
|
|
$skuProps = $$skuProps;
|
|
|
|
if (is_array($skuProps)) {
|
|
|
|
foreach ($skuProps as $iblock => $val) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockPropertySku[$iblock][$prop] = $val;
|
2015-05-18 17:38:06 +03:00
|
|
|
}
|
2014-01-30 15:54:49 +04:00
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if ($hlblockModule === true) {
|
|
|
|
foreach ($hlblockList as $hlblockTable => $hlblock) {
|
|
|
|
$hbProps = ('highloadblock' . $hlblockTable . '_' . $prop);
|
|
|
|
$hbProps = $$hbProps;
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if (is_array($hbProps)) {
|
|
|
|
foreach ($hbProps as $iblock => $val) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockPropertySkuHl[$hlblockTable][$iblock][$prop] = $val;
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 12:19:59 +03:00
|
|
|
|
2015-05-18 17:38:06 +03:00
|
|
|
$productUnitProps = "IBLOCK_PROPERTY_UNIT_PRODUCT" . "_" . $prop;
|
|
|
|
$productUnitProps = $$productUnitProps;
|
|
|
|
if (is_array($productUnitProps)) {
|
|
|
|
foreach ($productUnitProps as $iblock => $val) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockPropertyUnitProduct[$iblock][$prop] = $val;
|
2015-05-18 17:38:06 +03:00
|
|
|
}
|
2014-01-30 15:54:49 +04:00
|
|
|
}
|
2014-04-15 20:31:11 +04:00
|
|
|
|
2015-05-18 17:38:06 +03:00
|
|
|
$productProps = "IBLOCK_PROPERTY_PRODUCT" . "_" . $prop;
|
|
|
|
$productProps = $$productProps;
|
|
|
|
if (is_array($productProps)) {
|
|
|
|
foreach ($productProps as $iblock => $val) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockPropertyProduct[$iblock][$prop] = $val;
|
2015-05-18 17:38:06 +03:00
|
|
|
}
|
2014-01-30 15:54:49 +04:00
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if ($hlblockModule === true) {
|
|
|
|
foreach ($hlblockList as $hlblockTable => $hlblock) {
|
|
|
|
$hbProps = ('highloadblock_product' . $hlblockTable . '_' . $prop);
|
|
|
|
$hbProps = $$hbProps;
|
2018-03-22 16:11:04 +03:00
|
|
|
|
2018-05-23 12:19:59 +03:00
|
|
|
if (is_array($hbProps)) {
|
|
|
|
foreach ($hbProps as $iblock => $val) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$iblockPropertyProductHl[$hlblockTable][$iblock][$prop] = $val;
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|
2018-03-22 16:11:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 17:42:20 +04:00
|
|
|
}
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$productPictures = [];
|
2018-10-04 16:28:14 +03:00
|
|
|
|
|
|
|
if (is_array($IBLOCK_PROPERTY_PRODUCT_picture)) {
|
|
|
|
foreach ($IBLOCK_PROPERTY_PRODUCT_picture as $key => $value) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$productPictures[$key] = $value;
|
2018-10-04 16:28:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$skuPictures = [];
|
2018-10-04 16:28:14 +03:00
|
|
|
|
|
|
|
if (is_array($IBLOCK_PROPERTY_SKU_picture)) {
|
|
|
|
foreach ($IBLOCK_PROPERTY_SKU_picture as $key => $value) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$skuPictures[$key] = $value;
|
2018-10-04 16:28:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$xmlProps = new XmlSetupPropsCategories(
|
|
|
|
new XmlSetupProps($iblockPropertyProduct, $iblockPropertyUnitProduct, $productPictures),
|
|
|
|
new XmlSetupProps($iblockPropertySku, $iblockPropertyUnitSku, $skuPictures)
|
|
|
|
);
|
2018-05-23 12:19:59 +03:00
|
|
|
|
|
|
|
if ($hlblockModule === true) {
|
2021-05-31 16:33:02 +03:00
|
|
|
$xmlProps->highloadblockSku = $iblockPropertySkuHl;
|
|
|
|
$xmlProps->highloadblockProduct = $iblockPropertyProductHl;
|
2018-05-23 12:19:59 +03:00
|
|
|
}
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$fileSetup = new XmlSetup($xmlProps);
|
|
|
|
$fileSetup->profileId = $profile_id;
|
|
|
|
$fileSetup->iblocksForExport = $IBLOCK_EXPORT;
|
|
|
|
$fileSetup->maxOffersValue = $MAX_OFFERS_VALUE ?? null;
|
|
|
|
$fileSetup->filePath = $SETUP_FILE_NAME;
|
|
|
|
$fileSetup->loadPurchasePrice = $LOAD_PURCHASE_PRICE === 'Y';
|
|
|
|
$fileSetup->basePriceId = CatalogRepository::getBasePriceId($fileSetup->profileId);
|
|
|
|
$logger = Logger::getInstance('/bitrix/catalog_export/');
|
|
|
|
|
|
|
|
if (!is_array($fileSetup->iblocksForExport) || count($fileSetup->iblocksForExport) === 0) {
|
|
|
|
$logger->write(GetMessage("IBLOCK_NOT_SELECTED"), 'i_crm_load_log');
|
|
|
|
} else {
|
|
|
|
$loader = new IcmlDirector($fileSetup, $logger);
|
|
|
|
$loader->generateXml();
|
2018-12-26 11:41:06 +03:00
|
|
|
}
|
2021-05-31 16:33:02 +03:00
|
|
|
}
|