Forums / General Questions / Custom function upon successful order placement

Custom function upon successful order placement

Locked

Started by gwixel on 3 May 2008, 4:21 AM · Views: 1,836

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
3 May 2008, 4:21 AM
#1
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Custom function upon successful order placement

I'm integrating Zen Cart into my own CMS and I have a need to call a custom function when an order is successfully placed. The basic Idea is I'm selling "points" that can then be redeemed for merchandise.

When an order for points is placed, I want to call a custom function that inserts the number of points purchased into another database table.

My question is, which particular file should I be working with to place my function call? Zen Cart is new to me and I'm still struggling to find my way around in the code. :smile:

3 May 2008, 5:36 AM
#2
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Custom function upon successful order placement

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

3 May 2008, 4:58 PM
#3
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Re: Custom function upon successful order placement

Thanks yellow1912, that's exactly the kind of information I was looking for!

3 May 2008, 7:30 PM
#4
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Re: Custom function upon successful order placement

I've been reading through the documentation for the API and testing a little observer class I made. I've also read through some forum posts, but I can't find the nugget of truth I'm looking for yet. :blink: The API examples hook into $_SESSION['cart'] and I want to hook into the checkout process. I'm assuming I need to use the NOTIFY_HEADER_END_CHECKOUT_SUCCESS event in my case.

What object do I attach to in my constructor function? I read some posts about using $zco_notifier, so I've tested a line like:

$zco_notifier->attach($this, array('NOTIFY_HEADER_END_CHECKOUT_SUCCESS'));

but nothing in my update() function seems to be getting triggered. In my update function I set up a query to $db to insert some data. Earlier, this worked when I hooked into $_SESSION['cart'] as a sanity check, but nothing happens when attempting to hook into $zc_notifier for the checkout success event. I also tried $this-attach which didn't work either.

I know I'm close, I just can't figure out how to structure my attach statement. Thanks in advance for any advice.

17 May 2008, 12:16 AM
#5
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Re: Custom function upon successful order placement

Bump...

Any ideas at all on this? I can't find any examples of how to hook a function into a successful checkout process. Perhaps I'm just not looking in the right place yet... :-(

17 May 2008, 12:38 AM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,747
Plugin Contributions:
56

Re: Custom function upon successful order placement

Look for SMS on Sale in the downloads area. This shows how to do what you're looking to do; you might want to put it earlier or later in the process, but at least you can get some ideas from looking at this.

Good luck,
Scott

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

17 May 2008, 12:43 AM
#7
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Re: Custom function upon successful order placement

Thanks swguy. I think I may be onto something.... I've successfully attached a notifier using: $zco_notifier->attach($this, array('NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION'));

It's not in the right place yet or doing what I want, but it's a start. I'll post another question if I get stumped...

17 May 2008, 4:45 AM
#8
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Re: Custom function upon successful order placement

OK, I guess I'm stumped... Looking at SMS on Sale was very helpful. What I need to do is get some info about the products purchased, parse that data and then use it to populate a table in another database. The first thing to figure out is how to get at the array (I'm assuming it's an array) of products purchased in the order. I've been searching the code for something resembling $order->info['products']... Is that where I should be looking, or is that info stored elsewhere?

17 May 2008, 5:37 AM
#9
gwixel avatar

gwixel

New Zenner

Join Date:
May 2008
Posts:
23
Plugin Contributions:
0

Re: Custom function upon successful order placement

Aha! I found it... The info I needed is found in $order->products['qty'] and $order->products['model'].