Zen Cart Logo
Forums / General Questions / Order confirmation email recipients based on product purchased

Order confirmation email recipients based on product purchased

Locked

Views: 4,397

Results 1 to 16 of 16
This thread is locked. New replies are disabled.
7 Feb 2009, 1:38 AM
#1
legionsmith avatar

legionsmith

New Zenner

Join Date:
Nov 2008
Posts:
4
Plugin Contributions:
0

Order confirmation email recipients based on product purchased

Hi all, I've got sort of a strange situation I need to solve here.
I have a zen cart 1.3.7.1 store that I will be adding a couple of virtual products to (not downloadable, they're organization memberships), anyway I need to set things up so that when those two products are purchased then an email is sent not only to me but to this other guy. Problem is, he can't receive confirmation emails when any of the other products are sold, just his.

so basically, I need something like:

"if product_id_1 is sold, then email me and john doe"

otherwise, for all other products, just email me.

Does that make sense? I can't seem to find any posts or mods relating to something of this nature. I'm fairly proficient with php, with a little bit of help I could probably custom code this if need be, but I'm not sure where to start.
Any help would be greatly appreciated.

Thanks,
Michael Smith

7 Feb 2009, 3:36 AM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Order confirmation email recipients based on product purchased

You'll need to customize the function send_order_email in the file includes/classes/order.php - note that there is no override capability for this file.

Basically you'll want to do a conditional test to see if your target product is in the array $this->products, and if it is, send an extra email

7 Feb 2009, 3:48 AM
#3
legionsmith avatar

legionsmith

New Zenner

Join Date:
Nov 2008
Posts:
4
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Bunyip,

Ok cool..I'll go check that out now and see what I can do with it. I appreciate your response. I may have another question or two as well. We'll see how my attempt at hard code customizing goes. hehe

I see you're in my neck of the woods. I'm in Denver myself.

Thanks again,
Michael

7 Feb 2009, 4:05 AM
#4
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Order confirmation email recipients based on product purchased

If you're reasonably proficient with php you shouldn't have any great problems.

I'm not too far away from you - in Conifer.
If you need any direct assistance, PM me for phone/email details.

7 Feb 2009, 4:11 AM
#5
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Order confirmation email recipients based on product purchased

I was just giving this a little more thought, and it should be possible to achieve what you want without actually modifying the core class file order.php

You could use the notifier system, attaching a function to the notifier NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL that is set during the checkout process. That way you would only be adding new files and not editing a core file. It's a bit more complicated though.

7 Feb 2009, 5:18 AM
#6
legionsmith avatar

legionsmith

New Zenner

Join Date:
Nov 2008
Posts:
4
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Ok, yeah, I've poked around in that file. I never would have found that on my own. I'm not worried about editing the core file...I've been running this store for about 3 years now, made several modifications and have plenty of backups.
I'll just have to play around with things. I'm not going to mess with it until tomorrow, I'll post updates here for you or anyone else who might be interested.

Thanks again,
Michael

7 Feb 2009, 9:01 PM
#7
legionsmith avatar

legionsmith

New Zenner

Join Date:
Nov 2008
Posts:
4
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Ok, I think I'm on the right track. I found function_send_order_email at line 863. so starting at line 865 I've added:

if (in_array("Post 1 New Membership",$this->products)) {

	} else {

}

Where Post 1 New Membership is 'name' of product, and it's looking in the $this->products (line 188) array for this info.

Now, I'm a little confused by all the email functions below all of this. I'm not sure if there is something preexisting I can call or if I need to write a new function. I'm kind of thinking I can basically call zen_mail $html_msg I guess to a new variable I create that holds the Post 1 Commander's email address. He's the guy that needs to get an email when his new membership is purchased.

I could use a little help figuring out if I can use a pre-existing email function or what exactly to do next. What do you think?

Thanks a bunch,
Michael

7 Feb 2009, 9:41 PM
#8
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Order confirmation email recipients based on product purchased

You should be able to use an existing email function - just copy the one that sends the additional email already, and modify the recipient and content.

9 Feb 2009, 4:39 AM
#9
msmith1111 avatar

msmith1111

New Zenner

Join Date:
Apr 2006
Posts:
15
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Ok, well I got it working in a testing environment but honestly, it is NOT the way to go for this sort of thing. Basically I checked if product_id's were in the products array and if so then zen_mail to a variable that stores the additional email address to send to. I copied the SEND_EXTRA_ORDER_EMAILS_TO function, chopped it up and rewrote large bits of it to do what I needed. Again though, it's not really a great solution because I'll need to add email addresses in the future for other products for other posts.

So, I've been looking at the notifier in includes/modules/checkout_process.php. I'm thinking that the way to go with this would be to create a full fledged add-on that can be controlled from the admin. What I need is this:

A form on the admin side that will let me specify a product(s) that triggers an email to a specified email address. Basically we have other Posts that want to have their new memberships and renewal on our storefront, when someone signs up (buys one of those products) then the Commander of the Post who's membership was purchased will receive an email. This is in addition to the emails that get send by the admin system anyway. So, if product 1 is purchased then bob jones in Denver gets an email. if product 2 is purchased then john doe in Colorado Springs gets an email, but bob jones doesn't.
Does all that make sense?

So, my question here is, where would I start in writing an add-on and is there any big pitfalls I should keep in mind while doing this?
And where would I start with the notifier system, I feel like I'm missing something with the notifier system, I see where it auto loads in config.core but I don't see any kind of constructor for it. I don't really understand what controls it's behavior.

I've never taken my Zen Cart knowledge this far, it's mostly been templates, custom forms and such on the front end. I'm also a bit weak on the OOP side of things, so it takes me a while to see what's probably painfully obvious to everyone else.

Any and all thoughts are greatly appreciated. I know it sounds like a heck of a mess to figure out but I need to come up with something.

Thanks,
Michael

p.s. just realized I logged in under my other account. this is LegionSmith

9 Feb 2009, 4:53 AM
#10
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Order confirmation email recipients based on product purchased

Start with the wiki (link at top of page) for tutorial on the notifier class. First thing to do would be to add a new field to the product table (or for future upgradeability, into a new product_extra table cross-referenced by product id) so you can identify who gets the extra email for the product.
That would make it easier to just zip through the ordered products post-checkout and send an email if there's an address in that new field for the product.

9 Feb 2009, 5:17 AM
#11
msmith1111 avatar

msmith1111

New Zenner

Join Date:
Apr 2006
Posts:
15
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Oh, now I feel silly. I've never ever seen that wiki link up there before. Sure enough, it tells me everything I need to know about the notifier system.
Thanks for the tip on the extra table as well, that's a good idea. Hopefully I can take it from here, I'll be sure to bother you if I have any more questions. :-)
kudos to the Zen Cart team for the wiki!

