Override not working on my plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
So I have discovered why my plugin is not working. It has to do with an override I created that overrides a method in the CustomerAttributeService class. I know that there are a couple parts to this theres the override and then the DependacyRegistrar.

Here's my DependacyRegistrar code:

namespace Nop.Plugin.Colhouse.Customizations;
public class DependencyRegistrar
{
  public static int Order => 0;

  public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
  {
    RegistrationExtensions.RegisterType<CustomerAttributeService>(builder).As<ICustomerAttributeService>().InstancePerLifetimeScope();
    RegistrationExtensions.RegisterType<ColhouseCookieAuthenticationService>(builder).As<IAuthenticationService>().InstancePerLifetimeScope();
  }
}


And here is my override:

namespace Nop.Plugin.Colhouse.Customizations.Services
{

  public class CustomerAttributeService : Nop.Services.Customers.CustomerAttributeService
  {
    private readonly IRepository<CustomerAttribute> _customerAttributeRepository;

    private readonly IWebHelper _webHelper;

    private readonly ISettingService _settingService;

    private readonly IStoreContext _storeContext;

    public CustomerAttributeService(IStaticCacheManager cacheManager,
      IRepository<CustomerAttribute> customerAttributeRepository,
      IRepository<CustomerAttributeValue> customerAttributeValueRepository,
      IWebHelper webHelper,
      ISettingService settingService,
      IStoreContext storeContext)
      : base(customerAttributeRepository, customerAttributeValueRepository, cacheManager)
    {
      _customerAttributeRepository = customerAttributeRepository;
      _webHelper = webHelper;
      _settingService = settingService;
      _storeContext = storeContext;
    }

    public override async Task<IList<CustomerAttribute>> GetAllCustomerAttributesAsync()
    {
      ColHouseDesignsSettings settings = await _settingService.LoadSettingAsync<ColHouseDesignsSettings>(0);
      if (settings.Enable)
      {
        string currentUrl = _webHelper.GetThisPageUrl(false);
        if (!currentUrl.ToLowerInvariant().Contains("admin"))
        {
          Store currentStore = _storeContext.GetCurrentStore();
          bool isWholsesale = currentStore.Id == settings.WholesaleStoreId;
          bool isRetail = currentStore.Id == settings.RetailStoreId;
          if (isWholsesale)
          {
            if (!string.IsNullOrEmpty(settings.WholesaleCustomerFormFieldIds))
            {
              List<int> wholesaleCustomerFormFieldIds = settings.WholesaleCustomerFormFieldIds.Split(',').Select(int.Parse).ToList();
              IOrderedQueryable<CustomerAttribute> query2 = _customerAttributeRepository.Table.Where((Expression<Func<CustomerAttribute, bool>>)((CustomerAttribute ca) => wholesaleCustomerFormFieldIds.Contains(ca.Id))).OrderBy((Expression<Func<CustomerAttribute, int>>)((CustomerAttribute ca) => ca.DisplayOrder));
              return query2.ToList();
            }
            return new List<CustomerAttribute>();
          }
          if (isRetail)
          {
            if (!string.IsNullOrEmpty(settings.RetailCustomerFormFieldIds))
            {
              List<int> retailCustomerFormFieldIds = settings.RetailCustomerFormFieldIds.Split(',').Select(int.Parse).ToList();
              IOrderedQueryable<CustomerAttribute> query = _customerAttributeRepository.Table.Where((Expression<Func<CustomerAttribute, bool>>)((CustomerAttribute ca) => retailCustomerFormFieldIds.Contains(ca.Id))).OrderBy((Expression<Func<CustomerAttribute, int>>)((CustomerAttribute ca) => ca.DisplayOrder));
              return query.ToList();
            }
            return new List<CustomerAttribute>();
          }
        }
      }
      return await GetAllCustomerAttributesAsync();
    }
  }
}

At any rate this is not working and I am not sure why. My only thought is that it is not registered properly.

Thanks!
Rob
1 year ago
What version of nopCommerce ?
You may need to change the Order => 0; to a higher value

For 4.5 I use
public int Order => 3000;
in my plugins
1 year ago
HI
if you are using nopCommerce 4.4 or 4.5 you need to register like this
first Interface and then service

 public virtual void Register(IServiceCollection services, ITypeFinder typeFinder, AppSettings appSettings)
        {
            services.AddScoped<IShippingByWeightByTotalService, ShippingByWeightByTotalService>();
        }

as you can check the reference from this plugin Nop.Plugin.Shipping.FixedByWeightByTotal

as your code might be like this

 public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
  {
    RegistrationExtensions.RegisterType<ICustomerAttributeService>(builder).As<CustomerAttributeService>().InstancePerLifetimeScope();
    RegistrationExtensions.RegisterType<IAuthenticationService>(builder).As<ColhouseCookieAuthenticationService>().InstancePerLifetimeScope();
  }


it might work, or you can check in the existing plugin
1 year ago
skagitmedia wrote:
So I have discovered why my plugin is not working. It has to do with an override I created that overrides a method in the CustomerAttributeService class. I know that there are a couple parts to this theres the override and then the DependacyRegistrar.

Here's my DependacyRegistrar code:

namespace Nop.Plugin.Colhouse.Customizations;
public class DependencyRegistrar
{
  public static int Order => 0;

  public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
  {
    RegistrationExtensions.RegisterType<CustomerAttributeService>(builder).As<ICustomerAttributeService>().InstancePerLifetimeScope();
    RegistrationExtensions.RegisterType<ColhouseCookieAuthenticationService>(builder).As<IAuthenticationService>().InstancePerLifetimeScope();
  }
}

Rob


You need to give high priority.

public static int Order => int.maxvalue;
1 year ago
First of all thank you all for the responses. I have tried them all yet no success. I rebuilt the plugin every time as well. Is there something else I am missing?

Thanks!
Rob
1 year ago
What version of nopCommerce ?
1 year ago
RE: "...this is not working "
Please describe "not working".  Did you set a breakpoint in the code, and it never gets hit?
1 year ago
Nop commerce Version 4.50.4
And yes I set a breakpoint and it is blowing right by.
Thanks!
Rob
1 year ago
Actually I had problem with v4.50.4 as well
I have a plugin with overrides that worked perfectly in v4.50.3
I copied the plugin to v4.50.4 and changed nothing and the overrides did not work
I then did a Diff and manually went through and made all the changes in v4.50.4 to a copy of the v4.50.3 version called v4.50.3to4, trying to find what change may have caused the issue.
After in theory, all the changes were made and the two versions were the supposedly the same I checked the v4.50.3to4 version and the overrides worked
I went back to the original v4.50.4 version just to double check and the overrides were still not working
So I have stayed the v4.50.3to4 version and found no problems
Totally confusing to me
1 year ago
Yidna wrote:
Actually I had problem with v4.50.4 as well
I have a plugin with overrides that worked perfectly in v4.50.3
I copied the plugin to v4.50.4 and changed nothing and the overrides did not work
I then did a Diff and manually went through and made all the changes in v4.50.4 to a copy of the v4.50.3 version called v4.50.3to4, trying to find what change may have caused the issue.
After in theory, all the changes were made and the two versions were the supposedly the same I checked the v4.50.3to4 version and the overrides worked
I went back to the original v4.50.4 version just to double check and the overrides were still not working
So I have stayed the v4.50.3to4 version and found no problems
Totally confusing to me


Are you suggesting I go back to 4.50.3? It almost sounds like that there is a bug in version 4.50.4.
I post it on the bug thread and see what they say.

Thanks!
Rob
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.