Jump to content

Email Macro


Claudia M

Recommended Posts

Please be aware that the list of email variables (aka macros) shown in the table below the editor is a static list. That is, the list is not derived from inspecting any template, or being provided a dynamic analysis of what the core code is supplying. (I am not aware of this list being updated since CC500.)

So, modifications can be made to the core code that assigns data to template variables to provide additional information -- the customer's group membership name, for example. It then follows that the admin will need to be aware of this new template variable and edit the email template to use it.

Link to comment
Share on other sites

There will be two parts:

1. In the Order class, using the existing customer_id from the order summary data, fetch the relevant names of the membership groups. Assign this to the element 'cust_groups' of the 'billing' array. (Fortunately, there is a hook that can be used.)

2. Edit the email template to show {$BILLING.cust_groups}.

Link to comment
Share on other sites

Is this where and how I add the info to classes/order.class? Anywhere else I need to add info, excluding the email template.  Do I have to add one for each customer group or will Cubecart figure it out since it will already be assigned to the customer. And why is this assigned to BILLING instead of just using DATA?

I created a field in the order summary data base for - realemail.  Should I add this here too? And How would I tell the email template which to use.  If customer is not from CubeCart then the realemail would be used.

Sorry for all the questions and thanks so much for your help

Line 134

 public function assignOrderDetails($values = null, $admin = null)

    {

        $this->_email_details = (is_null($values)) ? $this->_email_details : $values;

        $field = $GLOBALS['config']->get('config', 'oid_mode') == 'i' ? $GLOBALS['config']->get('config', 'oid_col') : 'cart_order_id';

        $order_id = $this->_email_details['order_summary'][$field];

        $this->_email_details['order_summary']['link'] = (is_null($admin)) ? $GLOBALS['storeURL'].'/index.php?_a=vieworder&cart_order_id='.$order_id : $GLOBALS['storeURL'].'/'.$GLOBALS['config']->get('config', 'adminFile').'?_g=orders&action=edit&order_id='.$order_id;

 

        foreach ($GLOBALS['hooks']->load('class.order.assign_order_details') as $hook) {

            include $hook;

        } // custom made details

        $GLOBALS['smarty']->assign('BILLING', $this->_cust_groups['billing']);

        $GLOBALS['smarty']->assign('DATA', $this->_email_details['order_summary']);

        $GLOBALS['smarty']->assign('BILLING', $this->_email_details['billing']);

        $GLOBALS['smarty']->assign('SHIPPING', $this->_email_details['shipping']);

        $GLOBALS['smarty']->assign('TAXES', $this->_email_details['taxes']);

        $GLOBALS['smarty']->assign('PRODUCTS', $this->_email_details['products']);

    }

Link to comment
Share on other sites

That's a good try, but let's use a function that adds the extra data to an array before this particular code uses that array to create email template variables. In this way, we can have the extra data available at many more instances than just email templates.

Let's use the code snippet found in the function getOrderDetails(). In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

When the page refreshes, at the bottom will be a form for the snippet.

Enabled: checked
Unique ID: addcustgrps@cubecart
Execution Order: 1
Description: Adds Customer Group Name(s) to Order Details
Trigger: class.order.get_order_details
Version: 1.0
Author: forums.cubecart.com/topic/53037-orders-to-show-customer-group/
PHP Code:
?php
/****************************************
 * Hook: class.order.get_order_details
 * 
 ***************************************/
$values['billing']['cust_groups'] = '';
if(($snippet_addcustgrps_group_id_resultset = $GLOBALS['db']->select('CubeCart_customer_membership', false, array('customer_id' => $order_summary['customer_id']))) !== false) {
  $snippet_addcustgrps_group_ids = [];
  $snippet_addcustgrps_group_names = [];
  foreach ($snippet_addcustgrps_group_id_resultset as $snippet_addcustgrps_group_id_record) {
    $snippet_addcustgrps_group_ids[] = $snippet_addcustgrps_group_id_record['group_id'];
  }
  $snippet_addcustgrps_group_name_resultset = $GLOBALS['db']->select('CubeCart_customer_group', 'group_name', array('group_id' => $snippet_addcustgrps_group_ids));
  foreach ($snippet_addcustgrps_group_name_resultset as $snippet_addcustgrps_group_name_record) {
    $snippet_addcustgrps_group_names[] = $snippet_addcustgrps_group_name_record['group_name'];
  }
  $values['billing']['cust_groups'] = implode(',',$snippet_addcustgrps_group_names);
}

The function getOrderDetails() then puts this data into a variable called $this->_email_details. Then the function assignOrderDetails() does a bit more processing and sends the data to Smarty template variables.

There is now a {$BILLING.cust_groups} string of group names we have available. The $BILLING array contains everything about the purchaser, while $DATA contains overall details about the order.

Link to comment
Share on other sites

I know it would be near impossible to change the CC auto generated Order Number ( I don't use the sequenced order numbers).  I'm thinking of my ebay customers I add to CC.  What if I added a database field in the Order Summary database like I did for realemail and name it realorderno or something like that.  Could I then add a code snippet like above for this realorderno and add the macro to the email templates?

I was trying to be able to send ebay customers order emails thru CC but I think it might be to involved.  I'd have to be able to use the ebay / Etsy order numbers and if I don't get the customer setup quickly the order date may be off. 

If anyone has any ideas it would be appreciated.

Claudia

 

Link to comment
Share on other sites

Information added directly to the CubeCart_order_summary database table will appear as an available macro for email templates. One would only need to add more code to the function getOrderDetails() if that data needed to be processed or enhanced in some way (for example, formatting prices to the customer's currency symbols).

You would use the macro {$DATA.realorderno}.

Link to comment
Share on other sites

You don't need to. Data put into and taken directly out of the CubeCart_order_summary database table will (should) be available in the $DATA macro array.

We needed the snippet above because the customer membership group names are not stored in the CubeCart_order_summary table. We had to derive it from the customer_id number.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...