Developer forum

Forum » Ecommerce - Standard features » Display of the main fields of a product

Display of the main fields of a product

Tomas Gomez
Reply

Hi,

In the product page, we want to display a brief selection of the main fields of the product, according its product group (e.g. field1 and field2 for bikes, while field3 and field4 for wheels). The fields can be product fields, product group fields, or category fields. 

The problem is how to dynamically configure which are the main fields. That is, where and how the webpage editor can add/sort/remove the fields that are going to be displayed for a certain product group.

The best option would be in the Product group edition. We implemented a custom ProductFieldTypeProvider to display a control to select the fields, but all the fields of the datase are shown (there are hundreds of fields) because the ProductFieldTypeProvider doesn't know about the product group (see here).

Another option would be to create a new page in the frontend with the Product group hierarchy and one selector for each group. Each selector would contain only the fields belonging to its group.

We feel there should be an easier way to do this, as it is a quite standard feature to have this selection of fields as the short description of a product.

Any suggestion?

BR
Tomas


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Tomas,

 

We are exploring the "Field Display Groups" for that. Here's how we're doing it:

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply
This post has been marked as an answer

Hi guys,

"Field Display Groups should be the way to do it. My understanding is that this functionality is still under development. Probably a new API will be implemented at some point.

Prior to "Fields DisplayGroups" we have used a convention instead. We have added prefixes to system names of the fields and we have used those prefixes to list them.

But if you already have the fields and you have hundreds of them, it's not an ideal approach to redefine your fields. Nuno's solution might be the best bet, assuming you will be able to change the approach once the new API will be implemented.

Adrian

Votes for this answer: 1
 
Tomas Gomez
Reply

Thank you, guys :-)

Yes, the field display groups should be the best option, but couldn't get how to operate them. If you get it, Nuno, please let me know, I'll check it.

Meanwhile we finished the ProductFieldTypeProvider option. Actually, it's a good alternative when there are not so many fields. If you want to try the code let me know.

Regards,
Tomas

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Tomas,

 

Sorry about the long delay, but different responsabilities took me away from this. Here's the code (trimmed down) of what we used

 

@helper RenderProductSpecifications()
{
 
    var productService = Dynamicweb.Ecommerce.Services.Products;
    var productId = GetString("Ecom:Product.Number");
    var product = productService.GetProductByNumber(productId, Dynamicweb.Ecommerce.Common.Context.Language.LanguageId);
    //var variants = productService.GetProductsAndVariantsByProduct(product);
   // var variants = GetLoop("VariantCombinations");
    var group = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(GetString("Ecom:Product.PrimaryOrFirstGroupID"));
    var variants = group.Products.Where(p => string.Equals(p.Id, product.Id, StringComparison.OrdinalIgnoreCase) && !p.IsVariantMaster);
 
    var comparableFieldsFieldDisplayGroupId = Pageview.AreaSettings.GetItem("Custom").GetItem("CustomSettings").GetList("ComparableFields").SelectedValue;
    var specificationsFieldDisplayGroupId = Pageview.AreaSettings.GetItem("Custom").GetItem("CustomSettings").GetList("SpecificationsFields").SelectedValue;
    
    <section>
<div>
@getFieldDisplayGroupsMultiple(variants, Convert.ToInt32(comparableFieldsFieldDisplayGroupId))
</div>
<div>
@getFieldDisplayGroupsSingle(product, Convert.ToInt32(specificationsFieldDisplayGroupId))
</div>
    </section>
}
 
@helper getFieldDisplayGroupsMultiple(IEnumerable<Dynamicweb.Ecommerce.Products.Product> variants, int displayGroupId )
{
    var productCategoriesFields =  Dynamicweb.Ecommerce.Services.FieldDisplayGroups.GetById(displayGroupId).FieldIds.ToString();
    var groupName = Dynamicweb.Ecommerce.Services.FieldDisplayGroups.GetById(displayGroupId).Name;
    List<String> groupFields = new List<String>(productCategoriesFields.Split(",".ToCharArray()));
 
<div>@groupName</div>
<table>
<thead>
<tr>
<th></th>
@foreach(var variant in variants)
{
<th>@variant.Name</th>
}
</tr>
</thead>   
<tbody>
@foreach (var field in groupFields)
{
var categoryID = GetCategoryId(field);
var fieldID = GetFieldId(field);
<tr class="@hideRow @categoryID @fieldID dw-mod">
<td class="u-no-border-top u-border-bottom dw-mod">@GetCategoryName(field)</td>
@foreach (var variant in variants)
{
<td>@GetFieldDisplayValue(variant, field, categoryID, fieldID)</td>
}
</tr>
}
</tbody>
</table>
}
 
@helper getFieldDisplayGroupsSingle(Dynamicweb.Ecommerce.Products.Product product, int displayGroupId )
{
    var productCategoriesFields =  Dynamicweb.Ecommerce.Services.FieldDisplayGroups.GetById(displayGroupId).FieldIds.ToString();
    List<String> groupFields = new List<String>(productCategoriesFields.Split(",".ToCharArray()));
    
    foreach (var field in groupFields)
    {
        var categoryID = GetCategoryId(field);
        var fieldID = GetFieldId(field);
        var value = GetFieldDisplayValue(product, field, categoryID, fieldID);
 
        if (value.IsNotNullOrEmpty())
        {
            <div>
<div>@GetCategoryName(field)</div>
<div>@value.ToString()</div>
</div>
}
}
}

 

Hope if helps you,

Nuno Aguiar

Votes for this answer: 1
 
Tomas Gomez
Reply

Hi Nuno,

I forgot to thank you the code. We still use the ProductFieldTypeProvider option... but it is a question of time our client want to see the Field display groups in the Frontend, so thanks a lot!

Best regards,
Tomas

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Thomas,

 

You are welcome. We've perfected it in the meanwhile :P That version is not taking the proper field names/labels into consideration. Here's a new version (attached) "to share" in case other people need it. I am also expecting this to become available at some point in Dynamicweb. You just need to compile it (and potentially change the namespace).

 

The GetFieldValue is an extension of an object of type Product, and the GetFieldBySystemName returns an object of type ProductField, which you then can get the proper Name from it. All you still need is to get the FieldldDisplayGroupId to get it to work smiley

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Tomas Gomez
Reply

Good point to create those services! Thanks a lot!

BR Tomás

 

You must be logged in to post in the forum