Getting the value of a custom field
To get the value of a custom field for a specific product, you must perform the following:
- Get the catalog manager.
Get an instance of the CatalogManager object.
- Get the specified product.
Get an instance of the product with the specified ID. For more information, see Querying products.
- Get the value of the field.
To set the value of the field you must call the GetValue method of the product instance. Pass the name of the field as an argument.
Here is a code example:
public static object GetCustomFieldValue(Guid productId, string customFieldName)
{
CatalogManager catalogManager = CatalogManager.GetManager();
Product product = catalogManager.GetProduct(productId);
if (product == null)
{
return null; // Product does not exist
}
return product.GetValue(customFieldName);
}