ProductOverviewModel showing zero count for SpecificationAttributeModels

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
I'm trying to pull a specificationAttribute for products displayed on any category page and tried to reference (in razor):
@Model.SpecificationAttributeModels.Count

in the _ProductBox.cshtml page but the count is always zero (even though all the products have about 8 defined for each). The count should be returning 7 or 8 (depending on the product).

Somehow the specificationAttributes are never set in the ProductOverviewModel (even though it's defined).
Is there something I'm missing?

Thanks
8 years ago
This property is not prepared by default (for performance optimization). Open "Category" method of \Nop.Web\Controllers\CatalogController.cs. Find

model.Products = PrepareProductOverviewModels(products).ToList();


and replace with

model.Products = PrepareProductOverviewModels(products, prepareSpecificationAttributes: true).ToList();
8 years ago
That did the trick! Thank you!
2 years ago
You could also add a code-snippet to the Razor-Template to get a specification attribute(s) and cache it, e.g. in _ProductBox.cshtml:

var mySpec = cacheManager.Get($"Nop.pres.product.specs-{Model.Id}-mySpec", () => specificationAttributeService.GetProductSpecificationAttributes(Model.Id, 1234).FirstOrDefault()?.CustomValue);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.