Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    154
    Plugin Contributions
    0

    Default Observer Notifier NOTIFIER_CART_GET_PRODUCTS_END Help

    Hi all knowledgeable and intellectually imbued peoples

    I would like to sort the contents of my shopping cart alphabetically by name. I know how to do this by modifying the core file (/includes/classes/shopping_cart.php) as I've shown here: http://www.zen-cart.com/forum/showthread.php?t=181068

    As I've just begun to look into using observers/notifiers I figured I should write it properly so as not to modify core files.

    Now I'm totally stumped!!!

    From the other thread, you can see that I need to do a sort on the values in array $products_array before it is returned by the get_products() method.

    I am tying into NOTIFIER_CART_GET_PRODUCTS_END that is triggered just before the $shopping_cart->get_products method returns the $products_array content.



    1) How can I get access to the $products_array content from within my observer class so that I can run the sort on it?

    2) How can I pass the newly sorted array back into $shopping_cart->get_products so that it returns the sorted cart details back to its original calling source?

    3) Or should I be approaching this completely differently?

    Thanks,
    Celtic

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Observer Notifier NOTIFIER_CART_GET_PRODUCTS_END Help

    In your shopping_cart class I think you'll need to change the 3 references to $products_array to $this->products_array instead, and then it'll be available for manipulation in your observer class and any changes you make to it will pass back automatically.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Feb 2010
    Posts
    154
    Plugin Contributions
    0

    Default Re: Observer Notifier NOTIFIER_CART_GET_PRODUCTS_END Help

    Thanks DrB, but that's a no-go unfortunately.

    Here's what I've got in the update method...


    PHP Code:
        function update( &$class$eventID$paramsArray ) {
                echo 
    "one...";
                
    print_r($class->products_array);
                echo 
    "...two...";
                
    print_r($this->products_array);
                echo 
    "...three...";
                
    print_r($products_array);
                echo 
    "...four...";
                global 
    $products_array;
                
    print_r($products_array);
                echo 
    "...done!";
                
    //exit;
                //return "YO DUDE!";
        

    Any other thoughts?

    Thanks,
    Celtic

 

 

Similar Threads

  1. v151 Multiple Observer Classes for Same Notifier Event
    By Dave224 in forum General Questions
    Replies: 6
    Last Post: 8 Jul 2013, 11:07 PM
  2. Observer Noob help?
    By absurdparadox in forum All Other Contributions/Addons
    Replies: 6
    Last Post: 17 Mar 2010, 05:40 PM
  3. Notifier/Observer problem editing Real World Example 1
    By dale88 in forum Templates, Stylesheets, Page Layout
    Replies: 23
    Last Post: 12 Mar 2010, 02:03 AM
  4. observer/notifier the "base" class
    By David Bo in forum Basic Configuration
    Replies: 1
    Last Post: 3 Apr 2007, 02:23 AM
  5. Is notifier/observer system good for this?
    By s_p_ike in forum General Questions
    Replies: 5
    Last Post: 7 Aug 2006, 10:16 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