From 960ed4438aaed36c2eec1bfbf46d217f687c6a0e Mon Sep 17 00:00:00 2001 From: max-baranikov Date: Fri, 26 Aug 2022 13:30:51 +0300 Subject: [PATCH] Added loading catalog in CRM after ICML generation --- retailcrm/lib/RetailcrmCatalogHelper.php | 28 +++++++++++++++++++++ retailcrm/lib/events/RetailcrmIcmlEvent.php | 14 +++++++++++ retailcrm/views/index.html | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/retailcrm/lib/RetailcrmCatalogHelper.php b/retailcrm/lib/RetailcrmCatalogHelper.php index 17d6b25..e02e5d9 100644 --- a/retailcrm/lib/RetailcrmCatalogHelper.php +++ b/retailcrm/lib/RetailcrmCatalogHelper.php @@ -87,6 +87,34 @@ class RetailcrmCatalogHelper return _PS_ROOT_DIR_ . '/' . self::getIcmlFileName(); } + public static function isIcmlFileLinkActual() + { + $api = RetailcrmTools::getApiClient(); + if (empty($api)) { + return null; + } + + $reference = new RetailcrmReferences($api); + $site = $reference->getSite(); + + if (empty($site)) { + return null; + } + + $newYmlUrl = RetailcrmCatalogHelper::getIcmlFileLink(); + + RetailcrmLogger::writeDebug( + __METHOD__, sprintf( + 'Comparing %s and %s: %s', + $newYmlUrl, + $site['ymlUrl'], + $newYmlUrl === $site['ymlUrl'] ? 'true' : 'false' + ) + ); + + return $newYmlUrl === $site['ymlUrl']; + } + /** * @param int $productsCount * @param int $offersCount diff --git a/retailcrm/lib/events/RetailcrmIcmlEvent.php b/retailcrm/lib/events/RetailcrmIcmlEvent.php index e0e721f..d36d733 100644 --- a/retailcrm/lib/events/RetailcrmIcmlEvent.php +++ b/retailcrm/lib/events/RetailcrmIcmlEvent.php @@ -61,6 +61,20 @@ class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEven $icml = new RetailcrmIcml($shop['name'], RetailcrmCatalogHelper::getIcmlFilePath()); $icml->generate($data[0], $data[1]); + + if (true !== RetailcrmCatalogHelper::isIcmlFileLinkActual()) { + RetailcrmLogger::writeDebug( + __METHOD__, + 'Skip statistic update due to non consistent ICML file link' + ); + + continue; + } + + $api = RetailcrmTools::getApiClient(); + if (null !== $api) { + $api->statisticUpdate(); + } } return true; diff --git a/retailcrm/views/index.html b/retailcrm/views/index.html index 684fbaa..360f168 100644 --- a/retailcrm/views/index.html +++ b/retailcrm/views/index.html @@ -1 +1 @@ -prestashop
\ No newline at end of file +prestashop