How to bulk email customers based on item purchased
Posted: Wed May 18, 2016 2:48 am
So a client recently wanted the ability to email customers based on certain order criteria. Specifically they wanted all customers who bought a certain product sku within a specified time period. I wrote something like that years ago to handle recall notices, but this was Able Gold. And it needed to be a better integration than some separate page hacked together on a whim.
It turns out, this was painfully simple to add. In case you haven't noticed, there are some excellent filter features in the Order Manager page. Date range is there, along with order statuses, shipment status and that oh-so-magical keyword search. One of the keyword search choices is SKU. Now we're getting somewhere!
I set out to modify the Order Manager page, only to realize that Able has already built about 95% of what I need. By leveraging the existing code and user controls, my modifications to Order Manager turned out simple and easy to implement. If you're interested in adding a bulk email option to the Order Manager page, follow these steps:
First, open the /Admin/Orders/default.aspx.cs and find this code in Page_Init():
and replace it with this code:
Great. Now we have a menu choice for sending an email. But, we still need to process that menu choice when the GO button is clicked. That change is accomplished later in the page code.
Later in the same file, locate the BatchButton_Click() method. Find this code:
and replace it with this code:
That's it! Now save the changes and refresh your page. You'll have a new menu choice in the bulk options dropdown at the bottom of the page. When you select some orders and click the button on the send-email choice, the new code will build a list of users for the orders that were selected. It then passes this list to an existing send-email routine normally used by other areas of the Able admin.
Able did all of the hard work for me. I just needed to wire up a new way to pass the data to their existing programming. Now my client can easily send an email to a select group of customers based on a wide variety of filter criteria. Exactly what they wanted with minimal customization !
It turns out, this was painfully simple to add. In case you haven't noticed, there are some excellent filter features in the Order Manager page. Date range is there, along with order statuses, shipment status and that oh-so-magical keyword search. One of the keyword search choices is SKU. Now we're getting somewhere!
I set out to modify the Order Manager page, only to realize that Able has already built about 95% of what I need. By leveraging the existing code and user controls, my modifications to Order Manager turned out simple and easy to implement. If you're interested in adding a bulk email option to the Order Manager page, follow these steps:
First, open the /Admin/Orders/default.aspx.cs and find this code in Page_Init():
Code: Select all
BatchAction.Items.Add(new ListItem("Export", "EXPORT"));
Code: Select all
BatchAction.Items.Add(new ListItem("Export", "EXPORT"));
// BEGIN MOD: AbleMods.com
// DATE: 05/18/2016
BatchAction.Items.Add(new ListItem("Send Email", "EMAIL"));
// END MOD: AbleMods.com
Later in the same file, locate the BatchButton_Click() method. Find this code:
Code: Select all
switch (BatchAction.SelectedValue)
{
case "INVOICE":
Code: Select all
switch (BatchAction.SelectedValue)
{
// BEGIN MOD: AbleMods.com
// DATE: 05/18/2016
case "EMAIL":
// build list of users for the selected orders
List<int> selectedUserIds = new List<int>();
foreach (int orderId in orderIds)
{
// load the order
Order order = OrderDataSource.Load(orderId);
// make sure order is valid
if (order != null)
{
// add the user id from this order to the list
selectedUserIds.Add(order.UserId);
}
}
// if we have some people to email, call the email routine
if (selectedUserIds.Count > 0)
{
Session["SendMail_IdList"] = "UserId:" + AlwaysConvert.ToList(",", selectedUserIds);
Response.Redirect("~/Admin/People/Users/SendMail.aspx?ReturnUrl=" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("~/Admin/Orders/Default.aspx")));
}
break;
// END MOD: AbleMods.com
case "INVOICE":
Able did all of the hard work for me. I just needed to wire up a new way to pass the data to their existing programming. Now my client can easily send an email to a select group of customers based on a wide variety of filter criteria. Exactly what they wanted with minimal customization !