How to override View on Nop 4.20

Posted: July 05, 2019 at 6:17 AM Quote #242189
Hello community. I'm quiet new to Nop and i'm trying to make my first plugin on 4.20. I want to change Product/_AddToCart view. I already include new view in plugin, write new functionality on that page, but now i'm struggle to override Nop view with my plugin view. Thanks in advance!
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: July 08, 2019 at 2:14 PM Quote #242264
Hello, jomhur

I think you want to go to "Presentation\Nop.Web\Views\Product" and search for "ProductTemplate.Simple.cshtml" and "ProductTemplate.Grouped.cshtml".
In both cshtml file, you will find "@await Html.PartialAsync("_AddToCart", variant.AddToCart, dataDictAddToCart)".

If you want to replace the view, you can replace that line with your view component.

if you are creating a "IWidgetPlugin" you can call your view component like this:

"@await Component.InvokeAsync("Widget", new { widgetZone = PublicWidgetZones.HomepageTop })"

Just replace the "PublicWidgetZones.HomepageTop" with your WidgetZone Name.

I hope it will help you. Thank You.
This post/answer is useful
-1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: July 11, 2019 at 7:26 AM Quote #242425
jomhur wrote:
Hello community. I'm quiet new to Nop and i'm trying to make my first plugin on 4.20. I want to change Product/_AddToCart view. I already include new view in plugin, write new functionality on that page, but now i'm struggle to override Nop view with my plugin view. Thanks in advance!


You can use View location expander - IViewLocationExpander for override view from plugin.

Get a reference from - nopCommerce > Presentation > Nop.Web.Framework > Themes > ThemeableViewLocationExpander.cs

Hope this would be helpful.
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)
Up-vote the answer, if it helps you! :)


Thank You
Raju Paladiya
-------------------------------------------------------
nopAccelerate - Faster, Reliable & Scalable nopCommerce

sales(at)nopaccelerate.com
http://www.nopAccelerate.com | http://www.xcellence-it.com
Posted: July 11, 2019 at 9:55 PM Quote #242451
Hi,

If you write 1 Plugin and want to overwrite the file in the View folder. You need to do the following: Add 2 files to your Plugin's Infrastructure folder.



Infrastructure / HomepageCategoriesViewEngine.cs
Infrastructure / NopStartup.cs


--------------NopStartup.cs-------------
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Infrastructure;

namespace Nop.Plugin.Components.HomepageCategories.Infrasctructure
{
    /// <summary>
    /// Represents object for the configuring services on application startup
    /// </summary>
    public class NopStartup : INopStartup
    {
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new HomepageCategoriesViewEngine());
            });
        }

        /// <summary>
        /// Configure the using of added middleware
        /// </summary>
        /// <param name="application">Builder for configuring an application's request pipeline</param>
        public void Configure(IApplicationBuilder application)
        {
        }

        /// <summary>
        /// Gets order of this startup configuration implementation
        /// </summary>
        public int Order => int.MaxValue;
    }
}

-----------HomepageCategoriesViewEngine.cs-----------

using Microsoft.AspNetCore.Mvc.Razor;
using System.Collections.Generic;
using System.Linq;

namespace Nop.Plugin.Components.HomepageCategories.Infrasctructure
{
  public class HomepageCategoriesViewEngine : IViewLocationExpander
  {
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
            if (context.AreaName == null && context.ViewName == "Components/HomepageCategories/Default")
            {
                viewLocations = new[] { "/Plugins/Components.HomepageCategories/Views/PublicInfo.cshtml" }.Concat(viewLocations);
            }

            return viewLocations;
        }

    public void PopulateValues(ViewLocationExpanderContext context)
    {
    }
  }
}

Hope to help you!
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Plugin Dynamic Form for nopCommerce (Plugin Contact Form Nopcommerce): http://nopplugin.com/dynamic-form-nopcommerce

Nopcommerce Amp Plugin: http://nopplugin.com/google-accelerated-mobile-for-nopcommerce

Nopcommerce Multi Tenant: http://nopplugin.com/nopcommerce-multi-tenant-download
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