Referencing a plugin from a theme in nopCommerce no longer working in 4.60

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 năm cách đây
We have this large solution built in nopCommerce where we have 2 plugins and one custom theme.

I'm currently upgrading from 4.3 to 4.6 which means changing everything to async in service references (in the plugin) along with some other braking changes.

Both plugins are now upgraded but I have issues in the theme where I no longer can reference classes from the plugins.

Below is a sample of how _CheckoutAttributes.cshtml is layed out. It's located in Nop.Web/Themes/ThemeName/Views/Shared.

I've changed some of the naming to "ProjectName" to keep privacy.

@using System.Text
@using Nop.Core.Domain.Catalog
@using Nop.Core.Domain.Media
@using Nop.Services.Media
@using Nop.Services.Orders
@using Nop.Core
@using Nop.Plugin.Misc.ProjectName.Services
@inject IDownloadService downloadService
@inject CatalogSettings catalogSettings
@inject ICheckoutAttributeService checkoutAttributeService
@inject IStoreContext _storeContext
@inject IProjectNameCheckoutAttributeService projectNameCheckoutAttributeService
@inject IWebHelper _webHelper

@{
    var checkoutAttributes = projectNameCheckoutAttributeService.GetCheckoutAttributes();
}

<form method="post" enctype="multipart/form-data" id="checkout-attributes-form">

etc...


The error I get is The type or namespace name 'Plugin' does not exist in the namespace 'Nop' (are you missing an assembly reference?)

This used to work in nopCommerce 4.3 but no matter what I try now (clean, rebuild etc) it wont build.

In 4.3 the Intellisense actually gave the same error but the compilation of the project/solution still was successful.

Any input on how to solve this?

I've tried rebuilding, cleaning, restarting Visual Studio, keeping the cshtml files closed.

I've also tried referencing other standard plugins to see if it's a problem relating to only my plugins. But that also failed.

It seems like nopCommerce 4.6 or perhaps rather dot.net core 7 is more strict about being able to compile the razor files. Or perhaps it has something to do with Visual Studio?

I looked into if I can choose to only compile the razor files when loading them but can't seem to find a way to turn off building them at compile time.
1 năm cách đây
Do you need to add a reference in the _ViewImports.cshtml file
1 năm cách đây
Hi Yidna and thank you for your reply.

This does unfortunately not work as I get the same error.
1 năm cách đây
When I do this I copy the theme file above to my plugin directory Views
Then load it via Customer View Engine
1 năm cách đây
Thank you for the tip!

Do you know of any good online resource that explains how to setup a custom view engine in nopCommerce 4.6 or similar?
1 năm cách đây
There are a lot of posts about it the forum - here is some basic code


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

using Nop.Core;
using Nop.Core.Infrastructure;
using Nop.Services.Configuration;

using Nop.Web.Framework.Themes;
using Nop.Web.Framework;

namespace Nop.Plugin.Apollo.Appointments.ViewEngine
{
    public class CustomViewEngine : IViewLocationExpander
    {
        public string StoreTheme = "DefaultClean";

        public void PopulateValues(ViewLocationExpanderContext context)
        {
            //no need to add the themeable view locations at all as the administration should not be themeable anyway
            if (context.AreaName?.Equals(AreaNames.Admin) ?? false)
                return;

            var settingService = EngineContext.Current.Resolve<ISettingService>();
            var storeContext = EngineContext.Current.Resolve<IStoreContext>();

            StoreTheme = settingService.GetSettingByKeyAsync("storeinformationsettings.defaultstoretheme", "DefaultClean", storeContext.GetCurrentStore().Id, true).Result;

            context.Values[StoreTheme] = EngineContext.Current.Resolve<IThemeContext>().GetWorkingThemeNameAsync().Result;
        }

        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {

            if (context.AreaName == null)
            {
                if (!context.Values.TryGetValue(StoreTheme, out string? theme))
                    return viewLocations;

                if (context.ViewName == "_AddToCart" &&
                   (context.ControllerName == "Product" || context.ControllerName == "YourController"))
                {
                    viewLocations = new[] { $"~/Plugins/SSI.Plugin.Name/Views/FrontView/Shared/Themes/_AddToCart.cshtml" }.Concat(viewLocations);
                }

            }

            return viewLocations;
        }
    }
}


Add to the startup


        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<RazorViewEngineOptions>(o =>
            {
                o.ViewLocationExpanders.Add(new CustomViewEngine());
            });
        }
1 năm cách đây
Thank you for the example!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.