Hi everyone,
(sorry the formatting isnt exactly great, i will update it soon so its more readable)
I’m working on integrating ERP product data into Dynamicweb, and I’m running into an issue with two specific fields:
-
Recommended_quantity -
Recommended_quantity_price
I’ve already created global custom fields with those names, and the data is present in the import XML. Here’s an example snippet
<!-- DEBUG OUTPUT - TESTING DIRECT ACCESS -->
<div style="background: #f0f0f0; padding: 10px; margin: 10px 0; border: 1px solid #ccc; font-family: monospace; font-size: 12px;">
<strong>DIRECT FIELD ACCESS TEST:</strong><br/>
@foreach (var product in productList.Take(3)) // Only test first 3 products
{
<div><strong>Product @product.Number (@product.Name):</strong></div>
@* Test direct field access *@
@if (product.ProductFields != null)
{
<div>ProductFields count: @product.ProductFields.Count</div>
@* Look for recommended quantity fields *@
@foreach (var field in product.ProductFields)
{
<div>Field '@field.Key': '@field.Value?.Value?.ToString()'</div>
}
@* Try specific field names *@
var recQtyField = product.ProductFields.FirstOrDefault(x => x.Key == "Recommended_quantity");
var recPriceField = product.ProductFields.FirstOrDefault(x => x.Key == "Recommended_quantity_price");
<div>Recommended_quantity field: @(recQtyField.Key != null ? $"'{recQtyField.Value?.Value?.ToString()}'" : "NOT FOUND")</div>
<div>Recommended_quantity_price field: @(recPriceField.Key != null ? $"'{recPriceField.Value?.Value?.ToString()}'" : "NOT FOUND")</div>
@* If found, try to parse them *@
@if (recQtyField.Key != null && recPriceField.Key != null)
{
string quantities = recQtyField.Value?.Value?.ToString() ?? "";
string prices = recPriceField.Value?.Value?.ToString() ?? "";
<div>Raw quantities: '@quantities'</div>
<div>Raw prices: '@prices'</div>
if (!string.IsNullOrEmpty(quantities) && !string.IsNullOrEmpty(prices))
{
string[] qtyArray = quantities.Split('|');
string[] priceArray = prices.Split('|');
<div>Parsed quantities: [@string.Join(", ", qtyArray)]</div>
<div>Parsed prices: [@string.Join(", ", priceArray)]</div>
if (qtyArray.Length == priceArray.Length)
{
for (int i = 0; i < qtyArray.Length; i++)
{
<div>Quantity @qtyArray[i] = Price @priceArray[i]</div>
}
}
}
}
}
else
{
<div>ProductFields is NULL</div>
}
<div>---</div>
}
</div>
<!-- END DEBUG OUTPUT -->
✅ Things I’ve already checked:
-
Global custom fields exist in Dynamicweb with the exact same names.
-
Data is definitely being imported (I can see it in the XML).
-
Other custom fields are accessible via
ProductFields.
❓ My question:
-
Is there something special I need to configure in Dynamicweb for ERP-imported custom fields to show up in
ProductFields?
Or do these fields need to be linked/mapped differently in order to be available at runtime?
We actually have more code kinda like this in a dll to return the prices
public static string GetRecommendedQuantityPricesFormatted(this Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel productViewModel, PageView pageView)
{
string rgqpFormatted = string.Empty;
try
{
Product product = Services.Products.GetProductById(productViewModel.Id, productViewModel.VariantId, productViewModel.LanguageId);
Settings settings = SettingsManager.GetSettingsByShop(PageView.Current().Area.EcomShopId);
if (pageView.User != null)
{
ProductInfo productInfo = ProductManager.GetProductInfo(product, settings, pageView.User);
if (productInfo != null && productInfo.ContainsKey("Recommended_quantity_price"))
{
var recommendedQuantityPrices = productInfo["Recommended_quantity_price"]?.ToString();
if (!string.IsNullOrEmpty(recommendedQuantityPrices))
{
var prices = recommendedQuantityPrices.Split('|');
Currency currency = Dynamicweb.Ecommerce.Common.Context.Currency;
var formattedPrices = prices
.Select(price =>
{
if (double.TryParse(price, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out double parsedPrice))
{
return Services.Currencies.Format(currency, parsedPrice);
}
return string.Empty;
})
.Where(formattedPrice => !string.IsNullOrEmpty(formattedPrice))
.ToList();
rgqpFormatted = string.Join("| ", formattedPrices);
}
}
}
}
catch (Exception ex)
{
LogManager.System.GetLogger("CustomCode", "Helpers").Error($"Error getting Recommended Quantity Prices", ex);
}
return rgqpFormatted;
}
Any pointers or best practices would be greatly appreciated!