lintho wrote:As of now, it seems that the attributes for product specifications cannot be grouped.
It would be nice to assign some grouping to these spec attributes instead of displaying a long list.
For example, car specs being grouped as Exterior, Interior, Mechanical, Electrical, etc.
I just tried to add a column SpecificationType... unfortunately I am not able to have these multiple partial views render correctly on the page by passing in a SpecificationType parameter. Perhaps caching issue? It just repeats the first specified specification type even though the parameter is working/filtering.
I ended up with the follwing ProductSpesifications.cshtml view. Correct me if this isnt what you wanted. I did notice the age of the post, and you might have found a better solution.
@model IList<ProductSpecificationModel>
@using Nop.Web.Models.Catalog;
@if (Model.Count > 0)
{
<div class="product-specs-box">
<div class="title">
<strong>@T("Products.Specs")</strong>
</div>
<table class="data-table">
<colgroup>
<col width="25%" />
<col />
</colgroup>
<tbody>
@foreach (var attr in Model.GroupBy(o => o.SpecificationAttributeId))
{
<tr>
<td class="a-left spec-name">
@attr.FirstOrDefault().SpecificationAttributeName
</td>
<td class="a-left spec-value">
@foreach (var attrOp in attr.Take(attr.Count()-1))
{
@attrOp.SpecificationAttributeOption<text>,</text>
}
@foreach (var attrOp in attr.Skip(attr.Count()-1).Take(1))
{
@attrOp.SpecificationAttributeOption
}
</td>
</tr>
}
</tbody>
</table>
</div>
}
Hi there,
Just to add on to the topic, I refactored lintho's code to make it shorter.
....... snippet.......
@foreach (var attr in Model.GroupBy(o => o.SpecificationAttributeId))
{
var attrValues = String.Join(", ", attr.Select(x => x.SpecificationAttributeOption).ToArray());
<tr>
<td class="a-left spec-name">
@attr.FirstOrDefault().SpecificationAttributeName
</td>
<td class="a-left spec-value">
@attrValues
</td>
</tr>
}
....... snippet.......
Also, if you make this change, you might also want to do the same thing for the compare product view. (CompareProducts.cshtml)
......snippet......
@foreach (var specificationAttribute in specificationAttributes)
{
<tr class="specification">
<td>@specificationAttribute.SpecificationAttributeName
</td>
@foreach (var product in Model.Products)
{
var specValue = string.Empty;
var foundProductSpec = product.SpecificationAttributeModels.FirstOrDefault(psa => psa.SpecificationAttributeId == specificationAttribute.SpecificationAttributeId);
if (foundProductSpec != null)
{
var specValues = product.SpecificationAttributeModels.Where(o =>o.SpecificationAttributeId == foundProductSpec.SpecificationAttributeId)
.Select(x=>x.SpecificationAttributeOption).ToList();
// concat string with delimiter
specValue = String.Join(", ", specValues.ToArray());
}
<td style="width: @columnWidth;" class="a-center">
@if (!String.IsNullOrEmpty(specValue))
{
@specValue
}
else
{
<text> </text>
}
</td>
}
</tr>
}
.....snippet.....