Developer forum

Forum » Integration » Trouble accessing ERP custom fields (Recommended_quantity & Recommended_quantity_price) in Dynamicweb

Trouble accessing ERP custom fields (Recommended_quantity & Recommended_quantity_price) in Dynamicweb

Alex Guo
Reply

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



<item table="EcomProducts">
      <column columnName="ProductId"><![CDATA[03031011]]></column>
      <column columnName="ProductVariantId"><![CDATA[VARGRP67_03031011]]></column>
      <column columnName="ProductIdentifier"><![CDATA[03031011.VARGRP67_03031011.NLB]]></column>
      <column columnName="ProductNumber"><![CDATA[03031011]]></column>
      <column columnName="ProductPrice"><![CDATA[1,024.75]]></column>
      <column columnName="ProductPriceWithVat"><![CDATA[1,239.94]]></column>
      <column columnName="ProductStock"><![CDATA[20]]></column>
      <column columnName="ProductCurrencyCode"><![CDATA[]]></column>
      <column columnName="Recommended_quantity"><![CDATA[1|2|4]]></column>
      <column columnName="Recommended_quantity_price"><![CDATA[1,024.75|994.00|973.51]]></column>
      <column columnName="Product_Gross_Price"><![CDATA[2,274.48]]></column>
      <column columnName="Product_BlanketOrder_Price"><![CDATA[0]]></column>
      <column columnName="Product_BlanketOrder_Number"><![CDATA[]]></column>
      <column columnName="ProductOutlet"><![CDATA[false]]></column>
    </item>




On the frontend, I tried debugging with Razor:

 

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

But the fields don’t show up — Recommended_quantity and Recommended_quantity_price always come back as 0.

✅ 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!


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Did you update your import mapping to include those fields? Depending in your setup, they may not get mapped automatically and you need to do that in the import job.

Imar

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Alex,
try to check if the values are in the database after the import (you can run the "select * from EcomProducts" query from the Settings -> Database -> Sql Firehose).
Maybe try to clear the Products services caches (if the data is in the db): System -> Developer -> Cache -> Service Caches
ProductFieldService
ProductService

Also you can check if the "Do not render" setting is not set:

and if the Product Fields are selected in the Product Catalog app settings:


BR, Dmitrij

 
Alex Guo
Reply

Thanks for the replies!

We actually had this working in our DW9 project, but now we’re upgrading it to a new DW10 project. I checked the DW9 project, and I don’t see any import mappings for these fields there either.

My colleague mentioned that the ERP values might not actually be stored in the DB, but only loaded temporarily - not sure if that’s the case?
Every time you navigate to a product the erp sends a request and response

I already checked the other suggestions (cache clearing, “Do not render” setting, Product Catalog app field selection), and everything looks correct on that side.

Ill try debugging some more and see what i can find

-----------------
I added debugging to the DLL and this is the result

Product: 03031049 (Variant: VARGRP67_03031049)  
Currency: EUR  

Raw data:  
- Quantities: "1|2|4"  
- Prices: "3,191.40|3,031.83|2,872.26"  

Parsed results:  
- Quantities → [1, 2, 4]  
- Prices → [3191.40, 3031.83, 2872.26]  

Formatted output:  
- Qty 1 → € 3.191,40  
- Qty 2 → € 3.031,83  
- Qty 4 → € 2.872,26  
or
[
    ("1", "€ 3.191,40"),
    ("2", "€ 3.031,83"),
    ("4", "€ 2.872,26")
]

Summary:  
- Processed items: 3  
- Keys available: ProductId, TotalPrice, TotalPriceWithVat, CurrencyCode, Stock, Prices, Recommended_quantity, Product_Gross_Price, Recommended_quantity_price  
- Product loaded: True  
- ProductInfo retrieved: True  


So the prices are correct. Maybe my frontend template is wrong then?
Which is weird because it works in DW9. I only updated the Template to work for DW10 and didn't change any other functions for the prices

 
Alex Guo
Reply

Update:

As you can see in the picture for some reason i cant get the prices and quantities outside the table, but in the table i do get the prices and quantities.
the thing is that i need them outside, at least the quantities

 

You must be logged in to post in the forum