Is there a way to Access Product Generic Atributes in a view ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hi

I have added a Generic Attribute to some products, but I am struggling to access the Generic attribute in a view.

I have no problem accessing  Generic Attributes in controllers, but I don't want  modify the core, i want to create a custom view and access the Generic Attributes form the view.

Is this possible?, and if so some sample code would be great.

Thanks
9 years ago
Spire wrote:
Hi

I have added a Generic Attribute to some products, but I am struggling to access the Generic attribute in a view.

I have no problem accessing  Generic Attributes in controllers, but I don't want  modify the core, i want to create a custom view and access the Generic Attributes form the view.

Is this possible?, and if so some sample code would be great.

Thanks


@using Nop.Services.Common;
@using Nop.Core.Infrastructure;

@{
    var genericAttributeService = EngineContext.Current.Resolve<IGenericAttributeService>();
    var attributes = genericAttributeService.GetAttributesForEntity(Model.ProductId, "Product");
}


This gives you a list of attributes related to that product. You need to further locate the actual attribute you want to get. :)
9 years ago
Hi

Many thanks for your help worked great

Spire
9 years ago
Spire wrote:
Hi

I have added a Generic Attribute to some products, but I am struggling to access the Generic attribute in a view.

I have no problem accessing  Generic Attributes in controllers, but I don't want  modify the core, i want to create a custom view and access the Generic Attributes form the view.

Is this possible?, and if so some sample code would be great.

Thanks



How do you add a generic attribute? I want to add a new value to display for eg pack size in product details page. How can i do it?
9 years ago
Hi

Well in my case I wanted to display a youtube video on the product details page but not on all products, so I created a plugin that added a video tab in the admin section of the products where I could add the youtube url link in a product generic attribute.

Then when the product has a video I create a video tab on the product details page in the public store.


var product = _productService.GetProductById(id);
_genericAttributeService.SaveAttribute<string>(product, Constants.ProductVideoUrlAttribute, productVideoUrl);
9 years ago
Spire wrote:
Hi

Well in my case I wanted to display a youtube video on the product details page but not on all products, so I created a plugin that added a video tab in the admin section of the products where I could add the youtube url link in a product generic attribute.

Then when the product has a video I create a video tab on the product details page in the public store.


var product = _productService.GetProductById(id);
_genericAttributeService.SaveAttribute<string>(product, Constants.ProductVideoUrlAttribute, productVideoUrl);


I'm using nopcommerce 3.4 version. I want to display inner and outer pack size, cant i insert into specification attribute?
We used import routines to import products in database. Would it be correct to insert into specification attribute during product import?
9 years ago
Hi

Yes that would work on the products, not sure about the import routine, as I have not played around with that.,
9 years ago
wooncherk wrote:
Hi

I have added a Generic Attribute to some products, but I am struggling to access the Generic attribute in a view.

I have no problem accessing  Generic Attributes in controllers, but I don't want  modify the core, i want to create a custom view and access the Generic Attributes form the view.

Is this possible?, and if so some sample code would be great.

Thanks

@using Nop.Services.Common;
@using Nop.Core.Infrastructure;

@{
    var genericAttributeService = EngineContext.Current.Resolve<IGenericAttributeService>();
    var attributes = genericAttributeService.GetAttributesForEntity(Model.ProductId, "Product");
}


This gives you a list of attributes related to that product. You need to further locate the actual attribute you want to get. :)



I want to have Specification attribute on a view, say product box for some reason. Hoe can it be done. Not able to use enginecontext as it is not registered
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.