Close

Custom rule not queueing messages

ron.richardson
9 years ago
#8785 Quote
Avatar
  • 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:

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.
Boyko
9 years ago
#8804 Quote
Avatar
  • 1570
ron.richardson wrote:
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?  


Hi ron.richardson,

Please note that after you return the list of info objects they are then processed and checked against the time intervals. So one possible reason is that they don't match the time rules.
I would advice you to do the followings just to make sure that this is the problem:

1. Crate a new reminder for one of the predefined ones.
2. Make sure this reminder adds messages in the queue.
3. Then add the same time intervals for your reminder using your rule.

Then your info objects should have the same times and they should be queued as well.
Regards,
Nop-Templates.com Team