'fieldset', '#title' => t('Main settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); // ACTIVATED $form['settings']['salemail_active'] = array( '#type' => 'radios', '#title' => t('Enable Salemail'), '#default_value' => variable_get('salemail_active', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t("Enable or disable transaction notifications. If enabled, the specified person will receive an email each time a payment is completed."), ); // EMAIL ADDRESS $form['settings']['salemail_email'] = array( '#type' => 'textfield', '#title' => t('Email'), '#default_value' => variable_get('salemail_email', variable_get("site_mail", ini_get("sendmail_from"))), '#size' => 20, '#maxlength' => 255, '#description' => t('An invoice email will be sent to this email address upon payment completion.'), ); return system_settings_form($form); } /** * Implementation of hook_menu() - for salemail callback */ function salemail_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/ecsettings/salemail', 'title' => 'Salemail', 'description' => t('Allow specified email address to be noticed when a payment in complete.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('salemail_ec_settings'), 'access' => user_access('administer store'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } /** * Implementation of hook_ecommerceapi() - for salemail callback */ function salemail_ecommerceapi(&$txn, $op) { //If the review screen has been submitted then send an email] //Note that ec4 supports post_process as an operation. if ($op == 'on payment completion') { $active = variable_get("salemail_active", 0); if ($active) { //Send an email $to = variable_get("salemail_email", variable_get("site_mail", ini_get("sendmail_from"))); ec_mail_send_mid(variable_get(MAILVAR_SALEMAIL, 0), $to, &$txn); } } } /** * Implements hook_token_list() from the token module. * Code reused from store module */ function salemail_token_list($type = 'all') { if (in_array($type, array('all', ECMAIL_TYPE_ADMIN_SALE_NOTIFY))) { $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-id'] = t('Transaction ID.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-balance'] = t('Transaction balance.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-order-date'] = t('Date the order/transaction was created.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-last-mod'] = t('Date the transaction was last modified.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-workflow'] = t('Current state of the transaction.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-shipping-cost'] = t('Cost of shipping.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-payment-status'] = t('Current payment status.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-payment-method'] = t('Payment method used.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-payment-date'] = t('Date payment was made.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-mail'] = t('Mail address stored with the transaction.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-billing-firstname'] = t('First name of the customer.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-billing-lastname'] = t('Surname of the customer.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-billing-address'] = t('Billing address.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-bill-to'] = t("\nBilling to:\n%billing-address\n", array('%billing-address' => t('Billing address is automatically added here'))); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-shipping-address'] = t('Shipping address.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-ship-to'] = t("Shipping to:\n%shipping-address\n", array('%shipping-address' => t('Shipping address is automatically added here'))); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-shipping-method'] = t("\nShipping service:\n%shipping-service\n", array('%shipping-service' => t('Shipping method is automatically added here'))); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-bill-plus-ship'] = t('Three other transaction tokens joined together: [txn-ship-to] [txn-shipping-method] [txn-bill-to].'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['txn-items'] = t('Listing of items in the transaction.'); $vars[ECMAIL_TYPE_ADMIN_SALE_NOTIFY]['site-url-brief'] = t('Site url without the protocol (http://).'); } return $vars; } /** * Implements hook_token_values() from the token module. * Code reused from store module */ function salemail_token_values($type, $object = NULL) { if ($type == ECMAIL_TYPE_ADMIN_SALE_NOTIFY) { global $base_url; $txn = (object) $object; $items = ""; $subtotal = 0; if ($txn->items) { foreach ($txn->items as $p) { $product = product_load($p); $subtotal += $p->qty * $p->price; $items .= t('@order of @title at @price each', array('@order' => format_plural($p->qty, '1 order', '@count orders'), '@title' => $p->title, '@price' => payment_format($p->price))). "\n"; } } $values['txn-id'] = $txn->txnid; $values['txn-balance'] = payment_format($txn->gross); $values['txn-order-date'] = format_date($txn->created); $values['txn-last-mod'] = format_date($txn->changed); $values['txn-workflow'] = $txn->workflow; $values['txn-shipping-cost'] = $txn->shipping_cost; $values['txn-payment-status'] = $txn->payment_status; $values['txn-payment-method'] = $txn->payment_method; $values['txn-payment-date'] = format_date($txn->payment_date); $values['txn-mail'] = $txn->mail; $values['txn-billing-firstname'] = ucfirst($txn->address['billing']->firstname ? $txn->address['billing']->firstname : ''); $values['txn-billing-lastname'] = ucfirst($txn->address['billing']->lastname ? $txn->address['billing']->lastname : t('Customer')); $values['txn-billing-address'] = store_format_address($txn, 'billing'); $values['txn-bill-to'] = $values['txn-billing-address'] ? t("\nBilling to:\n@billing-address\n", array('@billing-address' => $values['txn-billing-address'])) : ''; $values['txn-shipping-address'] = store_format_address($txn, 'shipping'); $values['txn-ship-to'] = $values['txn-shipping-address'] ? t("Shipping to:\n@shipping-address\n", array('@shipping-address' => $values['txn-shipping-address'])) : ''; $values['txn-shipping-method'] = t("\nShipping service:\n@shipping-service\n", array('@shipping-service' => store_format_shipping_method($txn))); $values['txn-bill-plus-ship'] = $values['txn-ship-to'] . $values['txn-shipping-method'] . $values['txn-bill-to']; $values['txn-items'] = $items; $values['site-url-brief'] = substr($base_url, strlen("http://")); } return $values; } /* * Implementation of hook_mail_types() from ec_mail module. */ function salemail_mail_types() { return array( ECMAIL_TYPE_ADMIN_SALE_NOTIFY => t('Sale notification') ); } /* * Implementation of hook_mail_reset() from ec_mail module. */ function salemail_mail_reset($type) { $mids = array(); if ($type == ECMAIL_TYPE_ADMIN_SALE_NOTIFY) { $mail = array(); $mail['type'] = ECMAIL_TYPE_ADMIN_SALE_NOTIFY; $mail['name'] = 'Default admin sale notification'; $mail['subject'] = "New order at [site-name] ([txn-id])"; $mail['body'] = "There's a new order being processed. The transaction ID is --[txn-id]\n\nBilling and Shipping Information:\n\nE-mail address: [txn-mail]\n\nShip to: \n[txn-shipping-address]\n\nBilling to: \n[txn-billing-address]\n\nPayment details:\n[txn-payment-method]\n\nOrder Summary:\n[txn-items]\n\nTotal including shipping: [txn-balance]"; $mid = variable_get(MAILVAR_SALEMAIL, 0); if ($mid != 0) { $mail['mid'] = $mid; } $mid = ec_mail_save(&$mail); ec_mail_variable_change(MAILVAR_SALEMAIL, $mid, TRUE); $mids[] = $mid; } return $mids; } ?>