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 @@ -