Product Reviews

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi all,
This is more of a learning question for me (I'm new to MVC) to work out the best and most maintainable way to change the layout of a page with nop 2.1, in this instance; the way product reviews are rendered.
I'm trying to put the product reviews on the product page.
In my theme folder I've copied and altered the Product.cshtml page and I've added
@Html.Action("ProductReviews", "Catalog", new { productId = Model.Id})
into the spot that I want the reviews rendered. This obviously renders the whole Product review page, which I want to continue to be able to use separately) so I need to strip it back to just the list of reviews without the layout, creation section.
I've done that and it works except then the Product review separate page obviously doesn't work properly.
Should I create another View called ProductReviewsList.cshtml and call like this:
@Html.Action("ProductReviewsList", "Catalog", new { productId = Model.Id})
I then would need to alter the CatalogController.cs to include the ProductReviewsList action and I read on Skyler's cheat sheet that altering these classes is a bad idea maintenance wise.

Another approach I could take is adding a List<ProductReview> to the Product Model and then do a partial view for the review list. Thoughts on that? Is that the same maintenance problem because I'm altering a nop class?

Any help is greatly appreciated.
Thanks,
Greg
12 years ago
gkennedy1 wrote:
Hi all,
This is more of a learning question for me (I'm new to MVC) to work out the best and most maintainable way to change the layout of a page with nop 2.1, in this instance; the way product reviews are rendered.
I'm trying to put the product reviews on the product page.
In my theme folder I've copied and altered the Product.cshtml page and I've added
@Html.Action("ProductReviews", "Catalog", new { productId = Model.Id})
into the spot that I want the reviews rendered. This obviously renders the whole Product review page, which I want to continue to be able to use separately) so I need to strip it back to just the list of reviews without the layout, creation section.
I've done that and it works except then the Product review separate page obviously doesn't work properly.
Should I create another View called ProductReviewsList.cshtml and call like this:
@Html.Action("ProductReviewsList", "Catalog", new { productId = Model.Id})
I then would need to alter the CatalogController.cs to include the ProductReviewsList action and I read on Skyler's cheat sheet that altering these classes is a bad idea maintenance wise.

Another approach I could take is adding a List<ProductReview> to the Product Model and then do a partial view for the review list. Thoughts on that? Is that the same maintenance problem because I'm altering a nop class?

Any help is greatly appreciated.
Thanks,
Greg


Hi Greg,

It isn't the end of the world if you modify a nopCommerce class. Inevitably there will be a scenario that requires a nopCommerce file to be changed; just limit the number of nopCommerce files you modify.

For example you could create a new controller with the new actions. Then you can override the existing product review views using a custom theme folder.

Using the example above the functionality is now upgrade resistant. You'll need to merge the project file with the next nopCommerce release, but that is just one file (instead of the controller, views, and models).

Let me know if you have any questions. Thanks for reading my blog!

http://blog.csharpwebdeveloper.com/2011/09/27/cheat-sheet-for-effectively-extending-nopcommerce/
12 years ago
Great, Thanks Skyler. I changed the nop CatalogController to a partial class and added to it that way.
Keep blogging, your commentary is very helpful.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.