From 2a3153af09fb22c34a2a4c0458eabe44f5f69062 Mon Sep 17 00:00:00 2001 From: Dmitriy Benyuk Date: Fri, 26 Jun 2026 13:32:54 +0300 Subject: [PATCH 1/2] Add UpdateProductInViewModel --- ...Ecommerce.DynamicwebLiveIntegration.csproj | 2 +- .../Products/ProductProviderBase.cs | 2 +- .../TemplatesHelper.cs | 47 +++++++++++++++++-- .../XmlGenerators/ProductInfoXmlGenerator.cs | 2 +- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj index 792b6a2..c5a7b99 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj @@ -1,6 +1,6 @@  - 10.21.6 + 10.21.7 1.0.0.0 Live Integration Live Integration diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductProviderBase.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductProviderBase.cs index 8245bf6..25caa8b 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductProviderBase.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductProviderBase.cs @@ -169,7 +169,7 @@ public virtual void FillProductValues(ProductInfo productInfo, Product product, productPrice.PriceWithVAT = price.PriceWithVAT; // Update Product Custom Fields - if (settings.AddProductFieldsToRequest && product.ProductFieldValues.Count > 0) + if (settings.AddProductFieldsToRequest) { FillProductFieldValues(product, productInfo); } diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs index 1ee6f22..29fbc9e 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs @@ -1,7 +1,10 @@ -using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration; +using Dynamicweb.Configuration; +using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Connectors; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Extensions; +using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products; using Dynamicweb.Ecommerce.Orders; +using Dynamicweb.Ecommerce.ProductCatalog; using Dynamicweb.Ecommerce.Products; using System; using System.Collections.Generic; @@ -102,7 +105,7 @@ public static bool UpdateProduct(Product product, double quantity, string curren var productSelection = product.GetPriceProductSelection(1, null); var context = new LiveContext(Services.Currencies.GetCurrency(currencyCode), Helpers.GetCurrentExtranetUser(), Services.Shops.GetShop(shopId)); return Products.ProductManager.FetchProductInfos( - new List(){ productSelection }, + new List() { productSelection }, context, settings, new Logging.Logger(settings), false, SubmitType.Live, updateCache); } @@ -122,6 +125,44 @@ public static bool IsLazyLoadingForProductInfoEnabled && (user == null || !user.IsLiveIntegrationPricesDisabled()) && settings.LazyLoadProductInfo; } - } + } + + /// + /// Updates the product fields in the specified product view model with live information from the ERP. + /// + /// The product view model. + public static void UpdateProductInViewModel(ProductViewModel product) + { + var shopId = Global.CurrentShopId; + var settings = SettingsManager.GetSettingsByShop(shopId); + if (settings == null) + return; + + var user = Helpers.GetCurrentExtranetUser(); + var loadedProduct = Services.Products.GetProductById(product.Id, product.VariantId, product.LanguageId); + if (loadedProduct == null || !Helpers.CanCheckPrice(settings, loadedProduct, user)) + return; + + var logger = new Logging.Logger(settings); + bool showVariantDefault = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Ecom/Product/ShowVariantDefault"); + var productForRequest = showVariantDefault ? ProductManager.ProductProvider.GetProductFromVariantComboId(loadedProduct, logger) : loadedProduct; + var context = new LiveContext(Helpers.GetCurrentCurrency(), user, null); + string unitId = settings.UseUnitPrices ? productForRequest.DefaultUnitId : null; + var productSelection = productForRequest.GetPriceProductSelection(1, unitId); + + var productInfo = ProductManager.GetProductInfo(productForRequest, settings, user); + if (productInfo == null) + { + if (!ProductManager.FetchProductInfos([productSelection], context, settings, logger, false, SubmitType.Live, true)) + return; + + productInfo = ProductManager.GetProductInfo(productForRequest, settings, user); + } + + if (productInfo == null) + return; + + ProductManager.ProductProvider.FillProductValues(productInfo, loadedProduct, settings, productSelection.Quantity, context); + } } } \ No newline at end of file diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/XmlGenerators/ProductInfoXmlGenerator.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/XmlGenerators/ProductInfoXmlGenerator.cs index 86ae5b8..1f792a8 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/XmlGenerators/ProductInfoXmlGenerator.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/XmlGenerators/ProductInfoXmlGenerator.cs @@ -100,7 +100,7 @@ private XmlNode BuildProductInfoXml(Settings currentSettings, XmlDocument xmlDoc AddChildXmlNode(itemNode, "CurrencyCode", currencyCode); AddChildXmlNode(itemNode, "Quantity", productWithQuantity.Quantity.ToIntegrationString(currentSettings, logger)); - if (settings.AddProductFieldsToRequest && product.ProductFieldValues.Count > 0) + if (settings.AddProductFieldsToRequest) { AppendProductFields(currentSettings, product, itemNode, logger); } From c2b90f7b16b2cde85f701e7950fb53000b004495 Mon Sep 17 00:00:00 2001 From: Dmitriy Benyuk Date: Tue, 30 Jun 2026 11:02:12 +0300 Subject: [PATCH 2/2] fix null ref exception --- .../TemplatesHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs index 29fbc9e..d32b0ac 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/TemplatesHelper.cs @@ -146,6 +146,8 @@ public static void UpdateProductInViewModel(ProductViewModel product) var logger = new Logging.Logger(settings); bool showVariantDefault = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Ecom/Product/ShowVariantDefault"); var productForRequest = showVariantDefault ? ProductManager.ProductProvider.GetProductFromVariantComboId(loadedProduct, logger) : loadedProduct; + productForRequest = productForRequest ?? loadedProduct; + var context = new LiveContext(Helpers.GetCurrentCurrency(), user, null); string unitId = settings.UseUnitPrices ? productForRequest.DefaultUnitId : null; var productSelection = productForRequest.GetPriceProductSelection(1, unitId);