sailing123 Posted March 17, 2017 Share Posted March 17, 2017 (edited) Hi again :-) Another issue that I need to address. In Cubecart 4, the admin receives a copy of all emails sent to customers, ie pending, processing, complete, etc. This is great for 2 reasons: when the customer mistypes her/his email address, our email system alerts us and 50% of the time we can correct it manually and resend the emails so minimum communication interruption remotely we can check that orders have been dispatched by members of staff without actually going into the admin. Although point 1 is more important. In Cubecart 6, the store settings only let the admin choose one set of order status email only. Al tells me that I could just edit the classes/mailer.class.php file to BCC me into ever send function call. I had a quick look and it is all php coding, well above my capabilities. Would anyone know the coding bit I require and where to insert it please ? Thanks S. Edited March 17, 2017 by sailing123 Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 18, 2017 Share Posted March 18, 2017 (edited) The following is a plan to create two Code Snippets for CC615: one to "globalize" the Mailer class instance instantiated by Order->orderStatus(), and the other to toss in all admin emails that have been set to receive such notifications to a BCC array. In admin, Manage Hooks, Code Snippets tab, click Add Snippet. Enabled: Checked Unique ID: classize_mailer@cubecart Execution Order: 99 Description: Class-izes the Mailer instantiation so that it can be seen outside the orderStatus() method. Trigger: class.order.order_status Version: 1.0 Author: https://forums.cubecart.com/topic/52330-how-to-add-admin-as-bcc-of-all-customers-order-status-emails/ PHP Code: <?php $this->_mailer =& $mailer; Save. Start another Code Snippet. Enabled: Checked Unique ID: bcc_admin@cubecart Execution Order: 99 Description: BCC's the admins on all customer emails. Trigger: class.order.assign_order_details Version: 1.0 Author: https://forums.cubecart.com/topic/52330-how-to-add-admin-as-bcc-of-all-customers-order-status-emails/ PHP Code: <?php //$this->_mailer->SMTPDebug = 2; //$this->_mailer->Debugoutput = 'error_log'; $addBCC_notify_admins = explode(',', $this->_notifyAdmins()); foreach ($addBCC_notify_admins as $admin) { $this->_mailer->addBCC($admin); } Save. As I have been testing this, a couple of things are preventing me from discovering if this really works. I see the names getting added to the BCC array, and I see the names being mentioned in RCPT TO commands to the SMTP Server. But (due to a funny thing about my web server), the Test Gateway does not complete, so I do not get all the diagnostics I want, and maybe the SMTP server I am sending this out to is grouping all the email addresses (as the customer and all admins have the same domain of an email address). I do not see any BCC TO command. So, more experimenting. But I wanted to get this posted. Edited March 18, 2017 by bsmither 1 Quote Link to comment Share on other sites More sharing options...
sailing123 Posted March 18, 2017 Author Share Posted March 18, 2017 Hi bsmither, Can't it be just a matter of letting the store settings to allow multiple selection in the function "Order status for admin email notifications", using the html <select multiple> for the form ? You then hold down the Ctrl (windows) / Command (Mac) button to select multiple options, like this https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple S. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 18, 2017 Share Posted March 18, 2017 I have some core edits that add BCC to specific emails. I'll test commenting those out today and try the Snippet - hopefully it works! Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 18, 2017 Share Posted March 18, 2017 We can add to core code the additional options to send the admin an email when an order moves to that status. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 I tested your code snippet today with emails as a customer contacting us, with good results. One plugin email did not BCC, but it actually only emails the admin, anyway, to notify of a new testimonial waiting for approval. So I would think it's outside the logic of your snippet. Going to test with some fake orders now. No such luck on orders. I get a string of nonsense characters ( PD9waHAKJHRoaXMtPl9tYWlsZXIgPSYgJG1haWxlcjs= ) on a blank page when the snippets are enabled and I try to change from Pending to Processing on my fake order. Quote [19-Mar-2017 16:21:30 America/Chicago] PHP Fatal error: Call to a member function addBCC() on null in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6 Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 The snippet hooks into the CubeCart code that does things when an order's status changes. It is meant to BCC a copy of the customer's email that CubeCart sends when the order moves through the various statuses. If a visitor uses the Contact Us page, this has nothing to do with moving an order to a different status. (You, as the admin, should be getting the email from the Contact Us page anyway!) Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 I thought the idea was to get a BCC, so I could easily reply to the customer to any email the admin received. I un-commented the debug lines in the snippet and tried Pending to Processing again. I still get the string of characters on a blank page, but there's more in the error log: Quote [19-Mar-2017 16:27:11 America/Chicago] PHP Fatal error: Call to a member function addBCC() on null in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6 [19-Mar-2017 16:35:07 America/Chicago] PHP Warning: Creating default object from empty value in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 2 [19-Mar-2017 16:35:07 America/Chicago] PHP Fatal error: Call to undefined method stdClass::addBCC() in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6 Here's the snippet_3afa312cdc3acf2182d2144a8cfac7be.php as it reads now: <?php $this->_mailer->SMTPDebug = 2; $this->_mailer->Debugoutput = 'error_log'; $addBCC_notify_admins = explode(',', $this->_notifyAdmins()); foreach ($addBCC_notify_admins as $admin) { $this->_mailer->addBCC($admin); } Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 "Creating default object from empty value" This tells me that the first snippet isn't getting executed. The snippet at class.order.order_status has this: $this->_mailer =& $mailer; This statement is what allows the second snippet to be able to call functions in the Mailer. Are you moving a fake order via admin control? As opposed to working your way through a purchase from start to finish as a customer? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 I created the order by logging in with a test customer account. I took it to PayPal, but then went back to the store. Then when I tried to change it to Processing, as if it had been paid - I get the error message. Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 (edited) The non-sense characters are the contents of the first snippet -- base64 encoded. So, CubeCart must not have this snippet stored in the database correctly. But if so, then CubeCart must not be creating a snippet file from it. You have snippet_3afa312cdc3acf2182d2144a8cfac7be.php, but where is snippet_5c6632328d5bb207a40e3ef624488c36.php? Edited March 19, 2017 by bsmither Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 That base64 encoded string is all that is in the other snippet. Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 Storing snippet code in the database in a base64 format is new to CC615. But similar strange hash would appear on a blank page for any snippet code if the problem was with CubeCart code not decoding the snippet code properly. So, I think the problem is (probably) not with Cubecart. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 We have 3 domains, so it's not because I'm using a customer email address from our store domain. Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 Unless you have two stores using the same database? One at CC615 and the other at some other version ahead or behind, or some manual version edit to CC615 didn't make it from a version prior. " That base64 encoded string is all that is in the other snippet. " Where did you look? The snippet file or the CubeCart_code_snippet table? If snippet_5c6632328d5bb207a40e3ef624488c36.php , then I assume the contents of snippet_3afa312cdc3acf2182d2144a8cfac7be.php are NOT base64 encoded? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 I'll check the table itself. The PD9waHAKJHRoaXMtPl9tYWlsZXIgPSYgJG1haWxlcjs= is what's in the snippet file I see via FTP. Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 I think the table will have the base64 encoded code. What about the contents of snippet_3afa312cdc3acf2182d2144a8cfac7be.php? The question then is, why isn't CubeCart decoding the first snippet before writing it to the file? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 Here's the snippet file: snippet_5c6632328d5bb207a40e3ef624488c36.php snippet_3afa312cdc3acf2182d2144a8cfac7be.php My test store is on current commit of 6.1.6 - but I don't remember anything that's been changed that sounds like it would affect this. Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 Ok, snippet_3afa is not encoded, but snippet_5c66 is encoded. Try: Delete the snippet_5c66. Go back into admin, Code Snippets, bring up the first snippet ("Class-izes...") for editing. No need to edit it. Just save it. CubeCart will not make another snippet until it is actually needed. So, make another test order. (Or maybe move an existing Processing order to Completed.) Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 Delete _5c66 in the database table? Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 Delete the actual file at /includes/extra/snippet_5c6632328d5bb207a40e3ef624488c36.php Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 Sorry - UEQ5d2FIQUtKSFJvYVhNdFBsOXRZV2xzWlhJZ1BTWWdKRzFoYVd4bGNqcz0= [19-Mar-2017 17:43:47 America/Chicago] PHP Warning: Creating default object from empty value in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 2 [19-Mar-2017 17:43:47 America/Chicago] PHP Fatal error: Call to undefined method stdClass::addBCC() in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6 Maybe I copied something wrong when I created the snippets: Went to see to make a copy of my code for you and found THIS! Is THIS supposed to be in the snippet box where I saved the classize one????? UEQ5d2FIQUtKSFJvYVhNdFBsOXRZV2xzWlhJZ1BTWWdKRzFoYVd4bGNqcz0= Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 Ok, this: UEQ5d2FIQUtKSFJvYVhNdFBsOXRZV2xzWlhJZ1BTWWdKRzFoYVd4bGNqcz0= is base64 encoded this: PD9waHAKJHRoaXMtPl9tYWlsZXIgPSYgJG1haWxlcjs= You deleted the snippet_5c66 file, and CubeCart put it back. When you brought up the snippet for editing, did the code look like the code in my initial post above? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted March 19, 2017 Share Posted March 19, 2017 NO! the <?php $this->_mailer =& $mailer; is GONE and the encoded is there Quote Link to comment Share on other sites More sharing options...
bsmither Posted March 19, 2017 Share Posted March 19, 2017 Please re-edit that snippet by changing the code to what is supposed to be there. Save. Try making an order. 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.