Affiliate Timeout Set to 30 Days

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 năm cách đây
Hi, All,

I have been looking at how to set the timeouts on affiliates to 30-days instead of a lifetime, in our industry the lifetime setting is not beneficial, so instead a quick attempt has been made by following the steps below, feedback would be good.

Set the scheduled task to delete guests to 86400 seconds or 1-day

Edit the DeleteGuestTask class in NopServices -> Customers and adding the following code.


public async System.Threading.Tasks.Task ExecuteAsync()
        {
            var olderThanMinutes = _customerSettings.DeleteGuestTaskOlderThanMinutes;
            // Default value in case 0 is returned.  0 would effectively disable this service and harm performance.
            olderThanMinutes = olderThanMinutes == 0 ? 1440 : olderThanMinutes;

            await _customerService.DeleteGuestCustomersAsync(null, DateTime.UtcNow.AddMinutes(-olderThanMinutes), true);

            // remove affiliates older then 30-days
            System.Collections.Generic.IList<Customer> customers = await _customerService.GetAllCustomersAsync();
            var affiliates = customers.Where(x => (x.AffiliateId != 0)).Where(x => x.CreatedOnUtc < DateTime.Now.AddDays(-30));



            foreach (var affiliate in affiliates)
            {
                affiliate.AffiliateId = 0;
                await _customerService.UpdateCustomerAsync(affiliate);
            }

        }


If anyone experienced with NOP has feedback, please feel free to respond.
2 năm cách đây
Looks fine.  Could be shortened a bit:
var customers = await _customerService.GetAllCustomersAsync();
var affiliates = customers.Where(x => x.AffiliateId != 0 && x.CreatedOnUtc < DateTime.Now.AddDays(-30));
2 năm cách đây
Thank ou  very much for your reply and help.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.