Zen Cart Logo
Forums / Basic Configuration / Writing observers and the &$class parameter

Writing observers and the &$class parameter

Locked

Views: 1,398

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
7 Aug 2007, 10:04 PM
#1
audleman avatar

audleman

New Zenner

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

Writing observers and the &$class parameter

Hi,

I am attempting to write an observer to work with a new donation product I'm creating. It attaches to NOTIFIER_CART_ADD_CART_START, called at the beginning of add_cart in shopping_cart.php. What I want it to do is check and see if the product being added is a donation, and if so remove any previous donations in the cart.

Problem is, I'm unsure how to access the ID of the product that's being added. It's passed to the function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {

The update function, here,

function update(&$class, $eventID) {

gets a reference to the class (in this case the shopping cart) passed in, which allows me to access variables defined in the class. But how do I access the parameters of the function?

Thanks,
Kevin

7 Aug 2007, 10:29 PM
#2
audleman avatar

audleman

New Zenner

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

Re: Writing observers and the &$class parameter

Well, I did find a way. I went in to add_cart and rewrote the notify function

It was:

$this->notify('NOTIFIER_CART_ADD_CART_START');

And now it's:

$this->notify('NOTIFIER_CART_ADD_CART_START', array($products_id));

So now I can access $products_id through $paramArray in

function update(&$class, $eventID, $paramArray) {

It works, though I had to modify core code which I don't like to do. Makes for messy upgrades.

Kevin

15 Oct 2008, 6:08 PM
#3
audleman avatar

audleman

New Zenner

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

Re: Writing observers and the &$class parameter

Eventually I re-wrote this so that I didn't have to modify a core file. Instead of passing the shopping cart class through the function, my observer simply utilizes the $_SESSION['cart'] object.

Kevin