Custom Table for Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 лет назад
Hello,

I am developing a custom plugin for NOP.

I need a custom table that the plugin can use to store some data....

I have been following this step by step tutorial:

http://docs.nopcommerce.com/display/nc/Plugin+with+data+access

But, when I try and build my solution I get 4 errors which I don't understand.

I my ObjectContext it is reporting:

'Nop.Plugin.Misc.ChiliPublisher.Data.ChiliOrdersObjectContext' does not implement interface member 'Nop.Data.IDbContext.ProxyCreationEnabled'

'Nop.Plugin.Misc.ChiliPublisher.Data.ChiliOrdersObjectContext' does not implement interface member 'Nop.Data.IDbContext.Detach(object)'

'Nop.Plugin.Misc.ChiliPublisher.Data.ChiliOrdersObjectContext' does not implement interface member 'Nop.Data.IDbContext.AutoDetectChangesEnabled'

Here is my code:

using Nop.Core;
using Nop.Data;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Plugin.Misc.ChiliPublisher.Data {
  public class ChiliObjectContext : DbContext, IDbContext {
    public ChiliObjectContext(string nameOrConnectionString) : base(nameOrConnectionString) { }

    #region Implementation of IDbContext

    #endregion

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
      modelBuilder.Configurations.Add(new ChiliOrdersMap());

      base.OnModelCreating(modelBuilder);
    }

    public string CreateDatabaseInstallationScript() {
      return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
    }

    public void Install() {
      //It's required to set initializer to null (for SQL Server Compact).
      //otherwise, you'll get something like "The model backing the 'your context name' context has changed since the database was created. Consider using Code First Migrations to update the database"
      Database.SetInitializer<ChiliObjectContext>(null);

      Database.ExecuteSqlCommand(CreateDatabaseInstallationScript());
      SaveChanges();
    }

    public void Uninstall() {
      var dbScript = "DROP TABLE ChiliOrders";
      Database.ExecuteSqlCommand(dbScript);
      SaveChanges();
    }

    public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity {
      return base.Set<TEntity>();
    }

    public System.Collections.Generic.IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new() {
      throw new System.NotImplementedException();
    }

    public System.Collections.Generic.IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters) {
      throw new System.NotImplementedException();
    }

    public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters) {
      throw new System.NotImplementedException();
    }
  }

}


And in my DependencyRegistrar it is reporting an error of:

'Nop.Plugin.Misc.ChiliPublisher.DependencyRegistrar' does not implement interface member 'Nop.Core.Infrastructure.DependencyManagement.IDependencyRegistrar.Register(Autofac.ContainerBuilder, Nop.Core.Infrastructure.ITypeFinder, Nop.Core.Configuration.NopConfig)'

and my code is:

using Autofac;
using Autofac.Core;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Misc.ChiliPublisher.Data;
using Nop.Plugin.Misc.ChiliPublisher.Domain;
using Nop.Plugin.Misc.ChiliPublisher.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nop.Web.Framework.Mvc;

namespace Nop.Plugin.Misc.ChiliPublisher {
  public class DependencyRegistrar : IDependencyRegistrar {

    private const string CONTEXT_NAME = "nop_object_context_chili_orders";

    public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder) {
      builder.RegisterType<ViewChiliPublishingService>().As<IViewChiliPublishingService>().InstancePerLifetimeScope();

      //data context
      this.RegisterPluginDataContext<ChiliObjectContext>(builder, CONTEXT_NAME);

      //override required repository with our custom context
      builder.RegisterType<EfRepository<ChiliOrders>>()
        .As<IRepository<ChiliOrders>>()
        .WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME))
        .InstancePerLifetimeScope();
    }

    public int Order {
      get { return 1; }
    }

  }
}


I have been back through the instructions multiple times but cannot see what I have missed.

Can anyone offer any help please?
8 лет назад
'Nop.Plugin.Misc.ChiliPublisher.Data.ChiliOrdersObjectContext' does not implement interface member 'Nop.Data.IDbContext.ProxyCreationEnabled'

'Nop.Plugin.Misc.ChiliPublisher.Data.ChiliOrdersObjectContext' does not implement interface member 'Nop.Data.IDbContext.Detach(object)'

'Nop.Plugin.Misc.ChiliPublisher.Data.ChiliOrdersObjectContext' does not implement interface member 'Nop.Data.IDbContext.AutoDetectChangesEnabled'

It says that you need to implement ProxyCreationEnabled,Detach,AutoDetectChangesEnabled on your ChiliOrdersObjectContext.cs files as on newer version this three member is newly created so you need to implement it

you can keep it blank but you must have to implement it.
8 лет назад
In addition with With vipul.dumaniya

Please see ===>\Plugins\Nop.Plugin.Feed.Froogle\Data\GoogleProductObjectContext.cs

It will help what should you do.
8 лет назад
followed the google plugin and got it working!

Thanks
8 лет назад
I got this dependencyRegistrar error i create new plugin in nopcommerce 3.70

Error  7  'Nop.Plugin.Misc.VendorPayouts.Infrastructure.DependencyRegistrar' does not implement interface member 'Nop.Core.Infrastructure.DependencyManagement.IDependencyRegistrar.Register(Autofac.ContainerBuilder, Nop.Core.Infrastructure.ITypeFinder, Nop.Core.Configuration.NopConfig)'  C:\SAGAR PATEL\PROJECTS\MALLDESK PRODUCT\PROJECT\Plugins\Nop.Plugin.Misc.VendorPayouts\Infrastructure\DependencyRegistrar.cs  18  18  Nop.Plugin.Misc.VendorPayouts
8 лет назад
sagu25patel wrote:
I got this dependencyRegistrar error i create new plugin in nopcommerce 3.70

Error  7  'Nop.Plugin.Misc.VendorPayouts.Infrastructure.DependencyRegistrar' does not implement interface member 'Nop.Core.Infrastructure.DependencyManagement.IDependencyRegistrar.Register(Autofac.ContainerBuilder, Nop.Core.Infrastructure.ITypeFinder, Nop.Core.Configuration.NopConfig)'  C:\SAGAR PATEL\PROJECTS\MALLDESK PRODUCT\PROJECT\Plugins\Nop.Plugin.Misc.VendorPayouts\Infrastructure\DependencyRegistrar.cs  18  18  Nop.Plugin.Misc.VendorPayouts


Do you register your Interface with Class at DependanceRegister.cs like

  builder.RegisterType<Yourervice>().As<IYourervice>();
8 лет назад
sagu25patel wrote:
I got this dependencyRegistrar error i create new plugin in nopcommerce 3.70

Error  7  'Nop.Plugin.Misc.VendorPayouts.Infrastructure.DependencyRegistrar' does not implement interface member 'Nop.Core.Infrastructure.DependencyManagement.IDependencyRegistrar.Register(Autofac.ContainerBuilder, Nop.Core.Infrastructure.ITypeFinder, Nop.Core.Configuration.NopConfig)'  C:\SAGAR PATEL\PROJECTS\MALLDESK PRODUCT\PROJECT\Plugins\Nop.Plugin.Misc.VendorPayouts\Infrastructure\DependencyRegistrar.cs  18  18  Nop.Plugin.Misc.VendorPayouts


Add a new parameter "NopConfig config" in DependencyRegistrar.cs in  Register method  like bellow

Old ===> That you have from 3.60


public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
//code
}


New ==> for 3.70

public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
{
//.......code
}
6 лет назад
I am using nopCommerce 3.9.0, want to create plugin but documentation is not updated till now.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.