Thanks,
Michael

10 Feb 2009, 8:06 PM
#12
msmith1111 avatar

msmith1111

New Zenner

Join Date:
Apr 2006
Posts:
15
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Ok, so far things are going well....I think. Following the methodology outlined in the wiki for setting up a notifier I have a custom config file in the "auto_loaders" folder, and I'm working on the script that goes in the "observers" folder. Now I have two questions:

first, I got this error immediately after setting up a config file:
Fatal error: Class 'emailOthers' not found in C:\wamp\www\zentest\includes\autoload_func.php on line 79
here is my config file "config.emailOther.php" residing in the auto_loaders folder:

<?php /** * @author michael * @copyright 2009 */ $autoLoadConfig[90][] = array('autoType'=>'class', 'loadFile'=>'observers/class.emailOthers.php'); $autoLoadConfig[90][] = array('autoType'=>'classInstantiate', 'className'=>'emailOthers', 'objectName'=>'emailOthers'); ?>

Any idea why I'm getting that error? I assume it's because my emailOthers.php observer file isn't in working order yet.

Question number 2:
I think I need to reference the $this->products array from order.php in my notifier script. But I'm not quite sure how to do so. This may sound like a silly question but is there a way I can check that array for specific values (i.e. product id) from within my notifier script? I'd like to check it to see if a specific product id is in the array and if so then "do something", otherwise continue.

Actually, one more question. I am using the notifier "NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL" as my trigger for this script. I'm not quite sure if thats the right one to use though, I know the names are fairly self explanatory but there are so many to choose from. What do you think?

Thanks again for your time,
Michael Smith

10 Feb 2009, 8:21 PM
#13
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Order confirmation email recipients based on product purchased

Q1 Error is probably because your observer class isn't complete yet.

Q2. You could query the order class, based on the order number (available in the checkout_process module as $insert_id after the order is created). Although everything I've seen in the tutorials and posts on the notifier/observer system say that there are no parameters pass with the notification, the function $notify has actually been built with a parameter capability (class.base.php line 56). You could use that to pass the order number.

Q3. Attaching to either AFTER_ORDER_CREATE_ADD_PRODUCTS or AFTER_SEND_ORDER_EMAIL should be fine.

2 Aug 2010, 7:32 PM
#14
ak69 avatar

ak69

New Zenner

Join Date:
Aug 2009
Posts:
3
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

Any updates on this? I'm trying to do something similar and want to ask here first since the topic has already been started. Better yet, any add ons available for this instead of changing core code?

2 Oct 2010, 12:08 PM
#15
apovey avatar

apovey

New Zenner

Join Date:
Jul 2007
Posts:
29
Plugin Contributions:
0

Re: Order confirmation email recipients based on product purchased

ak69:

Any updates on this? I'm trying to do something similar and want to ask here first since the topic has already been started. Better yet, any add ons available for this instead of changing core code?

Same here, any update on this or the possibility of an add-on?

2 Oct 2010, 1:00 PM
#16
mailbeez avatar

mailbeez

Zen Follower

Join Date:
Jun 2010
Location:
Copenhagen, Danmark
Posts:
479
Plugin Contributions:
2

Re: Order confirmation email recipients based on product purchased

bunyip:

You'll need to customize the function send_order_email in the file includes/classes/order.php - note that there is no override capability for this file.

Basically you'll want to do a conditional test to see if your target product is in the array $this->products, and if it is, send an extra email

hi,

another approach could be using aftersales trigger email campaigns mailbeez:

http://www.zen-cart.com/index.php?main_page=product_contrib_info&cPath=40_60&products_id=1661

this addon allows to "watch" for a certain condition e.g. order with a specific product and then send an email. you would need to build a query to find the orders with the specific products and set up a cronjob that e.g. every minute checks for a new order. so longest 1minute after a matching order the email would be send.

the addon can be installed by just copy the files into zencart and then activate it. it works by "read-only" and does tracking etc so you will never send the same mail twice.
most work would be to build the custom module - should be easy following the structure of the ready made ones.

cord