NopCommerce 4.3 extend model and use it in child theme view

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 anni tempo fa
How to extend model and use it in child theme view?
3 anni tempo fa
Hi Gatisc,

Completely possible. Can you elaborate a little on your requirement. Do you want a plugin solution, so not to touch nop source code, or looking to modify the nopCommerce source code for minor model additions?  

When you say 'extend model', does this require to store new data in database?

gatisc wrote:
How to extend model and use it in child theme view?
3 anni tempo fa
Thank You for quick response! No I don't need to store data in data base. I need to develop a plugin for my new child theme, which can pass another model, not ProductOverviewModel but my xxxxxxProductOverviewModel, where xxxxxx name of my child theme. I need to use This new model's fields like manufacturer. Name in _ProductBox.
3 anni tempo fa
if you don't already, download the VS template for a nop 4.3 plugin development. This will give you the structure for plugin

https://github.com/nopSolutions/nopCommerce-plugin-template-VS

I'm not experienced in theme development, but in nop the general flow for preparing a view is..

-Controller action calls service layer to get the Domain object(data)
-Controller action makes a call to Factory layer to prepare the view model, passing in the Domain object and returning a prepared model.
-Controller action returns the view, with prepared model.

So to follow nop patterns, you will need your own Service, Factory, in addition to your controllers/models/views.

Have a look at another plugin in the source code, for example Nop.Plugin.Shipping.FixedByWeightOrTotal

And also look at the front-end code in Nop.Web.Controllers to see how preparing the views hangs together





gatisc wrote:
Thank You for quick response! No I don't need to store data in data base. I need to develop a plugin for my new child theme, which can pass another model, not ProductOverviewModel but my xxxxxxProductOverviewModel, where xxxxxx name of my child theme. I need to use This new model's fields like manufacturer. Name in _ProductBox.
3 anni tempo fa
Actually I have made my own Factory and Controller which overrides the necessarry method. I have installed the plugin already. But, when I start the nopCommerce, it hits breakpoint in old controller. And _ProductBox view (cshtml) doesn't see my new class.
3 anni tempo fa
I see, ok. Hmm. On your DependencyRegistrar, try setting the Order  higher than 1 (maybe try 1001) - this should then 'win' against the Nop method

gatisc wrote:
Actually I have made my own Factory and Controller which overrides the necessarry method. I have installed the plugin already. But, when I start the nopCommerce, it hits breakpoint in old controller. And _ProductBox view (cshtml) doesn't see my new class.
3 anni tempo fa
Do I need to put this
builder.RegisterType<ArcaneProductController>().As<ProductController>().InstancePerLifetimeScope();
into DependencyRegistrar?
3 anni tempo fa
I'm not sure. I've never tried overriding a controller actually. Maybe someone else can comment?

gatisc wrote:
Do I need to put this
builder.RegisterType<ArcaneProductController>().As<ProductController>().InstancePerLifetimeScope();
into DependencyRegistrar?
3 anni tempo fa
Now it throws an exeption
DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'ArcaneThemePlus.Controllers.ArcaneProductController' can be invoked with the available services and parameters:
Cannot resolve parameter 'ArcaneThemePlus.Factories.ArcaneProductModelFactory productModelFactory' of constructor 'Void .ctor(Nop.Core.Domain.Security.CaptchaSettings, Nop.Core.Domain.Catalog.CatalogSettings, Nop.Services.Security.IAclService, Nop.Services.Catalog.ICompareProductsService, Nop.Services.Logging.ICustomerActivityService, Nop.Services.Customers.ICustomerService, Nop.Services.Events.IEventPublisher, Nop.Services.Localization.ILocalizationService, Nop.Services.Orders.IOrderService, Nop.Services.Security.IPermissionService, Nop.Services.Catalog.IProductAttributeParser, ArcaneThemePlus.Factories.ArcaneProductModelFactory, Nop.Services.Catalog.IProductService, Nop.Services.Catalog.IRecentlyViewedProductsService, Nop.Services.Catalog.IReviewTypeService, Nop.Web.Factories.IShoppingCartModelFactory, Nop.Services.Orders.IShoppingCartService, Nop.Core.IStoreContext, Nop.Services.Stores.IStoreMappingService, Nop.Services.Seo.IUrlRecordService, Nop.Core.IWebHelper, Nop.Core.IWorkContext, Nop.Services.Messages.IWorkflowMessageService, Nop.Core.Domain.Localization.LocalizationSettings, Nop.Core.Domain.Orders.ShoppingCartSettings)'.
3 anni tempo fa
Did you also register your ArcaneProductModelFactory as productModelFactory?
(it should probably be IProductModelFactory)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.