Grouping Specification Attributes - Specification Type

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Guys actually he want to adjust all the specifications in group wise. for example in mobile
we arrange

General
   Brand    Samsung
   Model    Galaxy Note2

Camera
   Front Camera   4MP
   Back Camera   8MP

instead of

   Brand    Samsung
   Model    Galaxy Note2
   Front Camera   4MP
   Back Camera   8MP

Same problem I am also facing. Need solution over it
9 years ago
Hi,

The following snippet would produce.
Attribute Name: Attribute value1, Attribute value2, Attribute value3.


Hope this would help.



@{
                    var a = (
                                from cr in Model
                                group cr.SpecificationAttributeOption by cr.SpecificationAttributeName into abc
                                select new { SpecificationAttributeName = abc.Key, SpecificationAttributeOption = string.Join(",", abc.ToArray()) }
                            ).ToList();
                                
                }
                @for (int i = 0; i < a.Count(); i++)
                {
                    var item = a[i];
                    
                    <tr @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))>
                        <td class="a-left spec-name">
                            <strong>@item.SpecificationAttributeName </strong>
                        </td>
                        <td class="a-left spec-value">
                            <strong>&nbsp;:&nbsp;</strong>@item.SpecificationAttributeOption
                        </td>
                    </tr>
                }



Mick,
8 years ago
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>&nbsp;</text>
                                    }
                                </td>
                            }
                        </tr>                    
                    }
.....snippet.....


I repliced "specValue = String.Join(", ", specValues.ToArray());"
with "specValue = String.Join(Environment.NewLine, specValues.ToArray());"
But NewLine not work
I try <br> and \n but not work
8 years ago
Check this: https://www.nopcommerce.com/boards/t/38537/feature-request-categorized-specification.aspx
8 years ago
Tecnofin wrote:

thanks for answer but I want a solution.

I Problem with my code on "CompareProducts.cshtml" with nop-template theme
My Code Here :

 @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.ValueRaw).ToList();
                                    
                                    // concat string with delimiter
                                    specValue = String.Join(",", specValues.ToArray());                                    
                                  
                                }

                                <td style="width: @columnWidth;" class="a-center">
                                    @if (!String.IsNullOrEmpty(specValue))
                                    {
                                       @specValue
                                    }
                                    else
                                    {
                                        <text>&nbsp;</text>
                                    }
                                </td>
                            }
                        </tr>                    
                    }


I Have 2 problem :
1. The first specification give "&nbsp;"
2. I want to replice "," delimiter Instead of "<br>" or "\n" or other line break that worked
specValue = String.Join(",", specValues.ToArray()); 

replice with:
specValue = String.Join("\n", specValues.ToArray()); 


Can anyone help me?

Sory for my english if not good.
8 years ago
EbiPenMan wrote:
2. I want to replice "," delimiter Instead of "<br>" or "\n" or other line break that worked

Can anyone help me?

Make sure you're outputting the specValue as raw html otherwise it's going to escape your break tag:

@Html.Raw(specValue)
8 years ago
petemitch wrote:
2. I want to replice "," delimiter Instead of "<br>" or "\n" or other line break that worked

Can anyone help me?
Make sure you're outputting the specValue as raw html otherwise it's going to escape your break tag:

@Html.Raw(specValue)


Thank you very much. Solved
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.