Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2007
    Posts
    69
    Plugin Contributions
    0

    Default 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

  2. #2
    Join Date
    Jul 2007
    Posts
    69
    Plugin Contributions
    0

    Default 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

  3. #3
    Join Date
    Jul 2007
    Posts
    69
    Plugin Contributions
    0

    Default 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

 

 

Similar Threads

  1. Replies: 5
    Last Post: 22 Aug 2014, 06:58 AM
  2. How to suppress URL &sort= Parameter?
    By rarpsl in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 15 Jan 2012, 11:11 PM
  3. Observers and Session Objects - not getting notified
    By avibodha in forum General Questions
    Replies: 2
    Last Post: 27 Feb 2011, 02:20 AM
  4. Observers and redirects
    By audleman in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 10 Sep 2008, 05:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg