From 7f69ebfa1fef8de7103b65440fb0a0e6463e5e43 Mon Sep 17 00:00:00 2001 From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com> Date: Mon, 1 Apr 2024 09:34:11 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#93089=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B0=20(#3?= =?UTF-8?q?42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 ++- intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 4 +- .../lib/icml/xmlcategorydirector.php | 7 ++-- intaro.retailcrm/lib/icml/xmlofferbuilder.php | 15 ++++--- .../lib/icml/xmlofferdirector.php | 4 +- .../lib/repository/filerepository.php | 23 +++++++---- .../lib/repository/siterepository.php | 40 +++++++++++++++++++ 8 files changed, 80 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cd9b73f..1184ecd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ +## 2024-03-28 v.6.5.12 +- Исправлена подстановка домена при генерации каталога + ## 2024-03-28 v.6.5.11 - Исправлена ошибка дублирования скидок ## 2024-03-18 v.6.5.10 -- Добавлена валидация прав API ключа +- Добавлена валидация прав API ключа ## 2024-03-01 v.6.5.9 - Исправлена проверка ФИО при отправке заказа в систему diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index c8674623..e880878d 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправлена ошибка дублирования скидок +- Исправлена подстановка домена при генерации каталога diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 06669763..33e20df8 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.5.11', - 'VERSION_DATE' => '2024-03-28 12:00:00' + 'VERSION' => '6.5.12', + 'VERSION_DATE' => '2024-03-28 17:00:00' ]; diff --git a/intaro.retailcrm/lib/icml/xmlcategorydirector.php b/intaro.retailcrm/lib/icml/xmlcategorydirector.php index 6bc48831..709b7dd1 100644 --- a/intaro.retailcrm/lib/icml/xmlcategorydirector.php +++ b/intaro.retailcrm/lib/icml/xmlcategorydirector.php @@ -91,9 +91,10 @@ class XmlCategoryDirector } try { + $xmlCategory = $this->xmlCategoryFactory->create( $category, - $this->fileRepository->getImageUrl($category->get('PICTURE')) + $this->fileRepository->getImageUrl($category->get('PICTURE'), $category->get('IBLOCK_ID')) ); if (!$xmlCategory) { @@ -102,7 +103,7 @@ class XmlCategoryDirector $xmlCategories[$categoryKey] = $this->xmlCategoryFactory->create( $category, - $this->fileRepository->getImageUrl($category->get('PICTURE')) + $this->fileRepository->getImageUrl($category->get('PICTURE'), $category->get('IBLOCK_ID')) ); } catch (ArgumentException | SystemException $exception) { AddMessage2Log($exception->getMessage()); @@ -130,7 +131,7 @@ class XmlCategoryDirector try { return $this->xmlCategoryFactory->create( $iblock, - $this->fileRepository->getImageUrl($iblock->get('PICTURE')), + $this->fileRepository->getImageUrl($iblock->get('PICTURE'), $iblockId), $categoryId ); } catch (ArgumentException | SystemException $exception) { diff --git a/intaro.retailcrm/lib/icml/xmlofferbuilder.php b/intaro.retailcrm/lib/icml/xmlofferbuilder.php index 68a7dd8c..6bce17dc 100644 --- a/intaro.retailcrm/lib/icml/xmlofferbuilder.php +++ b/intaro.retailcrm/lib/icml/xmlofferbuilder.php @@ -42,7 +42,7 @@ class XmlOfferBuilder /** * @var string|null */ - private $defaultServerName; + private $serverName; /** * @var array @@ -106,16 +106,16 @@ class XmlOfferBuilder * * @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetup $setup * @param array $measure - * @param string|null $defaultServerName + * @param string|null $serverName */ - public function __construct(XmlSetup $setup, array $measure, ?string $defaultServerName) + public function __construct(XmlSetup $setup, array $measure, ?string $serverName) { $this->setup = $setup; $this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice(); $this->settingsService = SettingsService::getInstance([], ''); $this->vatRates = $this->settingsService->vatRates; $this->measures = $this->prepareMeasures($measure); - $this->defaultServerName = $defaultServerName; + $this->serverName = $serverName; } /** @@ -198,6 +198,11 @@ class XmlOfferBuilder $this->productPicture = $getProductPicture; } + public function setServerName(string $serverName): void + { + $this->serverName = $serverName; + } + /** * Добавляет в XmlOffer значения настраиваемых параметров, производителя, вес и габариты */ @@ -242,7 +247,7 @@ class XmlOfferBuilder $this->xmlOffer->productType = (int) $item['CATALOG_TYPE']; $this->xmlOffer->quantity = $item['CATALOG_QUANTITY'] ?? ''; $this->xmlOffer->url = $item['DETAIL_PAGE_URL'] - ? $this->defaultServerName . $item['DETAIL_PAGE_URL'] + ? $this->serverName . $item['DETAIL_PAGE_URL'] : ''; $this->xmlOffer->price = $item['CATALOG_PRICE_' . $this->setup->basePriceId]; $this->xmlOffer->purchasePrice = $this->getPurchasePrice( diff --git a/intaro.retailcrm/lib/icml/xmlofferdirector.php b/intaro.retailcrm/lib/icml/xmlofferdirector.php index afca61e3..ef175f39 100644 --- a/intaro.retailcrm/lib/icml/xmlofferdirector.php +++ b/intaro.retailcrm/lib/icml/xmlofferdirector.php @@ -74,6 +74,8 @@ class XmlOfferDirector $ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo, $this->setup->loadNonActivity); $offers = []; + $this->xmlOfferBuilder->setServerName($this->fileRepository->getServerName($catalogIblockInfo->productIblockId)); + while ($offer = $ciBlockResult->Fetch()) { $categories = $this->catalogRepository->getProductCategories($offer['ID']); $offer['DETAIL_PAGE_URL'] = $this->replaceUrlTemplate($offer, $categories); @@ -211,7 +213,7 @@ class XmlOfferDirector $this->xmlOfferBuilder->setPicturesPath( $this ->fileRepository - ->getProductPicture($product, $pictureProperty ?? '') + ->getProductPicture($product, $pictureProperty ?? '', $catalogIblockInfo->productIblockId) ); } diff --git a/intaro.retailcrm/lib/repository/filerepository.php b/intaro.retailcrm/lib/repository/filerepository.php index 8d087486..c10308d4 100644 --- a/intaro.retailcrm/lib/repository/filerepository.php +++ b/intaro.retailcrm/lib/repository/filerepository.php @@ -14,6 +14,9 @@ class FileRepository * @var string */ private $defaultServerName; + + /** @var array */ + private $domainCatalogList = []; /** * FileRepository constructor. @@ -22,13 +25,14 @@ class FileRepository public function __construct(string $defaultServerName) { $this->defaultServerName = $defaultServerName; + $this->domainCatalogList = SiteRepository::getDomainList(); } /** * @param int|null $fileId * @return string */ - public function getImageUrl(?int $fileId): string + public function getImageUrl(?int $fileId, ?int $iBlockId = null): string { if (!$fileId) { return ''; @@ -36,9 +40,9 @@ class FileRepository $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->defaultServerName . $pathImage; + return $this->getServerName($iBlockId) . $pathImage; } return $pathImage; @@ -49,19 +53,24 @@ class FileRepository * @param string $pictureProp * @return string */ - public function getProductPicture(array $product, string $pictureProp = ''): string + public function getProductPicture(array $product, string $pictureProp = '', ?int $iBlockId = null): string { $picture = ''; $pictureId = $product['PROPERTY_' . $pictureProp . '_VALUE'] ?? null; if (isset($product['DETAIL_PICTURE'])) { - $picture = $this->getImageUrl($product['DETAIL_PICTURE']); + $picture = $this->getImageUrl($product['DETAIL_PICTURE'], $iBlockId); } elseif (isset($product['PREVIEW_PICTURE'])) { - $picture = $this->getImageUrl($product['PREVIEW_PICTURE']); + $picture = $this->getImageUrl($product['PREVIEW_PICTURE'], $iBlockId); } elseif ($pictureId !== null) { - $picture = $this->getImageUrl($pictureId); + $picture = $this->getImageUrl($pictureId, $iBlockId); } return $picture ?? ''; } + + public function getServerName(?int $iBlockId): string + { + return $this->domainCatalogList[$iBlockId] ?? $this->defaultServerName; + } } diff --git a/intaro.retailcrm/lib/repository/siterepository.php b/intaro.retailcrm/lib/repository/siterepository.php index fd7f528d..63a04e3f 100644 --- a/intaro.retailcrm/lib/repository/siterepository.php +++ b/intaro.retailcrm/lib/repository/siterepository.php @@ -4,6 +4,7 @@ namespace Intaro\RetailCrm\Repository; use CSite; use RetailcrmConfigProvider; +use Bitrix\Iblock\IblockTable; /** * Class SiteRepository @@ -26,4 +27,43 @@ class SiteRepository return null; } + + public static function getDomainList(): ?array + { + $result = []; + $resultBlock = []; + $resultSites = []; + + try { + $iBlockResult = IblockTable::GetList(['select' => ['ID', 'LID']], $sort, ['ACTIVE' => 'Y']); + + while ($iBlock = $iBlockResult->Fetch()) { + $resultBlock[] = $iBlock; + } + + $resultBlock = array_column($resultBlock, 'LID', 'ID'); + + $rsSites = CSite::GetList($by, $sort, ['ACTIVE' => 'Y']); + + while ($site = $rsSites->Fetch()) { + $resultSites[] = $site; + } + + $resultSites = array_column($resultSites, 'SERVER_NAME', 'LID'); + + foreach ($resultBlock as $id => $lid) { + if (isset($resultSites[$lid])) { + $result[$id] = RetailcrmConfigProvider::getProtocol() . $resultSites[$lid]; + } + } + } catch (\Throwable $exception) { + RCrmActions::eventLog( + 'SiteRepository:getDomainList', + 'domain', + 'Error when obtaining domains: ' . $exception->getMessage() + ); + } + + return $result; + } }