Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public virtual async Task<IPagedList<NewsLetterSubscription>> CustomerSubscripti
IPagedList<NewsLetterSubscription> model;
if (campaign.CustomerCreatedDateFrom.HasValue || campaign.CustomerCreatedDateTo.HasValue ||
campaign.CustomerHasShoppingCart is not (CampaignCondition.All and CampaignCondition.All) ||
campaign.CustomerHasOrders != CampaignCondition.All ||
campaign.CustomerLastActivityDateFrom.HasValue || campaign.CustomerLastActivityDateTo.HasValue ||
campaign.CustomerLastPurchaseDateFrom.HasValue || campaign.CustomerLastPurchaseDateTo.HasValue ||
campaign.CustomerTags.Count > 0 || campaign.CustomerGroups.Count > 0)
Expand Down Expand Up @@ -176,14 +177,15 @@ from customers in joined
break;
}

//every order placed sets the customer's last purchase date
switch (campaign.CustomerHasOrders)
{
//customer has order
case CampaignCondition.True:
query = query.Where(x => x.IsHasOrders);
query = query.Where(x => x.LastPurchaseDateUtc != null);
break;
case CampaignCondition.False:
query = query.Where(x => !x.IsHasOrders);
query = query.Where(x => x.LastPurchaseDateUtc == null);
break;
}

Expand Down Expand Up @@ -326,7 +328,6 @@ private class CampaignCustomerHelp
public DateTime LastActivityDateUtc { get; set; }
public DateTime? LastPurchaseDateUtc { get; set; }
public bool HasShoppingCartItems { get; set; }
public bool IsHasOrders { get; }
public ICollection<string> CustomerTags { get; set; }
public ICollection<string> NewsletterCategories { get; set; }
public ICollection<string> CustomerGroups { get; set; } = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ await _newsLetterSubscriptionRepository.InsertAsync(new NewsLetterSubscription
Assert.HasCount(1, result);
}

[TestMethod]
[DataRow(CampaignCondition.True, "buyer")]
[DataRow(CampaignCondition.False, "browser")]
public async Task CustomerSubscriptions_CustomerHasOrders_KeepsTheMatchingCustomers(CampaignCondition hasOrders, string expected)
{
await _customerRepository.InsertAsync(new Customer { Id = "buyer", LastPurchaseDateUtc = DateTime.UtcNow.AddDays(-1) });
await _customerRepository.InsertAsync(new Customer { Id = "browser" });
await _newsLetterSubscriptionRepository.InsertAsync(new NewsLetterSubscription { StoreId = "1", Active = true, CustomerId = "buyer", Email = "buyer@x.com" });
await _newsLetterSubscriptionRepository.InsertAsync(new NewsLetterSubscription { StoreId = "1", Active = true, CustomerId = "browser", Email = "browser@x.com" });

//alone, and next to another customer condition
foreach (var hasCart in new[] { CampaignCondition.All, CampaignCondition.False })
{
var campaign = new Campaign { StoreId = "1", CustomerHasOrders = hasOrders, CustomerHasShoppingCart = hasCart };

var result = await _campaignService.CustomerSubscriptions(campaign);

Assert.HasCount(1, result);
Assert.AreEqual(expected, result[0].CustomerId);
}
}

[TestMethod]
public async Task SendCampaignTest()
{
Expand Down
Loading