rnewcomer Posted November 20, 2017 Share Posted November 20, 2017 Hello... It's the weekly question from the CC Noob, hoping you can help me. Is there a way to attach a customer group to an order? I have all of my customers (I have a limited, captive customer list) assigned to customer groups. When the order comes in, some of our people do not know who the customer/order comes from. If I have the customer group added to the order, it goes a long way on processing the order. Note on customer number: We use a Microsoft product for our accounting system. The first part of the customer group (a four digit number) corresponds with the accounting system customer ID, while the last part is a city designator (Example: 9876-NYNY). Thanks in advance for any help you might have. RLN Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 21, 2017 Share Posted November 21, 2017 Please create this Code Snippet (admin, Manage Hooks, Code Snippets tab, Add Snippet link: Enabled: checked Unique ID: addcustgrps@cubecart600+ Execution Order: 99 Description: Adds Customer Membership 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 $snippet_addcustgrps_group_id_resultset = $GLOBALS['db']->select('CubeCart_customer_membership', false, array('customer_id' => $order_summary['customer_id'])); $snippet_addcustgrps_group_ids = []; 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); Assuming whatever is sending order summaries by email will be using Order::getOrderDetails(), which everything should, there will be this new data. The email templates use a $BILLING array. So, edit any and all templates (HTML and Plain Text) to include the string: {$BILLING.cust_groups} The result in the email could look something like: Spouse, Mistresses, Fav Escorts (depending on which group(s) this customer is assigned to). Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 21, 2017 Author Share Posted November 21, 2017 (edited) Ok... I'm missing something. I've added the snippet. I also went to the Admin: Order Received email template. The {$BILLING.cust_groups} was not listed as available macro... So, I added it... {if !empty($BILLING.company_name)}{$BILLING.company_name}{$BILLING.cust_groups} Not showing on the email. Would this also show in the Overview - order summary? That would be nice because, since the the person that normally receives the order email, is not always available. Her supervisor would login and handle the orders from there. He would not see the email. Thank you for your help. R Edited November 21, 2017 by rnewcomer Grammar Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 21, 2017 Share Posted November 21, 2017 Several points: The list of Macros shown is static informational text - the list is not dynamically derived from any sort of on-demand determination or query. Thus, any new template variables made available by plugin, code snippet, or hard coded will have no effect on the list of macros shown. The template line of code shows that it starts with an {if}, and the new variable is inside this block that only gets included if there is a Company Name. Only if there is a Company Name, then the Company Name and then the Groups will be shown. I have not verified where the admin Order Summary gets its info from. If the admin code uses the Order::getOrderDetails() function, then the customer groups will be available. One would need to edit an admin skin template to show it. I will check on that. Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 21, 2017 Author Share Posted November 21, 2017 Quote 19 minutes ago, bsmither said: The template line of code shows that it starts with an {if}, and the new variable is inside this block that only gets included if there is a Company Name. Only if there is a Company Name, then the Company Name and then the Groups will be shown. As always, you are right. Plus, I was using the wrong editor to place the {$BILLING.cust_groups}. It now shows on the email. Now it would be perfect if I could get that to show on the Order Summary. Since I'm still relatively new, I afraid, I don't even know where to begin looking. Thank you, Sir. R Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 21, 2017 Share Posted November 21, 2017 In admin, the Edit Order code directly queries the CubeCart_order_summary and CubeCart_order_inventory tables, and constructs its own array of data to populate the admin Edit Order template. This process could, if it wanted to, use Order::getOrderDetails(). I have no idea why it doesn't. I'll be back shortly with suggestions on where to add code (won't be a snippet) to show the customer group in the list of orders. Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 22, 2017 Share Posted November 22, 2017 I guess it will be a snippet. Enabled: checked Unique ID: orderlistcustgroups@cubecart600+ Execution Order: 99 Description: Adds Customer Group Name(s) to Admin Orders List Trigger: admin.order.index.list Version: 1.0 Author: forums.cubecart.com/topic/53037-orders-to-show-customer-group/ PHP Code: <?php if($smarty_data['list_orders']){ foreach($smarty_data['list_orders'] as &$snippet_orderlistcustgroups_order) { $group_membership = $GLOBALS['db']->misc('SELECT `group_name` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_customer_membership` AS M INNER JOIN `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_customer_group` AS G WHERE G.`group_id` = M.`group_id` AND M.`customer_id` = '.$snippet_orderlistcustgroups_order['customer_id'].';'); if (is_array($group_membership)) { foreach ($group_membership as $membership) {$member_groups[] = $membership['group_name'];} } $snippet_orderlistcustgroups_order['cust_groups'] = isset($member_groups) ? implode(',', $member_groups) : ''; unset($member_groups); } $GLOBALS['smarty']->assign('ORDER_LIST', $smarty_data['list_orders']); } Warning: This snippet reassigns modified source list data to the template variable. If another hook/snippet with an earlier execution order value retrieves and modifies the actual ORDER_LIST template assignment, that modification to the assignment will be lost. Just FYI. Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 22, 2017 Share Posted November 22, 2017 Forgot to discuss the edit to the admin skin template: In orders.index.php, find: Near line 41: {if $order.customer_id} <a href="{$order.link_customer}" title="{$order.name}">{$order.name}</a> {else} {$order.name} {/if} On a new blank line after that, add: {if $order.cust_groups}({$order.cust_groups}){/if} Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 22, 2017 Author Share Posted November 22, 2017 (edited) That looks great. Got it in and it's working perfectly. Here's a follow up question... Could that same or similar edit be placed into line 199 of orders.index.php? <fieldset class="other"> <legend>{$LANG.account.contact_details}</legend> <div><label>{$LANG.common.email}</label><span><a href="mailto:{$OVERVIEW_SUMMARY.email}">{$OVERVIEW_SUMMARY.email}</a></span></div> NEW LINE: RIGHT AROUND HERE? WHICH WOULD BE LINE 199 BECAUSE OF THE PREVIOUS EDIT. <div><label>{$LANG.address.phone}</label><span>{$OVERVIEW_SUMMARY.phone}</span></div> {if !empty($OVERVIEW_SUMMARY.mobile)} <div><label>{$LANG.address.mobile}</label><span>{$OVERVIEW_SUMMARY.mobile}</span></div> {/if} <div><label>{$LANG.common.ip_address}</label><span>{$OVERVIEW_SUMMARY.ip_address}</span></div> </fieldset> Something along this line to put the Customer Group in between email and phone? Thanks for your help... R Edited November 22, 2017 by rnewcomer Grammar Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 22, 2017 Share Posted November 22, 2017 We would have to find a different hook to write a snippet against. Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 22, 2017 Share Posted November 22, 2017 Create this snippet: Enabled: checked Unique ID: ordersumcustgroups@cubecart600+ Execution Order: 99 Description: Adds Customer Group Name(s) to Admin Order Summary Trigger: admin.order.index.display Version: 1.0 Author: forums.cubecart.com/topic/53037-orders-to-show-customer-group/ PHP Code: <?php $snippet_ordersumcustgroups = $GLOBALS['db']->misc('SELECT `group_name` FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_customer_membership` AS M INNER JOIN `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_customer_group` AS G WHERE G.`group_id` = M.`group_id` AND M.`customer_id` = '.$summary[0]['customer_id'].';'); if (is_array($snippet_ordersumcustgroups)) { foreach ($snippet_ordersumcustgroups as $membership) {$member_groups[] = $membership['group_name'];} } $snippet_ordersumcustgroups_order['cust_groups'] = isset($member_groups) ? implode(',', $member_groups) : ''; unset($member_groups); $GLOBALS['smarty']->assign('CUST_GROUPS', $snippet_ordersumcustgroups_order['cust_groups']); Make this edit in the admin skin template: orders.index.php, near line 197, find: <div><label>{$LANG.common.email}</label><span><a href="mailto:{$OVERVIEW_SUMMARY.email}">{$OVERVIEW_SUMMARY.email}</a></span></div> On a new blank line after that, add: <div><label>{$LANG.customer.title_groups_membership}</label><span>{if $CUST_GROUPS}{$CUST_GROUPS}{else}{$LANG.common.unknown}{/if}</span></div> 1 Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 22, 2017 Author Share Posted November 22, 2017 Once again, Sir... this is absolutely perfect. Thank you very much.... R Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 29, 2017 Author Share Posted November 29, 2017 And the hits keep coming.... "B", a while back, you helped me with an Extension called Dropship Products v1.1.0. Was wondering if these latest "snippets" would work in there? Of course I had to give it a shot and stuck this... {$BILLING.cust_groups} in the template. Of course it did not work. I'm assuming that I need to add a hook? Your thoughts... Thank you. R Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 29, 2017 Share Posted November 29, 2017 (Be sure to be using the Source mode of the editor.) Try using: {$DROPSHIP_BILLING.cust_groups} Then, you will probably need to change the execution order of the code snippet "Adds Customer Membership Group Name(s) to Order Details" to 1. (I do not know for sure if the plugin runs first, or if the snippet runs first, and if the execution order of the snippet makes any difference in this case.) Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 30, 2017 Author Share Posted November 30, 2017 16 hours ago, bsmither said: (Be sure to be using the Source mode of the editor.) Try using: {$DROPSHIP_BILLING.cust_groups} Then, you will probably need to change the execution order of the code snippet "Adds Customer Membership Group Name(s) to Order Details" to 1. (I do not know for sure if the plugin runs first, or if the snippet runs first, and if the execution order of the snippet makes any difference in this case.) Yup... you have warned me to use the "source" mode in the past. I did, and inserted the bold into the email message: <p>This order, {$DROPSHIP_DATA.cart_order_id}, for {$DROPSHIP_BILLING.cust_groups}, dated {$DROPSHIP_DATA.order_date}, has products from your department.</p> I then moved the execution order of "Adds Customer Membership Group... Details" to 1. Unfortunately, didn't place the Customer Group into the email. Your thoughts. Thank you, Sir. R Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 30, 2017 Share Posted November 30, 2017 I will need to determine which runs first, the plugin which creates $DROPSHIP_BILLING from the order details, or the snippet that adds cust_groups into the order details. Be back soon. 1 Quote Link to comment Share on other sites More sharing options...
rnewcomer Posted November 30, 2017 Author Share Posted November 30, 2017 Thank you. R Quote Link to comment Share on other sites More sharing options...
bsmither Posted December 1, 2017 Share Posted December 1, 2017 In the snippet above (addcustgrps@cubecart600+), make this edit: Find: $snippet_addcustgrps_group_ids = []; On a new blank line after that, add: $snippet_addcustgrps_group_names = []; (Do this also for the edit to the hook I just sent you as a PM.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.