From 58f50941b44747fd9224cdd8f46193236b490cf9 Mon Sep 17 00:00:00 2001 From: Dmitriy Benyuk Date: Thu, 3 Jul 2025 10:23:51 +0300 Subject: [PATCH] Fix duplicate requests for non existing products --- .../Cache/ResponseCache.cs | 1 + ...amicweb.Ecommerce.DynamicwebLiveIntegration.csproj | 2 +- .../Products/ProductManager.cs | 11 +++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Cache/ResponseCache.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Cache/ResponseCache.cs index 50ca201..096ae4a 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Cache/ResponseCache.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Cache/ResponseCache.cs @@ -205,6 +205,7 @@ public static bool IsProductInCache(ResponseCacheLevel productCacheLevel, string if (cachedProductInfo.TryGetValue(productIdentifier, out var productInfo)) { + if (productInfo is null) return true; return Equals(currency.Code, productInfo["CurrencyCode"]); } } diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj index f3646fa..6888e21 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj @@ -1,6 +1,6 @@  - 10.4.26 + 10.4.27 1.0.0.0 Live Integration Live Integration diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs index 9e7b6b0..8286d38 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs @@ -212,7 +212,7 @@ private static bool FetchProductInfosInternal(List produc // Parse the response Dictionary prices = ProcessResponse(settings, response, logger, context); - if (prices != null && prices.Count > 0) + if (prices != null) { if (updateCache) { @@ -225,7 +225,14 @@ private static bool FetchProductInfosInternal(List produc cachedProductInfos.Remove(productKey); cachedProductInfos.Add(productKey, prices[productKey]); } - } + // Cache empty values for products that were in the request but were not returned in the response + + foreach (var priceProductSelection in productsForRequest) + { + var productIdentifier = ProductProvider.GetProductIdentifier(settings, priceProductSelection.Product, priceProductSelection.UnitId); + cachedProductInfos.TryAdd(productIdentifier, null); + } + } } } else