- 6
I've built a custom rule, and it shows up just fine. I've configured it and debugged it to verify that results are coming back. However, nothing is getting queued up in the Reminders report. As long as my query returns back values, it should be as simple as returning a List<CustomerReminderInfo> records from GetCustomerReminderInfos, right?
Here is my partial code:
Is there anything else I need to do to get the reminder emails to be added to the queue? Like I said before, I've used the debugger and verified that the query returns records, and it returns back a List<> with the expected number of records. Nothing gets added to SS_CR_CustomerReminderMessageRecord however or the Nop message queue.
Here is my partial code:
public IList<string> GetAllowedTokens()
{
var allowedTokens = new List<string>()
{
"%Customer.FirstName%",
"%Product.Name%"
};
return allowedTokens;
}
public IList<CustomerReminderInfo> GetCustomerReminderInfos(TimeSpan conditionMetDateEarlierThan, TimeSpan conditionMetDateLaterThan, int storeId)
{
List<CustomerReminderInfo> reminders = new List<CustomerReminderInfo>();
var currentDateTime = DateTime.UtcNow;
var ts1 = Convert.ToInt32(conditionMetDateEarlierThan.TotalSeconds);
var ts2 = Convert.ToInt32(conditionMetDateLaterThan.TotalSeconds);
var reviewableProducts = (
from o in _orderRepository.Table
join oi in _orderItemRepository.Table on o.Id equals oi.OrderId
join p in _productRepository.Table on oi.ProductId equals p.Id
join c in _customerRepository.Table on o.CustomerId equals c.Id
where
o.OrderStatus == OrderStatus.Complete
&& o.PaymentStatus == PaymentStatus.Paid
&& _productReviewRepository.Table.Where(x => x.CustomerId == o.CustomerId && x.ProductId == oi.ProductId).Count() == 0
&& o.PaidDateUtc.HasValue
&& DateTime.UtcNow >= DbFunctions.AddSeconds(o.PaidDateUtc.Value, ts1)
&& DateTime.UtcNow < DbFunctions.AddSeconds(o.PaidDateUtc.Value, ts2)
select new
{
Id = oi.Id,
Customer = c,
Product = p
}
);
foreach (var x in reviewableProducts)
{
var reminder = new CustomerReminderInfo()
{
Customer = x.Customer,
ReminderMessageId = x.Id,
RuleConditionMetDate = DateTime.UtcNow,
Tokens = GetTokens(x.Customer, x.Product),
StoreId = storeId
};
reminders.Add(reminder);
}
return reminders;
}
private IList<Token> GetTokens(Customer customer, Product product)
{
var tokens = new List<Token>();
var firstName = _genericAttributeService.GetAttributesForEntity(customer.Id, "Customer")
.Where(x => x.Key == SystemCustomerAttributeNames.FirstName)
.Where(x => x.KeyGroup == "Customer")
.Select(x => x.Value)
.FirstOrDefault();
tokens.Add(new Token("Customer.FirstName", firstName));
tokens.Add(new Token("Product.Name", product.Name));
return tokens;
}
Is there anything else I need to do to get the reminder emails to be added to the queue? Like I said before, I've used the debugger and verified that the query returns records, and it returns back a List<> with the expected number of records. Nothing gets added to SS_CR_CustomerReminderMessageRecord however or the Nop message queue.