From 2c161d3d261393b2daa148c661ace90fd232f035 Mon Sep 17 00:00:00 2001 From: gorokh Date: Wed, 13 Jan 2021 15:45:46 +0300 Subject: [PATCH] CDN correct url in icml --- CHANGELOG.md | 5 +++ .../classes/general/icml/RetailCrmICML.php | 36 ++++++++++++------ intaro.retailcrm/description.ru | 4 +- intaro.retailcrm/install/version.php | 4 +- tests/bootstrap.php | 6 +++ .../general/icml/RetailCrmICMLTest.php | 37 +++++++++++++++++++ 6 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 tests/classes/general/icml/RetailCrmICMLTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aa036f0..022e3c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2021-01-14 v.5.6.2 +* Исправлено формирование картинок в ICML при включеном CDN +* Убрана некорректная запись внешнего идентификатора платежа для новых платежей по истории +* Добавлена проверка на длину email при отправке в систему + ## 2020-12-15 v.5.6.1 * Обновлено наименование бренда diff --git a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php index adc0d841..9b4aae34 100644 --- a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php +++ b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php @@ -257,11 +257,11 @@ class RetailCrmICML . "" . $this->PrepareValue($arCategory["NAME"]) . "\n"; if (CFile::GetPath($arCategory["DETAIL_PICTURE"])) { - $category .= "\t" . $arCategory['SITE'] . CFile::GetPath($arCategory["DETAIL_PICTURE"]) . "\n"; + $category .= "\t" . $this->getImageUrl($arCategory["DETAIL_PICTURE"]) . "\n"; } if (CFile::GetPath($arCategory["PICTURE"])) { - $category .= "\t" . $arCategory['SITE'] . CFile::GetPath($arCategory["PICTURE"]) . "\n"; + $category .= "\t" . $this->getImageUrl($arCategory["PICTURE"]) . "\n"; } $category .= "\n"; @@ -421,16 +421,15 @@ class RetailCrmICML $offer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"]; if (CFile::GetPath($offer["DETAIL_PICTURE"])) { - $offer['PICTURE'] = $this->protocol . $this->serverName . CFile::GetPath($offer["DETAIL_PICTURE"]); - } elseif (CFile::GetPath($offer["PREVIEW_PICTURE"])){ - $offer['PICTURE'] = $this->protocol . $this->serverName . CFile::GetPath($offer["PREVIEW_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"]) ) { - $picture = CFile::GetPath($offer["PROPERTY_" . $this->skuPictures[$iblockId]['picture'] . "_VALUE"]); - $offer['PICTURE'] = $this->protocol . $this->serverName . $picture; + $offer['PICTURE'] = $this->getImageUrl($offer["PROPERTY_" . $this->skuPictures[$iblockId]['picture'] . "_VALUE"]); } else { $offer['PICTURE'] = $product['PICTURE']; } @@ -502,16 +501,15 @@ class RetailCrmICML $picture = ''; if (CFile::GetPath($product["DETAIL_PICTURE"])) { - $picture = $this->protocol . $this->serverName . CFile::GetPath($product["DETAIL_PICTURE"]); + $picture = $this->getImageUrl($product["DETAIL_PICTURE"]); } elseif (CFile::GetPath($product["PREVIEW_PICTURE"])){ - $picture= $this->protocol . $this->serverName . 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"]) ) { - $file = CFile::GetPath($product["PROPERTY_" . $this->productPictures[$iblockId]['picture'] . "_VALUE"]); - $picture = $this->protocol . $this->serverName . $file; + $picture = $this->getImageUrl($product["PROPERTY_" . $this->productPictures[$iblockId]['picture'] . "_VALUE"]); } return $picture; @@ -894,4 +892,20 @@ class RetailCrmICML "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 fc6b7015..db3af293 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1,3 @@ -- Обновлено наименование бренда +- Исправлено формирование картинок в ICML при включеном CDN +- Убрана некорректная запись внешнего идентификатора платежа для новых платежей по истории +- Добавлена проверка на длину email при отправке в систему diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 3923c760..bb562d48 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,5 +1,5 @@ "5.6.1", - "VERSION_DATE" => "2020-12-15 12:00:00" + "VERSION" => "5.6.2", + "VERSION_DATE" => "2021-01-14 16:00:00" ); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7b627d92..9ed17302 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,4 +31,10 @@ if (!IsModuleInstalled('intaro.retailcrm')) { COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5'); CModule::IncludeModule('intaro.retailcrm'); +CModule::IncludeModule("main"); +global $DB; +$strSql = "INSERT INTO b_file (TIMESTAMP_X, MODULE_ID, HEIGHT, WIDTH, FILE_SIZE, CONTENT_TYPE, SUBDIR, FILE_NAME, ORIGINAL_NAME, DESCRIPTION, HANDLER_ID, EXTERNAL_ID) +VALUES ('2020-05-08 19:04:03', 'iblock', '500', '500', '23791', 'image/jpeg', 'iblock/c44', 'test.jpg', '788c4cf58bd93a5f75f2e3f2034023db.jpg', '', '', 'c570f175b3f74ccfa62c4a10d8e44b5c');"; +$DB->Query($strSql); + require_once 'BitrixTestCase.php'; diff --git a/tests/classes/general/icml/RetailCrmICMLTest.php b/tests/classes/general/icml/RetailCrmICMLTest.php new file mode 100644 index 00000000..06a5ff94 --- /dev/null +++ b/tests/classes/general/icml/RetailCrmICMLTest.php @@ -0,0 +1,37 @@ +assertTrue(Loader::includeModule("intaro.retailcrm")); + } + + public function testGetImageUrl() + { + $test = new RetailCrmICML(); + $result = $test->getImageUrl(1); + + if (!empty($result)) { + $this->assertIsString($result); + $this->assertEquals("/upload/iblock/c44/test.jpg", $result); + } else { + $this->assertEmpty($result); + } + } +}