diff --git a/CHANGELOG.md b/CHANGELOG.md
index 022e3c31..e1155b25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+## 2021-05-31 v.5.7.0
+* Переработан генератор ICML каталога:
+ - генератор использует потоковую запись в файл через `XMLWriter`;
+ - по умолчанию опция выгрузки каталога в момент установки модуля отключена;
+ - код генератора каталога теперь использует автолоадер Битрикса.
+* Скидка на позицию больше не учитывается в заказе при установке произвольной цены для позиции.
+
## 2021-01-14 v.5.6.2
* Исправлено формирование картинок в ICML при включеном CDN
* Убрана некорректная запись внешнего идентификатора платежа для новых платежей по истории
diff --git a/composer.json b/composer.json
index 46354990..52b2760c 100755
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,8 @@
],
"require": {
"ext-json": "*",
- "ext-mbstring": "*"
+ "ext-mbstring": "*",
+ "ext-xmlwriter": "*"
},
"require-dev": {
"phpunit/phpunit": "^7",
diff --git a/composer.lock b/composer.lock
index 30588530..66b54f40 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "032aa518034a20c6776e550379084efc",
+ "content-hash": "72c54dce7daa3cd6c40577578128091a",
"packages": [],
"packages-dev": [
{
@@ -1761,7 +1761,9 @@
"prefer-lowest": false,
"platform": {
"ext-json": "*",
- "ext-mbstring": "*"
+ "ext-mbstring": "*",
+ "ext-xmlwriter": "*"
},
- "platform-dev": []
+ "platform-dev": [],
+ "plugin-api-version": "2.0.0"
}
diff --git a/intaro.retailcrm/classes/general/AddressBuilder.php b/intaro.retailcrm/classes/general/AddressBuilder.php
index 8db7ddf0..9416bf2e 100644
--- a/intaro.retailcrm/classes/general/AddressBuilder.php
+++ b/intaro.retailcrm/classes/general/AddressBuilder.php
@@ -1,4 +1,5 @@
1, // 1 mm = 1 mm
- 'cm' => 10, // 1 cm = 10 mm
- 'm' => 1000,
- 'mg' => 0.001, // 0.001 g = 1 mg
- 'g' => 1,
- 'kg' => 1000,
- );
-
- protected $measurementLink = array (
- 'mm' => 'mm',
- 'cm' => 'mm',
- 'm' => 'mm',
- 'mg' => 'g',
- 'g' => 'g',
- 'kg' => 'g',
- );
-
- protected $measure = array (
- 'pc. 1' => 'pc',
- 'm' => 'm',
- 'l' => 'l',
- 'kg' => 'kg',
- );
-
- public function Load()
- {
- global $USER;
- if (!isset($_SESSION["SESS_AUTH"]["USER_ID"]) || !$_SESSION["SESS_AUTH"]["USER_ID"]) {
- $USER = new CUser();
- }
-
- $this->isLogged = true;
- $this->localizedIBlockProps = $this->getLocalizedIBlockProps();
-
- $defaultSite = CSite::GetList($by = "def", $order = "desc", array('DEF' => 'Y'))->Fetch();
- $this->encodingDefault = $defaultSite["CHARSET"];
-
- $this->protocol = COption::GetOptionString($this->MODULE_ID, $this->PROTOCOL_OPTION);
- $this->purchasePriceNull = COption::GetOptionString($this->MODULE_ID, $this->CRM_PURCHASE_PRICE_NULL);
-
- $this->PrepareSettings();
-
- $this->fp = $this->PrepareFile($this->filename. '.tmp');
-
- if ($this->isLogged) {
- $this->fpLog = $this->PrepareFile($this->logFile);
- $this->WriteLog("Start Loading");
- }
-
- $this->PreWriteCatalog();
-
- $categories = $this->GetCategories();
-
- $this->WriteCategories($categories);
-
- $this->PreWriteOffers();
- $this->BuildOffers($categories);
- $this->PostWriteOffers();
-
- $this->PostWriteCatalog();
-
- if ($this->isLogged) {
- $this->WriteLog("Loading was ended successfully (peek memory usage: " . memory_get_peak_usage() . ")");
- }
-
- $this->CloseFile($this->fp);
- $this->CloseFile($this->fpLog);
- unlink($defaultSite['ABS_DOC_ROOT'] . $this->filename);
- rename($defaultSite['ABS_DOC_ROOT'] . $this->filename. '.tmp', $defaultSite['ABS_DOC_ROOT'] . $this->filename);
-
- return true;
-
- }
-
- private function setSiteAddress($block_id)
- {
- $site = CAllIBlock::GetSite($block_id)->Fetch();
-
- if ($site['SERVER_NAME']) {
- $this->serverName = $site['SERVER_NAME'];
- } else {
- $this->serverName = $this->defaultServerName;
- }
- }
-
- protected function PrepareSettings()
- {
- foreach ($this->propertiesSKU as $iblock => $arr) {
- foreach ($arr as $id => $sku) {
- $this->propertiesSKU[$iblock][$id] = strtoupper($sku);
- }
- }
-
- foreach ($this->propertiesProduct as $iblock => $arr) {
- foreach ($arr as $id => $prod) {
- $this->propertiesProduct[$iblock][$id] = strtoupper($prod);
- }
- }
- }
-
- protected function PrepareValue($text)
- {
- $newText = $this->application->ConvertCharset($text, $this->encodingDefault, $this->encoding);
- $newText = strip_tags($newText);
- $newText = str_replace("&", "&", $newText);
-
- return $newText;
- }
-
- protected function PrepareFile($filename)
- {
- $fullFilename = $_SERVER["DOCUMENT_ROOT"] . $filename;
- CheckDirPath($fullFilename);
-
- if ($fp = @fopen($fullFilename, "w")){
- return $fp;
- } else {
- return false;
- }
- }
-
- protected function PreWriteCatalog()
- {
- @fwrite($this->fp, "PrepareValue(Date("Y-m-d H:i:s")) . "\">\n
- \n
- " . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n
- " . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."\n"
- );
- }
-
- protected function WriteCategories($categories)
- {
- $stringCategories = "";
- @fwrite($this->fp, "\n");
- foreach ($categories as $category) {
- $stringCategories .= $this->BuildCategory($category);
- }
- @fwrite($this->fp, $stringCategories);
- @fwrite($this->fp, "\n");
- }
- protected function PreWriteOffers()
- {
- @fwrite($this->fp, "\n");
- }
-
- protected function PostWriteOffers()
- {
- @fwrite($this->fp, "\n");
- }
-
- protected function WriteOffers($offers)
- {
- @fwrite($this->fp, $offers);
- }
-
- protected function WriteLog($text)
- {
- if ($this->isLogged) {
- @fwrite($this->fpLog, Date("Y:m:d H:i:s") . ": " . $text . "\n");
- }
- }
-
- protected function PostWriteCatalog()
- {
- @fwrite($this->fp, "\n
- \n");
- }
-
- protected function CloseFile($fp)
- {
- @fclose($fp);
- }
-
- protected function GetCategories()
- {
- $categories = array();
- foreach ($this->iblocks as $id) {
- $this->setSiteAddress($id);
- $filter = array("IBLOCK_ID" => $id);
-
- $dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
- $hasCategories = false;
-
- while ($arRes = $dbRes->Fetch()) {
- $categories[$arRes['ID']] = $arRes;
- $categories[$arRes['ID']]['SITE'] = $this->protocol . $this->serverName;
- $hasCategories = true;
- }
-
- if (!$hasCategories) {
- $iblock = CIBlock::GetByID($id)->Fetch();
-
- $arRes = array();
- $arRes['ID'] = $this->mainSection + $id;
- $arRes['IBLOCK_SECTION_ID'] = 0;
- $arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
- $categories[$arRes['ID']] = $arRes;
- $categories[$arRes['ID']]['SITE'] = $this->protocol . $this->serverName;
- }
- }
-
- return $categories;
- }
-
- protected function BuildCategory($arCategory)
- {
- $category =
- "PrepareValue($arCategory["ID"]) . "\""
- . (intval($arCategory["IBLOCK_SECTION_ID"]) > 0 ?
- " parentId=\"" . $this->PrepareValue($arCategory["IBLOCK_SECTION_ID"]) . "\""
- :"")
- . ">\n\t"
- . "" . $this->PrepareValue($arCategory["NAME"]) . "\n";
-
- if (CFile::GetPath($arCategory["DETAIL_PICTURE"])) {
- $category .= "\t\n";
- }
-
- if (CFile::GetPath($arCategory["PICTURE"])) {
- $category .= "\t\n";
- }
-
- $category .= "\n";
-
- return $category;
- }
-
- protected function BuildOffers(&$allCategories)
- {
- $basePriceId = $this->getBasePriceId();
-
- foreach ($this->iblocks as $key => $id) {
- $this->setSiteAddress($id);
- $barcodes = $this->getProductBarcodesByIblock($id);
-
- // Get Info by infoblocks
- $iblockData = CIBlock::GetByID($id)->Fetch();
- $iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
-
- $highloadblockSkuProps = $this->getAvailableHighloadOfferSkuProps($iblockOffer['IBLOCK_ID']);
- $highloadblockProductProps = $this->getAvailableHighloadProductProps($id);
-
- $arSelect = $this->buildProductQuery($id);
- $arSelectOffer = $this->buildOfferQuery($id, $iblockOffer['SKU_PROPERTY_ID']);
-
- // Set filter
- $order = array("id");
- $filter = array(
- "IBLOCK_ID" => $id,
- "ACTIVE" => 'Y',
- );
- $arNavStatParams = array(
- "iNumPage" => 1,
- "nPageSize" => $this->pageSize,
- );
-
- // Cycle page to page
- do {
- // Get products on this page
- $elems = array();
- $dbResProductsIds = CIBlockElement::GetList($order, $filter, false, $arNavStatParams, array('ID'));
-
- while ($obIds = $dbResProductsIds->Fetch()) {
- $elems[] = $obIds['ID'];
- }
-
- foreach ($elems as $elemId) {
- $arFilter = array(
- "IBLOCK_ID" => $id,
- "ID" => array($elemId)
- );
-
- $this->ProcessProductOffers(
- $arSelect,
- $arSelectOffer,
- $allCategories,
- $basePriceId,
- $id,
- $iblockData,
- $iblockOffer,
- $barcodes,
- $highloadblockProductProps,
- $highloadblockSkuProps,
- $order,
- $arFilter
- );
- }
-
- if ($this->isLogged) {
- $this->WriteLog(
- count($elems)
- . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")"
- );
- }
-
- $arNavStatParams['iNumPage'] = $dbResProductsIds->NavPageNomer + 1;
- } while ($dbResProductsIds->NavPageNomer < $dbResProductsIds->NavPageCount);
- }
- }
-
- /**
- * Process offers for a single product
- *
- * @param array $arSelect Properties to select for order
- * @param array $arSelectOffer Properties to select for offer
- * @param array $allCategories Categories to pick data from
- * @param string $basePriceId Base price ID
- * @param string $iblockId iblock id
- * @param array $iblock iblock data
- * @param array $iblockOffer offer iblock
- * @param array $barcodes Catalog barcodes
- * @param array $highloadblockProductProps Product props
- * @param array $highloadblockSkuProps SKU props
- * @param array $order Order data
- * @param array $arFilter filter
- */
- protected function ProcessProductOffers(
- $arSelect,
- $arSelectOffer,
- $allCategories,
- $basePriceId,
- $iblockId,
- $iblock,
- $iblockOffer,
- $barcodes,
- $highloadblockProductProps,
- $highloadblockSkuProps,
- $order,
- $arFilter
- ) {
- $dbResProducts = CIBlockElement::GetList($order, $arFilter, false, false, $arSelect);
-
- $products = [];
-
- while ($product = $dbResProducts->GetNext()) {
- // Compile products to array
- $products[$product['ID']] = $product;
- $products[$product['ID']]['offers'] = [];
- }
-
- unset($product);
-
- if (!empty($iblockOffer['IBLOCK_ID']) && !empty($products)) {
- $arFilterOffer = array(
- 'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
- 'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => array_keys($products),
- );
-
- // Get all offers for products on this page
- $dbResOffers = CIBlockElement::GetList(
- array(),
- $arFilterOffer,
- false,
- array('nTopCount' => $this->pageSize * $this->offerPageSize),
- $arSelectOffer
- );
-
- while ($offer = $dbResOffers->GetNext()) {
- // Link offers to products
- $products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
- }
-
- unset($offer, $dbResOffers);
- }
-
- foreach ($products as $product) {
- $product['PICTURE'] = $this->getProductPicture($iblockId, $product);
- $resPropertiesProduct = $this->getProductProperties($iblockId, $highloadblockProductProps, $product);
- $categories = $this->getProductCategories($allCategories, $iblockId, $product['ID']);
-
- $existOffer = false;
- if (!empty($iblockOffer['IBLOCK_ID'])) {
- foreach ($product['offers'] as $offer) {
- $offer['BARCODE'] = isset($barcodes[$offer['ID']]) ? $barcodes[$offer['ID']] : '';
- $offer['PRODUCT_ID'] = $product["ID"];
- $offer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"];
-
- if (CFile::GetPath($offer["DETAIL_PICTURE"])) {
- $offer['PICTURE'] = $this->getImageUrl($offer["DETAIL_PICTURE"]);
- } elseif (CFile::GetPath($offer["PREVIEW_PICTURE"])) {
- $offer['PICTURE'] = $this->getImageUrl($offer["PREVIEW_PICTURE"]);
- } elseif (
- $this->skuPictures
- && isset($this->skuPictures[$iblockId])
- && CFile::GetPath($offer["PROPERTY_" . $this->skuPictures[$iblockId]['picture'] . "_VALUE"])
- ) {
- $offer['PICTURE'] = $this->getImageUrl($offer["PROPERTY_" . $this->skuPictures[$iblockId]['picture'] . "_VALUE"]);
- } else {
- $offer['PICTURE'] = $product['PICTURE'];
- }
-
- $offer['PRODUCT_NAME'] = $product["NAME"];
- $offer['PRODUCT_ACTIVE'] = $product["ACTIVE"];
- $offer['PRICE'] = $offer['CATALOG_PRICE_' . $basePriceId];
- $offer['PURCHASE_PRICE'] = $offer['CATALOG_PURCHASING_PRICE'];
- $offer['QUANTITY'] = $offer["CATALOG_QUANTITY"];
-
- // Get properties of product
- foreach ($this->propertiesSKU[$iblockId] as $key => $propSKU) {
- if ($propSKU != "") {
- if (isset ($offer["PROPERTY_" . $propSKU . "_NAME"])) {
- $offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_NAME"];
- } elseif (isset($offer["PROPERTY_" . $propSKU . "_VALUE"])) {
- $offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_VALUE"];
- } elseif (isset($offer[$propSKU])) {
- $offer['_PROP_' . $key] = $offer[$propSKU];
- }
- if (array_key_exists($key, $this->propertiesUnitSKU[$iblockId])) {
- $offer['_PROP_' . $key] *= $this->measurement[$this->propertiesUnitSKU[$iblockId][$key]];
- $offer['_PROP_' . $key . "_UNIT"] = $this->measurementLink[$this->propertiesUnitSKU[$iblockId][$key]];
- }
- if (isset($highloadblockSkuProps[$propSKU])) {
- $propVal = $this->getHBprop($highloadblockSkuProps[$propSKU], $offer["PROPERTY_" . $propSKU . "_VALUE"]);
- $tableName = $highloadblockSkuProps[$propSKU]['USER_TYPE_SETTINGS']['TABLE_NAME'];
- $field = $this->highloadblockSkuProperties[$tableName][$iblockId][$key];
- $offer['_PROP_' . $key] = $propVal[$field];
- }
- }
- }
-
- foreach ($resPropertiesProduct as $key => $propProduct) {
- if ($this->propertiesProduct[$iblockId][$key] != "" && !isset($offer[$key])) {
- $offer['_PROP_' . $key] = $propProduct;
- }
- }
-
- $this->PutOffer($offer, $categories, $iblock, $allCategories);
- $existOffer = true;
- }
- }
-
- if (!$existOffer) {
- $offer['BARCODE'] = isset($barcodes[$product["ID"]]) ? $barcodes[$product["ID"]] : '';
- $product['PRODUCT_ID'] = $product["ID"];
- $product['PRODUCT_NAME'] = $product["NAME"];
- $product['PRODUCT_ACTIVE'] = $product["ACTIVE"];
- $product['PRICE'] = $product['CATALOG_PRICE_' . $basePriceId];
- $product['PURCHASE_PRICE'] = $product['CATALOG_PURCHASING_PRICE'];
- $product['QUANTITY'] = $product["CATALOG_QUANTITY"];
-
- foreach ($resPropertiesProduct as $key => $propProduct) {
- if ($this->propertiesProduct[$iblockId][$key] != "" || $this->propertiesProduct[$iblockId][str_replace("_UNIT", "", $key)] != "") {
- $product['_PROP_' . $key] = $propProduct;
- }
- }
-
- $this->PutOffer($product, $categories, $iblock, $allCategories);
- }
- }
-
- unset($products);
- }
-
- protected function getProductPicture($iblockId, array $product)
- {
- $picture = '';
-
- if (CFile::GetPath($product["DETAIL_PICTURE"])) {
- $picture = $this->getImageUrl($product["DETAIL_PICTURE"]);
- } elseif (CFile::GetPath($product["PREVIEW_PICTURE"])){
- $picture = $this->getImageUrl($product["PREVIEW_PICTURE"]);
- } elseif (
- $this->productPictures
- && isset($this->productPictures[$iblockId])
- && CFile::GetPath($product["PROPERTY_" . $this->productPictures[$iblockId]['picture'] . "_VALUE"])
- ) {
- $picture = $this->getImageUrl($product["PROPERTY_" . $this->productPictures[$iblockId]['picture'] . "_VALUE"]);
- }
-
- return $picture;
- }
-
- protected function PutOffer($arOffer, $categories, $iblock, &$allCategories)
- {
- $offerData = $this->BuildOffer($arOffer, $categories, $iblock, $allCategories);
-
- if ($offerData !== "") {
- $this->WriteOffers($offerData);
- }
- }
-
- protected function BuildOffer($arOffer, $categories, $iblock, &$allCategories)
- {
- $offer = "";
- $offer .= "PrepareValue($arOffer["ID"]) . "\" ".
- "productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
- "quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n";
-
- if ($arOffer['PRODUCT_ACTIVE'] == "N") {
- $offer .= "" . $this->PrepareValue($arOffer['PRODUCT_ACTIVE']) . "\n";
- }
-
- $keys = array_keys($categories);
- if (strpos($arOffer['DETAIL_PAGE_URL'], "#SECTION_PATH#") !== false) {
- if (count($categories) != 0) {
- $category = $allCategories[$keys[0]];
- $path = $category['CODE'];
-
- if (intval($category["IBLOCK_SECTION_ID"] ) != 0) {
- while (true) {
- $category = $allCategories[$category['IBLOCK_SECTION_ID']];
- $path = $category['CODE'] . '/' . $path;
- if(intval($category["IBLOCK_SECTION_ID"]) == 0){
- break;
- }
- }
- }
-
- }
- $arOffer['DETAIL_PAGE_URL'] = str_replace("#SECTION_PATH#", $path, $arOffer['DETAIL_PAGE_URL']);
- }
-
- if (isset($arOffer["PICTURE"]) && $arOffer["PICTURE"]) {
- $offer .= "\n";
- }
-
- $offer .= "" . $this->protocol . $this->serverName . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "\n";
-
- $offer .= "" . $this->PrepareValue($arOffer['PRICE']) . "\n";
-
- if ($this->loadPurchasePrice) {
- if ($arOffer['PURCHASE_PRICE']) {
- $offer .= "" . $this->PrepareValue($arOffer['PURCHASE_PRICE']) . "\n";
- } elseif ("Y" == $this->purchasePriceNull) {
- $offer .= "0\n";
- }
- }
-
- foreach ($categories as $category) {
- $offer .= "" . $category['ID'] . "\n";
- }
-
- $offer .= "" . $this->PrepareValue($arOffer["NAME"]) . "\n";
-
- $offer .= "" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "\n";
- $offer .= "" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "\n";
-
- foreach ($this->propertiesProduct[$iblock['ID']] as $key => $propProduct) {
- if ($propProduct != "" && $arOffer['_PROP_' . $key] != null) {
- if ($key === "manufacturer") {
- $offer .= "" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "\n";
- } else {
- $name = $key;
-
- if (isset($this->localizedIBlockProps[$key])) {
- $name = $this->localizedIBlockProps[$key];
- }
-
- $offer .= '" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "\n";
- }
- }
- }
- foreach ($this->propertiesSKU[$iblock['ID']] as $key => $propProduct) {
- if ($propProduct != "" && $arOffer['_PROP_' . $key] != null) {
- if ($key === "manufacturer") {
- $offer .= "" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "\n";
- } else {
- $name = $key;
-
- if (isset($this->localizedIBlockProps[$key])) {
- $name = $this->localizedIBlockProps[$key];
- }
-
- $offer .= '" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "\n";
- }
- }
- }
- if (isset($arOffer["MEASURE"]['SYMBOL_INTL'])) {
- if ($this->measure[$arOffer["MEASURE"]['SYMBOL_INTL']]) {
- $offer .= '' . "\n";
- } else {
- $offer .= '' . "\n";
- }
- } else {
- $measure = \Bitrix\Catalog\ProductTable::getCurrentRatioWithMeasure($arOffer["ID"]);
-
- if ($this->measure[$measure[$arOffer["ID"]]["MEASURE"]['SYMBOL_INTL']]) {
- $offer .= '' . "\n";
- } else {
- $offer .= '' . "\n";
- }
- }
-
- if ($arOffer["BARCODE"]) {
- $offer.= "" . $this->PrepareValue($arOffer["BARCODE"]) . "\n";
- }
-
- if ((float)$arOffer["CATALOG_VAT"]) {
- $vatRate = $arOffer["CATALOG_VAT"];
- } else {
- $vatRate = 'none';
- }
-
- $offer.= "" . $this->PrepareValue($vatRate) . "\n";
- $offer.= "\n";
-
- return $offer;
- }
-
- private function getHBprop($hbProp, $xml_id)
- {
- if (CModule::IncludeModule('highloadblock')) {
- $hlblockArr = \Bitrix\Highloadblock\HighloadBlockTable::getList(array(
- 'filter' => array('=TABLE_NAME' => $hbProp['USER_TYPE_SETTINGS']['TABLE_NAME'])
- ))->fetch();
-
- $hlblock = HL\HighloadBlockTable::getById($hlblockArr["ID"])->fetch();
- $entity = HL\HighloadBlockTable::compileEntity($hlblock);
- $entityClass = $entity->getDataClass();
-
- $result = $entityClass::getList(array(
- 'select' => array('*'),
- 'filter' => array('UF_XML_ID' => $xml_id)
- ));
-
- return $result->fetch();
- }
-
- return array();
- }
-
- /**
- * Returns products IDs with barcodes by infoblock id
- *
- * @param int $iblockId
- *
- * @return array
- */
- private function getProductBarcodesByIblock($iblockId)
- {
- $barcodes = array();
- $dbBarCode = CCatalogStoreBarCode::getList(
- array(),
- array("IBLOCK_ID" => $iblockId),
- false,
- false,
- array('PRODUCT_ID', 'BARCODE')
- );
-
- while ($arBarCode = $dbBarCode->GetNext()) {
- if (!empty($arBarCode)) {
- $barcodes[$arBarCode['PRODUCT_ID']] = $arBarCode['BARCODE'];
- }
- }
-
- return $barcodes;
- }
-
- /**
- * Returns necessary product properties
- *
- * @param int $iblockId
- * @param array $highloadblockProductProps
- * @param array $product
- *
- * @return array
- */
- private function getProductProperties($iblockId, $highloadblockProductProps, $product)
- {
- // Get properties of product
- $resPropertiesProduct = array();
-
- foreach ($this->propertiesProduct[$iblockId] as $key => $propProduct) {
- $resPropertiesProduct[$key] = "";
-
- if ($propProduct != "") {
- if (isset($product["PROPERTY_" . $propProduct . "_NAME"])) {
- $resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_NAME"];
- } elseif (isset($product["PROPERTY_" . $propProduct . "_VALUE"])) {
- $resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_VALUE"];
- } elseif (isset($product[$propProduct])) {
- $resPropertiesProduct[$key] = $product[$propProduct];
- }
-
- if (array_key_exists($key, $this->propertiesUnitProduct[$iblockId])) {
- $resPropertiesProduct[$key] *= $this->measurement[$this->propertiesUnitProduct[$iblockId][$key]];
- $resPropertiesProduct[$key . "_UNIT"] = $this->measurementLink[$this->propertiesUnitProduct[$iblockId][$key]];
- }
-
- if (isset($highloadblockProductProps[$propProduct])) {
- $propVal = $this->getHBprop($highloadblockProductProps[$propProduct], $product["PROPERTY_" . $propProduct . "_VALUE"]);
- $tableName = $highloadblockProductProps[$propProduct]['USER_TYPE_SETTINGS']['TABLE_NAME'];
- $field = $this->highloadblockProductProperties[$tableName][$iblockId][$key];
-
- $resPropertiesProduct[$key] = $propVal[$field];
- }
- }
- }
-
- return $resPropertiesProduct;
- }
-
- /**
- * @param array $allCategories
- * @param int $iblockId
- * @param string $productId
- *
- * @return array
- */
- private function getProductCategories(&$allCategories, $iblockId, $productId)
- {
- $categories = array();
- $dbResCategories = CIBlockElement::GetElementGroups($productId, true);
-
- while ($arResCategory = $dbResCategories->Fetch()) {
- $categories[$arResCategory["ID"]] = array(
- 'ID' => $arResCategory["ID"],
- 'NAME' => $arResCategory["NAME"],
- );
- }
-
- if (count($categories) == 0) {
- $catId = $this->mainSection + $iblockId;
- $categories[$catId] = $allCategories[$catId];
- }
-
- return $categories;
- }
-
- private function buildProductQuery($iblockId)
- {
- $arSelect = array(
- "ID",
- "LID",
- "IBLOCK_ID",
- "IBLOCK_SECTION_ID",
- "ACTIVE",
- "NAME",
- "DETAIL_PICTURE",
- "PREVIEW_PICTURE",
- "DETAIL_PAGE_URL",
- "CATALOG_GROUP_" . $this->getBasePriceId()
- );
-
- // Set selected properties
- foreach ($this->propertiesProduct[$iblockId] as $key => $propProduct) {
- if ($this->propertiesProduct[$iblockId][$key] != "") {
- $arSelect[] = "PROPERTY_" . $propProduct;
- $arSelect[] = "PROPERTY_" . $propProduct . ".NAME";
- }
- }
-
- if ($this->productPictures && isset($this->productPictures[$iblockId])) {
- $arSelect[] = "PROPERTY_" . $this->productPictures[$iblockId]['picture'];
- $arSelect[] = "PROPERTY_" . $this->productPictures[$iblockId]['picture'] . ".NAME";
- }
-
- return $arSelect;
- }
-
- private function buildOfferQuery($iblockId, $skuPropertyId)
- {
- $arSelectOffer = array(
- 'ID',
- "NAME",
- "DETAIL_PAGE_URL",
- "DETAIL_PICTURE",
- "PREVIEW_PICTURE",
- 'PROPERTY_' . $skuPropertyId,
- "CATALOG_GROUP_" . $this->getBasePriceId()
- );
-
- // Set selected properties
- foreach ($this->propertiesSKU[$iblockId] as $key => $propSKU) {
- if ($this->propertiesSKU[$iblockId][$key] != "") {
- $arSelectOffer[] = "PROPERTY_" . $propSKU;
- $arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
- }
- }
-
- if ($this->skuPictures && isset($this->skuPictures[$iblockId])) {
- $arSelectOffer[] = "PROPERTY_" . $this->skuPictures[$iblockId]['picture'];
- $arSelectOffer[] = "PROPERTY_" . $this->skuPictures[$iblockId]['picture'] . ".NAME";
- }
-
- return $arSelectOffer;
- }
-
- private function getAvailableHighloadProductProps($iblockId)
- {
- $highloadblockProductProps = array();
- $productProps = CIBlockproperty::GetList(array(), array("IBLOCK_ID" => $iblockId));
-
- while ($arrProductProps = $productProps->Fetch()) {
- if ($arrProductProps["USER_TYPE"] == 'directory') {
- $highloadblockProductProps[$arrProductProps['CODE']] = $arrProductProps;
- }
- }
-
- return $highloadblockProductProps;
- }
-
- private function getAvailableHighloadOfferSkuProps($iblockId)
- {
- $highloadblockSkuProps = array();
- $skuProps = CIBlockproperty::GetList(array(), array("IBLOCK_ID" => $iblockId));
-
- while ($arrSkuProps = $skuProps->Fetch()) {
- if ($arrSkuProps["USER_TYPE"] == 'directory') {
- $highloadblockSkuProps[$arrSkuProps['CODE']] = $arrSkuProps;
- }
- }
-
- return $highloadblockSkuProps;
- }
-
- /**
- * Returns base price id
- *
- * @return string
- */
- private function getBasePriceId()
- {
- $basePriceId = COption::GetOptionString(
- $this->MODULE_ID,
- $this->CRM_CATALOG_BASE_PRICE . '_' . $this->profileID,
- 0
- );
-
- if (!$basePriceId) {
- $dbPriceType = CCatalogGroup::GetList(
- array(),
- array('BASE' => 'Y'),
- false,
- false,
- array('ID')
- );
-
- $result = $dbPriceType->GetNext();
- $basePriceId = $result['ID'];
- }
-
- return $basePriceId;
- }
-
- private function getLocalizedIBlockProps()
- {
- return array(
- "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")
- );
- }
-
- /**
- * @param $fileId
- * @return string
- */
- public function getImageUrl($fileId)
- {
- $pathImage = CFile::GetPath($fileId);
- $validation = "/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i";
-
- if ((bool)preg_match($validation, $pathImage) === false) {
- return $this->protocol . $this->serverName . $pathImage;
- } else {
- return $pathImage;
- }
- }
-}
diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru
index 83198c85..ef06d746 100644
--- a/intaro.retailcrm/description.ru
+++ b/intaro.retailcrm/description.ru
@@ -1,3 +1,2 @@
-- Исправлено формирование картинок в ICML при включеном CDN
-- Убрана некорректная запись внешнего идентификатора платежа для новых платежей по истории
-- Добавлена проверка на длину email при отправке в систему
\ No newline at end of file
+- Переработан генератор ICML каталога;
+- Скидка на позицию больше не учитывается в заказе при установке произвольной цены для позиции.
\ No newline at end of file
diff --git a/intaro.retailcrm/export/export_run.php b/intaro.retailcrm/export/export_run.php
index 283faa3b..844ec7d5 100644
--- a/intaro.retailcrm/export/export_run.php
+++ b/intaro.retailcrm/export/export_run.php
@@ -1,59 +1,65 @@
'Y'));
- while ($ar = $rsSites->Fetch()) {
- if ($ar['DEF'] == 'Y') {
- $SERVER_NAME = $ar['SERVER_NAME'];
- }
+ if (
+ !CModule::IncludeModule('iblock')
+ || !CModule::IncludeModule('catalog')
+ || !CModule::IncludeModule('intaro.retailcrm')
+ ) {
+ return;
}
$hlblockModule = false;
if (CModule::IncludeModule('highloadblock')) {
$hlblockModule = true;
- $hlblockList = array();
- $hlblockListDb = \Bitrix\Highloadblock\HighloadBlockTable::getList();
+ $hlblockList = [];
+ $hlblockListDb = HighloadBlockTable::getList();
while ($hlblockArr = $hlblockListDb->Fetch()) {
$hlblockList[$hlblockArr["TABLE_NAME"]] = $hlblockArr;
}
}
- $iblockProperties = array(
- "article" => "article",
- "manufacturer" => "manufacturer",
- "color" =>"color",
- "weight" => "weight",
- "size" => "size",
- "length" => "length",
- "width" => "width",
- "height" => "height",
- );
- $IBLOCK_PROPERTY_SKU = array();
- $IBLOCK_PROPERTY_SKU_HIGHLOADBLOCK = array();
- $IBLOCK_PROPERTY_UNIT_SKU = array();
+ $iblockProperties = [
+ 'article' => 'article',
+ 'manufacturer' => 'manufacturer',
+ 'color' => 'color',
+ 'weight' => 'weight',
+ 'size' => 'size',
+ 'length' => 'length',
+ 'width' => 'width',
+ 'height' => 'height',
+ ];
+
+ $iblockPropertySku = [];
+ $iblockPropertySkuHl = [];
+ $iblockPropertyUnitSku = [];
+ $iblockPropertyProduct = [];
+ $iblockPropertyProductHl = [];
+ $iblockPropertyUnitProduct = [];
+
foreach ($iblockProperties as $prop) {
$skuUnitProps = ('IBLOCK_PROPERTY_UNIT_SKU' . "_" . $prop);
$skuUnitProps = $$skuUnitProps;
+
if (is_array($skuUnitProps)) {
foreach ($skuUnitProps as $iblock => $val) {
- $IBLOCK_PROPERTY_UNIT_SKU[$iblock][$prop] = $val;
+ $iblockPropertyUnitSku[$iblock][$prop] = $val;
}
}
@@ -61,7 +67,7 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/expor
$skuProps = $$skuProps;
if (is_array($skuProps)) {
foreach ($skuProps as $iblock => $val) {
- $IBLOCK_PROPERTY_SKU[$iblock][$prop] = $val;
+ $iblockPropertySku[$iblock][$prop] = $val;
}
}
@@ -72,22 +78,17 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/expor
if (is_array($hbProps)) {
foreach ($hbProps as $iblock => $val) {
- $IBLOCK_PROPERTY_SKU_HIGHLOADBLOCK[$hlblockTable][$iblock][$prop] = $val;
+ $iblockPropertySkuHl[$hlblockTable][$iblock][$prop] = $val;
}
}
}
}
- }
- $IBLOCK_PROPERTY_PRODUCT = array();
- $IBLOCK_PROPERTY_PRODUCT_HIGHLOADBLOCK = array();
- $IBLOCK_PROPERTY_UNIT_PRODUCT = array();
- foreach ($iblockProperties as $prop) {
$productUnitProps = "IBLOCK_PROPERTY_UNIT_PRODUCT" . "_" . $prop;
$productUnitProps = $$productUnitProps;
if (is_array($productUnitProps)) {
foreach ($productUnitProps as $iblock => $val) {
- $IBLOCK_PROPERTY_UNIT_PRODUCT[$iblock][$prop] = $val;
+ $iblockPropertyUnitProduct[$iblock][$prop] = $val;
}
}
@@ -95,7 +96,7 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/expor
$productProps = $$productProps;
if (is_array($productProps)) {
foreach ($productProps as $iblock => $val) {
- $IBLOCK_PROPERTY_PRODUCT[$iblock][$prop] = $val;
+ $iblockPropertyProduct[$iblock][$prop] = $val;
}
}
@@ -106,51 +107,52 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/expor
if (is_array($hbProps)) {
foreach ($hbProps as $iblock => $val) {
- $IBLOCK_PROPERTY_PRODUCT_HIGHLOADBLOCK[$hlblockTable][$iblock][$prop] = $val;
+ $iblockPropertyProductHl[$hlblockTable][$iblock][$prop] = $val;
}
}
}
}
}
- $productPictures = array();
+ $productPictures = [];
if (is_array($IBLOCK_PROPERTY_PRODUCT_picture)) {
foreach ($IBLOCK_PROPERTY_PRODUCT_picture as $key => $value) {
- $productPictures[$key]['picture'] = $value;
+ $productPictures[$key] = $value;
}
}
- $skuPictures = array();
+ $skuPictures = [];
if (is_array($IBLOCK_PROPERTY_SKU_picture)) {
foreach ($IBLOCK_PROPERTY_SKU_picture as $key => $value) {
- $skuPictures[$key]['picture'] = $value;
+ $skuPictures[$key] = $value;
}
}
- $loader = new RetailCrmICML();
- $loader->profileID = $profile_id;
- $loader->iblocks = $IBLOCK_EXPORT;
- $loader->propertiesSKU = $IBLOCK_PROPERTY_SKU;
- $loader->propertiesUnitSKU = $IBLOCK_PROPERTY_UNIT_SKU;
- $loader->propertiesProduct = $IBLOCK_PROPERTY_PRODUCT;
- $loader->propertiesUnitProduct = $IBLOCK_PROPERTY_UNIT_PRODUCT;
- $loader->productPictures = $productPictures;
- $loader->skuPictures = $skuPictures;
+ $xmlProps = new XmlSetupPropsCategories(
+ new XmlSetupProps($iblockPropertyProduct, $iblockPropertyUnitProduct, $productPictures),
+ new XmlSetupProps($iblockPropertySku, $iblockPropertyUnitSku, $skuPictures)
+ );
if ($hlblockModule === true) {
- $loader->highloadblockSkuProperties = $IBLOCK_PROPERTY_SKU_HIGHLOADBLOCK;
- $loader->highloadblockProductProperties = $IBLOCK_PROPERTY_PRODUCT_HIGHLOADBLOCK;
+ $xmlProps->highloadblockSku = $iblockPropertySkuHl;
+ $xmlProps->highloadblockProduct = $iblockPropertyProductHl;
}
- if ($MAX_OFFERS_VALUE) {
- $loader->offerPageSize = $MAX_OFFERS_VALUE;
- }
+ $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/');
- $loader->filename = $SETUP_FILE_NAME;
- $loader->defaultServerName = $SERVER_NAME;
- $loader->application = $APPLICATION;
- $loader->loadPurchasePrice = $LOAD_PURCHASE_PRICE == 'Y';
- $loader->Load();
-}
\ No newline at end of file
+ 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();
+ }
+}
diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php
index 10c11f56..fc545a0a 100644
--- a/intaro.retailcrm/export/export_setup.php
+++ b/intaro.retailcrm/export/export_setup.php
@@ -1,13 +1,16 @@
+
+use Bitrix\Highloadblock\HighloadBlockTable;
+
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");
} else {
if (isset($_POST['ajax']) && $_POST['ajax'] == '1') {
CModule::IncludeModule('highloadblock');
- $rsData = \Bitrix\Highloadblock\HighloadBlockTable::getList(array('filter' => array('TABLE_NAME' => $_POST['table'])));
+ $rsData = HighloadBlockTable::getList(['filter' => ['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"];
@@ -55,11 +58,11 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/expor
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"];
diff --git a/intaro.retailcrm/include.php b/intaro.retailcrm/include.php
index cece9049..65786258 100644
--- a/intaro.retailcrm/include.php
+++ b/intaro.retailcrm/include.php
@@ -14,7 +14,6 @@ CModule::AddAutoloadClasses(
'RetailCrmUser' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php') ? '../../php_interface/retailcrm/RetailCrmUser.php' : 'classes/general/user/RetailCrmUser.php',
'RetailCrmOrder' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php') ? '../../php_interface/retailcrm/RetailCrmOrder.php' : 'classes/general/order/RetailCrmOrder_' . $version . '.php',
'RetailCrmHistory' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php') ? '../../php_interface/retailcrm/RetailCrmHistory.php' : 'classes/general/history/RetailCrmHistory_' . $version . '.php',
- 'RetailCrmICML' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmICML.php') ? '../../php_interface/retailcrm/RetailCrmICML.php' : 'classes/general/icml/RetailCrmICML.php',
'RetailCrmInventories' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmInventories.php') ? '../../php_interface/retailcrm/RetailCrmInventories.php' : 'classes/general/inventories/RetailCrmInventories.php',
'RetailCrmPrices' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmPrices.php') ? '../../php_interface/retailcrm/RetailCrmPrices.php' : 'classes/general/prices/RetailCrmPrices.php',
'RetailCrmCollector' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmCollector.php') ? '../../php_interface/retailcrm/RetailCrmCollector.php' : 'classes/general/collector/RetailCrmCollector.php',
diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php
index a0433735..d9ca2f79 100644
--- a/intaro.retailcrm/install/index.php
+++ b/intaro.retailcrm/install/index.php
@@ -6,73 +6,74 @@
* Class name: intaro_retailcrm
*/
global $MESS;
+use Bitrix\Main\Context;
+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\Exception\CurlException;
+use RetailCrm\Response\ApiResponse;
+
IncludeModuleLangFile(__FILE__);
if (class_exists('intaro_retailcrm'))
return;
class intaro_retailcrm extends CModule
{
- var $MODULE_ID = 'intaro.retailcrm';
- var $OLD_MODULE_ID = 'intaro.intarocrm';
- var $MODULE_VERSION;
- var $MODULE_VERSION_DATE;
- var $MODULE_NAME;
- var $MODULE_DESCRIPTION;
- var $MODULE_GROUP_RIGHTS = 'N';
-
- var $PARTNER_NAME;
- var $PARTNER_URI;
-
- var $RETAIL_CRM_API;
- var $RETAIL_CRM_EXPORT = 'retailcrm';
- var $CRM_API_HOST_OPTION = 'api_host';
- var $CRM_API_KEY_OPTION = 'api_key';
- var $CRM_SITES_LIST= 'sites_list';
- var $CRM_ORDER_TYPES_ARR = 'order_types_arr';
- var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
- var $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
- var $CRM_PAYMENT_TYPES = 'pay_types_arr';
- var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
- var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
- var $CRM_ORDER_LAST_ID = 'order_last_id';
- var $CRM_ORDER_PROPS = 'order_props';
- var $CRM_LEGAL_DETAILS = 'legal_details';
- var $CRM_CUSTOM_FIELDS = 'custom_fields';
- var $CRM_CONTRAGENT_TYPE = 'contragent_type';
- var $CRM_ORDER_DISCHARGE = 'order_discharge';
- var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
- var $CRM_ORDER_HISTORY = 'order_history';
- var $CRM_CUSTOMER_HISTORY = 'customer_history';
- var $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
+ public $MODULE_ID = 'intaro.retailcrm';
+ public $OLD_MODULE_ID = 'intaro.intarocrm';
+ public $MODULE_VERSION;
+ public $MODULE_VERSION_DATE;
+ public $MODULE_NAME;
+ public $MODULE_DESCRIPTION;
+ public $MODULE_GROUP_RIGHTS = 'N';
+ public $PARTNER_NAME;
+ public $PARTNER_URI;
+ public $RETAIL_CRM_API;
+ public $RETAIL_CRM_EXPORT = 'retailcrm';
+ public $CRM_API_HOST_OPTION = 'api_host';
+ public $CRM_API_KEY_OPTION = 'api_key';
+ public $CRM_SITES_LIST = 'sites_list';
+ public $CRM_ORDER_TYPES_ARR = 'order_types_arr';
+ public $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
+ public $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr';
+ public $CRM_PAYMENT_TYPES = 'pay_types_arr';
+ public $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
+ public $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
+ public $CRM_ORDER_LAST_ID = 'order_last_id';
+ public $CRM_ORDER_PROPS = 'order_props';
+ public $CRM_LEGAL_DETAILS = 'legal_details';
+ public $CRM_CUSTOM_FIELDS = 'custom_fields';
+ public $CRM_CONTRAGENT_TYPE = 'contragent_type';
+ public $CRM_ORDER_DISCHARGE = 'order_discharge';
+ public $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
+ public $CRM_ORDER_HISTORY = 'order_history';
+ public $CRM_CUSTOMER_HISTORY = 'customer_history';
+ public $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
//var $CRM_CATALOG_IBLOCKS = 'catalog_base_iblocks';
- var $CRM_ORDER_NUMBERS = 'order_numbers';
- var $CRM_CANSEL_ORDER = 'cansel_order';
- var $CRM_CURRENCY = 'currency';
- var $CRM_ADDRESS_OPTIONS = 'address_options';
-
- var $CRM_INVENTORIES_UPLOAD = 'inventories_upload';
- var $CRM_STORES = 'stores';
- var $CRM_SHOPS = 'shops';
- var $CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories';
-
- var $CRM_PRICES_UPLOAD = 'prices_upload';
- var $CRM_PRICES = 'prices';
- var $CRM_PRICE_SHOPS = 'price_shops';
- var $CRM_IBLOCKS_PRICES = 'iblock_prices';
-
- var $CRM_COLLECTOR = 'collector';
- var $CRM_COLL_KEY = 'coll_key';
-
- var $CRM_UA = 'ua';
- var $CRM_UA_KEYS = 'ua_keys';
-
- var $CRM_API_VERSION = 'api_version';
- var $HISTORY_TIME = 'history_time';
-
- var $CLIENT_ID = 'client_id';
- var $PROTOCOL = 'protocol';
-
- var $INSTALL_PATH;
+ public $CRM_ORDER_NUMBERS = 'order_numbers';
+ public $CRM_CANSEL_ORDER = 'cansel_order';
+ public $CRM_CURRENCY = 'currency';
+ public $CRM_ADDRESS_OPTIONS = 'address_options';
+ public $CRM_INVENTORIES_UPLOAD = 'inventories_upload';
+ public $CRM_STORES = 'stores';
+ public $CRM_SHOPS = 'shops';
+ public $CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories';
+ public $CRM_PRICES_UPLOAD = 'prices_upload';
+ public $CRM_PRICES = 'prices';
+ public $CRM_PRICE_SHOPS = 'price_shops';
+ public $CRM_IBLOCKS_PRICES = 'iblock_prices';
+ public $CRM_COLLECTOR = 'collector';
+ public $CRM_COLL_KEY = 'coll_key';
+ public $CRM_UA = 'ua';
+ public $CRM_UA_KEYS = 'ua_keys';
+ public $CRM_API_VERSION = 'api_version';
+ public $HISTORY_TIME = 'history_time';
+ public $CLIENT_ID = 'client_id';
+ public $PROTOCOL = 'protocol';
+ public $INSTALL_PATH;
function intaro_retailcrm()
{
@@ -94,6 +95,7 @@ class intaro_retailcrm extends CModule
if (!class_exists('RetailcrmConstants')) {
require_once dirname(__FILE__) . '/../classes/general/RetailcrmConstants.php';
}
+
if (!class_exists('RetailcrmConfigProvider')) {
require_once dirname(__FILE__) . '/../classes/general/RetailcrmConfigProvider.php';
}
@@ -136,7 +138,33 @@ 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/icml/RetailCrmICML.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/offerparam.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');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlcategory.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmldata.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmloffer.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlsetup.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlsetupprops.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/xml/xmlsetuppropscategories.php');
+ include($this->INSTALL_PATH . '/../lib/icml/icmldirector.php');
+ include($this->INSTALL_PATH . '/../lib/icml/icmlwriter.php');
+ include($this->INSTALL_PATH . '/../lib/icml/queryparamsmolder.php');
+ include($this->INSTALL_PATH . '/../lib/icml/xmlcategorydirector.php');
+ include($this->INSTALL_PATH . '/../lib/icml/xmlcategoryfactory.php');
+ include($this->INSTALL_PATH . '/../lib/icml/xmlofferdirector.php');
+ include($this->INSTALL_PATH . '/../lib/icml/xmlofferbuilder.php');
+ include($this->INSTALL_PATH . '/../lib/icml/utils/icmlutils.php');
+ include($this->INSTALL_PATH . '/../lib/repository/catalogrepository.php');
+ include($this->INSTALL_PATH . '/../lib/repository/filerepository.php');
+ include($this->INSTALL_PATH . '/../lib/repository/hlrepository.php');
+ include($this->INSTALL_PATH . '/../lib/repository/measurerepository.php');
+ include($this->INSTALL_PATH . '/../lib/repository/siterepository.php');
+ include($this->INSTALL_PATH . '/../lib/service/hl.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/orm/catalogiblockinfo.php');
+ include($this->INSTALL_PATH . '/../lib/model/bitrix/orm/iblockcatalog.php');
+ include($this->INSTALL_PATH . '/../classes/general/RetailcrmConstants.php');
include($this->INSTALL_PATH . '/../classes/general/Exception/InvalidJsonException.php');
include($this->INSTALL_PATH . '/../classes/general/Exception/CurlException.php');
include($this->INSTALL_PATH . '/../classes/general/RestNormalizer.php');
@@ -367,7 +395,7 @@ class intaro_retailcrm extends CModule
$arResult['paymentStatusesList'] = $this->RETAIL_CRM_API->paymentStatusesList()->paymentStatuses;
$arResult['paymentList'] = $this->RETAIL_CRM_API->statusesList()->statuses;
$arResult['paymentGroupList'] = $this->RETAIL_CRM_API->statusGroupsList()->statusGroups;
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
RCrmActions::eventLog(
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage()
@@ -477,7 +505,7 @@ class intaro_retailcrm extends CModule
'description' => RCrmActions::toJSON($deliveryType['DESCRIPTION']),
'paymentTypes' => ''
)));
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
$load = false;
RCrmActions::eventLog(
'intaro.crm/install/index.php', 'RetailCrm\ApiClient::deliveryTypeEdit::CurlException',
@@ -496,7 +524,7 @@ class intaro_retailcrm extends CModule
'name' => RCrmActions::toJSON($deliveryService['NAME']),
'deliveryType' => $deliveryType['ID']
)));
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
RCrmActions::eventLog(
'intaro.crm/install/index.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
@@ -722,7 +750,7 @@ class intaro_retailcrm extends CModule
if ($historyDate = COption::GetOptionString($this->OLD_MODULE_ID, 'order_history_date', 0)) {
try {
$history = $api->ordersHistory(array('startDate' => $historyDate));
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
RCrmActions::eventLog(
'intaro.retailcrm/install/index.php', 'RetailCrm\RestApi::ordersHistory::CurlException',
$e->getCode() . ': ' . $e->getMessage()
@@ -903,9 +931,9 @@ class intaro_retailcrm extends CModule
}
if (!isset($_POST['MAX_OFFERS_VALUE'])) {
- $maxOffers = "";
+ $maxOffers = null;
} else {
- $maxOffers = $_POST['MAX_OFFERS_VALUE'];
+ $maxOffers = (int) $_POST['MAX_OFFERS_VALUE'];
}
if (!isset($_POST['SETUP_PROFILE_NAME'])) {
@@ -970,146 +998,171 @@ class intaro_retailcrm extends CModule
);
$this->CopyFiles();
- if (isset($_POST['LOAD_NOW'])) {
- $loader = new RetailCrmICML();
- $loader->iblocks = $iblocks;
- $loader->propertiesUnitProduct = $propertiesUnitProduct;
- $loader->propertiesProduct = $propertiesProduct;
- $loader->propertiesUnitSKU = $propertiesUnitSKU;
- $loader->propertiesSKU = $propertiesSKU;
-
- if ($hlblockModule === true) {
- $loader->highloadblockSkuProperties = $propertiesHbSKU;
- $loader->highloadblockProductProperties = $propertiesHbProduct;
- }
-
- if ($maxOffers) {
- $loader->offerPageSize = $maxOffers;
- }
-
- $loader->filename = $filename;
- $loader->serverName = \Bitrix\Main\Context::getCurrent()->getServer()->getHttpHost();
- $loader->application = $APPLICATION;
- $loader->Load();
- }
-
+
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE);
-
- if ($typeLoading == 'agent' || $typeLoading == 'cron') {
- if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->RETAIL_CRM_EXPORT . '_run.php')) {
- $dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->RETAIL_CRM_EXPORT));
-
- while ($arProfile = $dbProfile->Fetch()) {
- if ($arProfile["DEFAULT_PROFILE"] != "Y") {
- CAgent::RemoveAgent("CCatalogExport::PreGenerateExport(" . $arProfile['ID'] . ");", "catalog");
- CCatalogExport::Delete($arProfile['ID']);
- }
- }
- }
-
- $ar = $this->GetProfileSetupVars(
- $iblocks,
- $propertiesProduct,
- $propertiesUnitProduct,
- $propertiesSKU,
- $propertiesUnitSKU,
- $propertiesHbSKU,
- $propertiesHbProduct,
- $filename,
- $maxOffers
- );
- $PROFILE_ID = CCatalogExport::Add(array(
- "LAST_USE" => false,
- "FILE_NAME" => $this->RETAIL_CRM_EXPORT,
- "NAME" => $profileName,
- "DEFAULT_PROFILE" => "N",
- "IN_MENU" => "N",
- "IN_AGENT" => "N",
- "IN_CRON" => "N",
- "NEED_EDIT" => "N",
- "SETUP_VARS" => $ar
- ));
- if (intval($PROFILE_ID) <= 0) {
- $arResult['errCode'] = 'ERR_IBLOCK';
-
- return;
- }
-
- COption::SetOptionString(
- $this->MODULE_ID,
- $this->CRM_CATALOG_BASE_PRICE . '_' . $PROFILE_ID,
- htmlspecialchars(trim($_POST['price-types']))
- );
-
- if ($typeLoading == 'agent') {
- $dateAgent = new DateTime();
- $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
- $dateAgent->add($intAgent);
- CAgent::AddAgent(
- "CCatalogExport::PreGenerateExport(" . $PROFILE_ID . ");", "catalog", "N", 86400, $dateAgent->format('d.m.Y H:i:s'), // date of first check
- "Y", // agent is active
- $dateAgent->format('d.m.Y H:i:s'), // date of first start
- 30
- );
-
- CCatalogExport::Update($PROFILE_ID, array(
- "IN_AGENT" => "Y"
- ));
- } else {
- $agent_period = 24;
- $agent_php_path = "/usr/local/php/bin/php";
-
- if (!file_exists($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php")) {
- CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS);
- $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php");
- $fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php", "rb");
- $tmp_data = fread($fp, $tmp_file_size);
- fclose($fp);
-
- $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data);
- $tmp_data = str_replace("#PHP_PATH#", $agent_php_path, $tmp_data);
-
- $fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php", "ab");
- fwrite($fp, $tmp_data);
- fclose($fp);
- }
-
- $cfg_data = "";
- if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) {
- $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg");
- $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb");
- $cfg_data = fread($fp, $cfg_file_size);
- fclose($fp);
- }
-
- CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/");
-
- if ($arProfile["IN_CRON"] == "Y") {
- // remove
- $cfg_data = preg_replace("#^.*?" . preg_quote(CATALOG_PATH2EXPORTS) . "cron_frame.php +" . $PROFILE_ID . " *>.*?$#im", "", $cfg_data);
- } else {
- $strTime = "0 */" . $agent_period . " * * * ";
- if (strlen($cfg_data) > 0)
- $cfg_data .= "\n";
-
- $cfg_data .= $strTime . $agent_php_path . " -f " . $_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php " . $PROFILE_ID . " >" . $_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/" . $PROFILE_ID . ".txt\n";
- }
-
- CCatalogExport::Update($PROFILE_ID, array(
- "IN_CRON" => "Y"
- ));
-
- CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/");
- $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data);
- $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb");
- fwrite($fp, $cfg_data);
- fclose($fp);
-
- $arRetval = array();
- @exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var);
+
+ if (
+ file_exists($_SERVER['DOCUMENT_ROOT']
+ . '/bitrix/php_interface/include/catalog_export/'
+ . $this->RETAIL_CRM_EXPORT
+ . '_run.php')
+ ) {
+ $dbProfile = CCatalogExport::GetList([], ['FILE_NAME' => $this->RETAIL_CRM_EXPORT]);
+
+ if ($dbProfile instanceof CDBResult) {
+ $this->removeExportProfiles($dbProfile);
+
}
}
-
+
+ $setupVars = $this->getProfileSetupVars(
+ $iblocks,
+ $propertiesProduct,
+ $propertiesUnitProduct,
+ $propertiesSKU,
+ $propertiesUnitSKU,
+ $propertiesHbSKU,
+ $propertiesHbProduct,
+ $filename,
+ $maxOffers
+ );
+ $profileId = CCatalogExport::Add([
+ "LAST_USE" => false,
+ "FILE_NAME" => $this->RETAIL_CRM_EXPORT,
+ "NAME" => $profileName,
+ "DEFAULT_PROFILE" => "N",
+ "IN_MENU" => "N",
+ "IN_AGENT" => "N",
+ "IN_CRON" => "N",
+ "NEED_EDIT" => "N",
+ "SETUP_VARS" => $setupVars,
+ ]);
+
+ if ((int) $profileId <= 0) {
+ $arResult['errCode'] = 'ERR_IBLOCK';
+
+ return;
+ }
+
+ COption::SetOptionString(
+ $this->MODULE_ID,
+ $this->CRM_CATALOG_BASE_PRICE . '_' . $profileId,
+ htmlspecialchars(trim($_POST['price-types']))
+ );
+
+ $agentId = null;
+
+ if ($typeLoading === 'agent') {
+ $dateAgent = new DateTime();
+ $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec;
+ $dateAgent->add($intAgent);
+ $agentId = CAgent::AddAgent(
+ 'CCatalogExport::PreGenerateExport(' . $profileId . ');',
+ 'catalog',
+ 'N',
+ 86400,
+ $dateAgent->format('d.m.Y H:i:s'),
+ 'Y',
+ $dateAgent->format('d.m.Y H:i:s'),
+ 30
+ );
+
+ CCatalogExport::Update($profileId, [
+ "IN_AGENT" => "Y",
+ ]);
+ }
+
+ if (
+ isset($_POST['LOAD_NOW'])
+ && $agentId === null
+ ) {
+ CAgent::AddAgent(
+ '\Intaro\RetailCrm\Component\Agent::preGenerateExport(' . $profileId . ');',
+ $this->MODULE_ID,
+ 'N',
+ 86400,
+ $dateAgent->format('d.m.Y H:i:s'),
+ 'Y',
+ $dateAgent->format('d.m.Y H:i:s')
+ );
+ }
+
+
+ if ('cron' === $typeLoading) {
+ include($this->INSTALL_PATH . '/../lib/vendor/symfony/component/process/phpexecutablefinder.php');
+ include($this->INSTALL_PATH . '/../lib/vendor/symfony/component/process/executablefinder.php');
+
+ $agent_period = 24;
+ $finder = new PhpExecutableFinder();
+ $agent_php_path = $finder->find();
+
+ if (!file_exists($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php")) {
+ CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS);
+ $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php");
+ $fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php", "rb");
+ $tmp_data = fread($fp, $tmp_file_size);
+ fclose($fp);
+
+ $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data);
+ $tmp_data = str_replace("#PHP_PATH#", $agent_php_path, $tmp_data);
+
+ $fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php", "ab");
+ fwrite($fp, $tmp_data);
+ fclose($fp);
+ }
+
+ $cfg_data = "";
+ if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) {
+ $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg");
+ $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb");
+ $cfg_data = fread($fp, $cfg_file_size);
+ fclose($fp);
+ }
+
+ CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/");
+
+ if ($arProfile["IN_CRON"] == "Y") {
+ // remove
+ $cfg_data = preg_replace("#^.*?"
+ . preg_quote(CATALOG_PATH2EXPORTS)
+ . "cron_frame.php +"
+ . $profileId
+ . " *>.*?$#im", "", $cfg_data);
+ } else {
+ $strTime = "0 */" . $agent_period . " * * * ";
+ if (strlen($cfg_data) > 0) {
+ $cfg_data .= "\n";
+ }
+
+ $cfg_data .= $strTime
+ . $agent_php_path
+ . " -f "
+ . $_SERVER["DOCUMENT_ROOT"]
+ . CATALOG_PATH2EXPORTS
+ . "cron_frame.php "
+ . $profileId
+ . " >"
+ . $_SERVER["DOCUMENT_ROOT"]
+ . CATALOG_PATH2EXPORTS
+ . "logs/"
+ . $profileId
+ . ".txt\n";
+ }
+
+ CCatalogExport::Update($profileId, [
+ "IN_CRON" => "Y",
+ ]);
+
+ CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/");
+ $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data);
+ $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb");
+ fwrite($fp, $cfg_data);
+ fclose($fp);
+
+ $arRetval = [];
+ @exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var);
+ }
+
$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);
@@ -1217,17 +1270,19 @@ class intaro_retailcrm extends CModule
UnRegisterModuleDependences("main", "OnBeforeProlog", $this->MODULE_ID, "RetailCrmUa", "add");
UnRegisterModuleDependences("sale", "OnSalePaymentEntitySaved", $this->MODULE_ID, "RetailCrmEvent", "paymentSave");
UnRegisterModuleDependences("sale", "OnSalePaymentEntityDeleted", $this->MODULE_ID, "RetailCrmEvent", "paymentDelete");
+
+ if (
+ CModule::IncludeModule('catalog')
+ && file_exists($_SERVER['DOCUMENT_ROOT']
+ . '/bitrix/php_interface/include/catalog_export/'
+ . $this->RETAIL_CRM_EXPORT
+ . '_run.php')
+ ) {
+ $dbProfile = CCatalogExport::GetList([], ['FILE_NAME' => $this->RETAIL_CRM_EXPORT]);
- if (CModule::IncludeModule("catalog")) {
- if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/' . $this->RETAIL_CRM_EXPORT . '_run.php')) {
- $dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->RETAIL_CRM_EXPORT));
-
- while ($arProfile = $dbProfile->Fetch()) {
- if ($arProfile["DEFAULT_PROFILE"] != "Y") {
- CAgent::RemoveAgent("CCatalogExport::PreGenerateExport(" . $arProfile['ID'] . ");", "catalog");
- CCatalogExport::Delete($arProfile['ID']);
- }
- }
+ if ($dbProfile instanceof CDBResult) {
+ $this->removeExportProfiles($dbProfile);
+
}
}
@@ -1245,7 +1300,14 @@ class intaro_retailcrm extends CModule
function CopyFiles()
{
CopyDirFiles(
- $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/export/', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/', true, true
+ $_SERVER['DOCUMENT_ROOT']
+ . '/bitrix/modules/'
+ . $this->MODULE_ID
+ . '/install/export/',
+ $_SERVER['DOCUMENT_ROOT']
+ . '/bitrix/php_interface/include/catalog_export/',
+ true,
+ true
);
}
@@ -1264,7 +1326,7 @@ class intaro_retailcrm extends CModule
rmdir($defaultSite['ABS_DOC_ROOT'] . '/retailcrm/');
}
- function GetProfileSetupVars(
+ function getProfileSetupVars(
$iblocks,
$propertiesProduct,
$propertiesUnitProduct,
@@ -1316,7 +1378,7 @@ class intaro_retailcrm extends CModule
try {
$history = $api->$method(array(), $page);
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
RCrmActions::eventLog(
'RetailCrmHistory::' . $method, 'RetailCrm\RestApi::' . $method . '::CurlException',
$e->getCode() . ': ' . $e->getMessage()
@@ -1336,7 +1398,7 @@ class intaro_retailcrm extends CModule
while (true) {
try {
$history = $api->$method(array(), $page);
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
RCrmActions::eventLog(
'RetailCrmHistory::' . $method, 'RetailCrm\RestApi::' . $method . '::CurlException',
$e->getCode() . ': ' . $e->getMessage()
@@ -1380,7 +1442,7 @@ class intaro_retailcrm extends CModule
$client = new RetailCrm\Http\Client($api_host . '/api/' . $version, array('apiKey' => $api_key));
try {
$result = $client->makeRequest('/reference/sites', 'GET');
- } catch (\RetailCrm\Exception\CurlException $e) {
+ } catch (CurlException $e) {
RCrmActions::eventLog(
'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::sitesList',
$e->getCode() . ': ' . $e->getMessage()
@@ -1389,7 +1451,7 @@ class intaro_retailcrm extends CModule
$res['errCode'] = 'ERR_' . $e->getCode();
}
- if ($result->getStatusCode() == 200) {
+ if ($result instanceof ApiResponse && $result->getStatusCode() == 200) {
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, $version);
$res['sitesList'] = $APPLICATION->ConvertCharsetArray($result->sites, 'utf-8', SITE_CHARSET);
@@ -1401,4 +1463,19 @@ class intaro_retailcrm extends CModule
return $res;
}
+
+ /**
+ * Удаляет профили экспорта icml каталага и агент, запускавший этот экспорт
+ *
+ * @param \CDBResult $dbProfile
+ */
+ private function removeExportProfiles(CDBResult $dbProfile): void
+ {
+ while ($arProfile = $dbProfile->Fetch()) {
+ if ($arProfile['DEFAULT_PROFILE'] !== 'Y') {
+ CAgent::RemoveAgent('CCatalogExport::PreGenerateExport(' . $arProfile['ID'] . ');', 'catalog');
+ CCatalogExport::Delete($arProfile['ID']);
+ }
+ }
+ }
}
diff --git a/intaro.retailcrm/install/step5.php b/intaro.retailcrm/install/step5.php
index 310f2663..51c99670 100644
--- a/intaro.retailcrm/install/step5.php
+++ b/intaro.retailcrm/install/step5.php
@@ -495,8 +495,9 @@ if (!empty($oldValues)) {
=GetMessage("LOAD_NOW");?>
-
+
+
=GetMessage("LOAD_NOW_MSG");?>
=GetMessage("BASE_PRICE");?>