1
0
mirror of synced 2024-11-22 21:36:10 +03:00
bitrix-module/intaro.retailcrm/export/export_run.php

161 lines
5.2 KiB
PHP
Raw Normal View History

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;
2021-09-08 10:05:09 +03:00
/** @var $SETUP_FILE_NAME */
2021-05-31 16:33:02 +03:00
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) {
2021-09-08 10:05:09 +03:00
$skuUnitProps = ('iblockPropertyUnitSku_' . $prop);
2015-05-18 17:38:06 +03:00
$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-04-15 20:31:11 +04:00
2021-09-08 10:05:09 +03:00
$skuProps = ('iblockPropertySku_' . $prop);
2015-05-18 17:38:06 +03:00
$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
}
}
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
2021-09-08 10:05:09 +03:00
$productUnitProps = 'iblockPropertyUnitProduct_' . $prop;
2015-05-18 17:38:06 +03:00
$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-04-15 20:31:11 +04:00
2021-09-08 10:05:09 +03:00
$productProps = "iblockPropertyProduct_" . $prop;
2015-05-18 17:38:06 +03:00
$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
}
}
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
2021-09-08 10:05:09 +03:00
if (is_array($iblockPropertyProduct_picture)) {
foreach ($iblockPropertyProduct_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
2021-09-08 10:05:09 +03:00
if (is_array($iblockPropertySku_picture)) {
foreach ($iblockPropertySku_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;
2021-09-08 10:05:09 +03:00
$fileSetup->iblocksForExport = $iblockExport;
$fileSetup->maxOffersValue = $maxOffersValue ?? null;
2021-05-31 16:33:02 +03:00
$fileSetup->filePath = $SETUP_FILE_NAME;
2021-09-08 10:05:09 +03:00
$fileSetup->loadPurchasePrice = $loadPurchasePrice === 'Y';
2021-05-31 16:33:02 +03:00
$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
}