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

Posted: March 07, 2015 at 6:24 PM Quote #141518
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
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: March 09, 2015 at 12:53 AM Quote #141555
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. :)
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Lam Woon Cherk
https://www.pronopcommerce.com

Looking to double your store's sale? Check out this plugin: http://bit.ly/2YVP8GT
(And no, it's not about putting more marketing money to get more traffics)

Sign up to my mailing list for tons of tips on nopCommerce: http://bit.ly/2fg5fMy
Posted: March 11, 2015 at 10:08 AM Quote #141676
Hi

Many thanks for your help worked great

Spire
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 08, 2015 at 4:04 AM Quote #143134
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 08, 2015 at 4:25 AM Quote #143135
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);
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 08, 2015 at 5:21 AM Quote #143138
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 08, 2015 at 5:30 AM Quote #143140
Hi

Yes that would work on the products, not sure about the import routine, as I have not played around with that.,
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 08, 2015 at 8:50 AM Quote #143152
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 post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2019
Learn more