Posted on 04/05/2020 08:37:29
Hello Aki Ruuskanen
I think you can use this sample to get product properties and their values.
public class ProductCategoryPropertyHelper
{
public Dictionary<ProductField, object> GetAllProprtiesValues(string productId, string variantId, string languageId)
{
var result = new Dictionary<ProductField, object>();
var product = Dynamicweb.Ecommerce.Services.Products.GetProductById(productId, variantId, languageId);
var productProperties = GetProductProperties(product);
foreach (var field in productProperties)
{
var propValue = Dynamicweb.Ecommerce.Services.Products.GetFieldValue(product, field);
if (propValue.Succeeded && propValue.Data != null)
{
result.Add(field, propValue.Data);
}
}
return result;
}
private IEnumerable<ProductField> GetProductProperties(Product product)
{
var productPropertyCategories = Dynamicweb.Ecommerce.Services.ProductCategories
.GetCategories(product, true)
.Where((category) => category.CategoryType == Dynamicweb.Ecommerce.Products.Categories.CategoryType.PropertyFields);
var propertyFieldsCategories = productPropertyCategories
.SelectMany(category => category.Fields)
.Select(field => $"ProductCategory|{field.Category.Id}|{field.Id}");
var systemNamesIdx = new HashSet<string>(propertyFieldsCategories);
var result = ProductField.GetCategoryFields().Where(field => systemNamesIdx.Contains(field.SystemName)).ToList();
return result;
}
}
BR, Alexander