From b413a0bfcc3ed996cd43e3b1ad4071fbd4b1e99e Mon Sep 17 00:00:00 2001 From: Dmitriy Benyuk Date: Thu, 22 May 2025 14:18:26 +0300 Subject: [PATCH] Changing primary variant dont show correct price --- ...Ecommerce.DynamicwebLiveIntegration.csproj | 2 +- .../Products/ProductManager.cs | 19 ++++--------------- .../Products/ProductPriceProvider.cs | 11 +++++++---- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj index c08430a..ab90bce 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.23 + 10.4.24 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 7ce4ca8..9e7b6b0 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs @@ -281,6 +281,7 @@ private static List GetProductsForRequest(Settings settin // Check for existence of the given products in the Cache List productsForRequest = new List(); bool getProductInformationForAllVariants = settings.GetProductInformationForAllVariants; + bool showVariantDefault = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Ecom/Product/ShowVariantDefault"); foreach (var productWithQuantity in products) { @@ -317,24 +318,12 @@ private static List GetProductsForRequest(Settings settin } } } - else + + if (showVariantDefault) { - if (!string.IsNullOrEmpty(product.VariantId) && !string.IsNullOrEmpty(product.DefaultVariantComboId) && !string.Equals(product.VariantId, product.DefaultVariantComboId) - && GetFilteredVariants(new List() { product }).Count != 0) - { - productIdentifier = ProductProvider.GetProductIdentifier(settings, product, productWithQuantity.UnitId); - if (!ResponseCache.IsProductInCache(productCacheLevel, productIdentifier, context.User, doCurrencyCheck ? context.Currency : null)) - { - if (ProductProvider.IsLivePriceEnabledForProduct(product) && product.HasIdentifier(settings)) - { - productsForRequest.Add(product.GetPriceProductSelection(productWithQuantity.Quantity, productWithQuantity.UnitId)); - } - } - } + product = ProductProvider.GetProductFromVariantComboId(product, logger); } - product = ProductProvider.GetProductFromVariantComboId(product, logger); - if (string.IsNullOrEmpty(product.VariantId) || GetFilteredVariants(new List() { product }).Count != 0) { productIdentifier = ProductProvider.GetProductIdentifier(settings, product, productWithQuantity.UnitId); diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductPriceProvider.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductPriceProvider.cs index 32eb255..313bd85 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductPriceProvider.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductPriceProvider.cs @@ -1,4 +1,5 @@ -using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Cache; +using Dynamicweb.Configuration; +using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Cache; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Connectors; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Extensions; @@ -30,10 +31,12 @@ public class ProductPriceProvider : PriceProvider, IPriceInfoProvider List products = new List(); - Product changedProduct = ProductManager.ProductProvider.GetProductFromVariantComboId(product.Product, logger); - products.Add(changedProduct.GetPriceProductSelection(product.Quantity, product.UnitId)); + bool showVariantDefault = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Ecom/Product/ShowVariantDefault"); + + Product productForRequest = showVariantDefault ? ProductManager.ProductProvider.GetProductFromVariantComboId(product.Product, logger) : product.Product; + products.Add(productForRequest.GetPriceProductSelection(product.Quantity, product.UnitId)); // After GetProductFromVariantComboId the variantId is empty or other product is returned so new identifier must be generated - productIdentifier = ProductManager.ProductProvider.GetProductIdentifier(settings, changedProduct, product.UnitId); + productIdentifier = ProductManager.ProductProvider.GetProductIdentifier(settings, productForRequest, product.UnitId); bool fetchedProductInfo = ProductManager.FetchProductInfos(products, context, settings, logger, true, SubmitType.Live); if (fetchedProductInfo &&