This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

How to Manually Send Email Messages

The built-in mail system allows you to send email notifications to customers and system administrators. The email messages are template based. You can create email templates on the System/Settings/Email Templates page.

Sending messages to customers

To send an email message to a customer you need:

  1. Find an email template by its code.
  2. Find a customer record.
  3. Replace the email template variables with real values.
  4. Send the message using the template's send_to_customer() method.

Example:

$template = System_EmailTemplate::create()->find_by_code('my_template');
$customer = Shop_Customer::create()->find(10);
if ($template && $customer)
{
  $message = $customer->set_customer_email_vars($template->content);
  $template->send_to_customer($customer, $message);
}

The set_customer_email_vars() method of the Shop_Customer class replaces all customer-related email variables (customer name, etc.) in the template with real values. If you use any custom email variables in the email template, you can replace them with the str_replace function:

$message = $template->content;
$message = str_replace('{my_var}', $some_variable, $message);
$template->send_to_customer($customer, $message);

The Shop_Order class has a similar method - set_order_and_customer_email_vars(), which replaces all order-related and customer email variables with real values. If you have an order object and your email template contains any order-related variables, you can replace them using the following code:

$message = $template->content;
$message = $order->set_order_and_customer_email_vars($customer, $message, null);

Sending messages to LemonStand users

The send_to_team() method of the System_EmailTemplate class allows you to send email messages to LemonStand users. The class accepts 2 required parameters: the list of users and the message text. To send an email message to LemonStand users you need:

  1. Find an email template by its code.
  2. Prepare a list of users you are going to send the message to.
  3. Replace the email template variables with real values.
  4. Send the message using the template's send_to_team() method.

Example:

$template = System_EmailTemplate::create()->find_by_code('my_template');
$users = Users_User::listAdministrators();
if ($template)
{
  $message = str_replace('{my_var}', $some_variable, $template->content);
  $template->send_to_team($users, $message);
}

The listAdministrators() method of the Users_User class returns a list of all system administrators. You can also use the list_users_having_permission() method for finding all users who have specific permissions. For example, to find users who have permissions to work with the Orders page you can use the following code:

$users = Users_User::list_users_having_permission('shop', 'manage_orders_and_customers');

You can find a list of module-specific user permissions in the module information class declaration, in the buildPermissionsUi() method. For example, the Shop module permissions are declared in the modules/shop/classes/shop_module.php script.


Previous: Managing Compound Email Variables
Return to Notifications and Emails