Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Strategy when multiple observers inject content in admin/orders.php

    There are several comments in admin/orders.php advising checking (for example) $extra_headings for (bool) false before initializing $extra_headings, since multiple observers might be injecting content. Suppose there ARE multiple observers from different add-ons injecting content. What strategy should be employed in this case? I suppose if $extra_headings is not (bool) false because observer A injected content, that observer B should add their content to $extra_headings, either at the beginning or end of the array depending on the desired order in the output. But how would an observer writer know the end users desired order? Another possibility might be for the user to control the loading order of the observers. It seems to me that guidance to observer writers is needed to avoid conflicts when $extra_headings is not (bool) false. Or perhaps guidance to users in add-on instructions. Thoughts anyone?

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: Strategy when multiple observers inject content in admin/orders.php

    @Dave224, the approach that I've taken for the heading/content injections is for the watching observers to add their content in the order in which they're loaded (via their associated auto-loader). That way, the outcome is repeatable and, as you indicated, also controllable by adjusting the content-adding plugins' auto-load checkpoints.

    Here's a section from one such plugin, showing how I handle the header-addition (content-addition uses a similar approach):
    Code:
                // -----
                // Issued by /admin/orders.php when generating the orders' listing, allowing the
                // insert of an additional column heading.  
                //
                // On entry:
                //
                // $p2 ... Contains a reference to the $extra_headings array, to be returned in the
                //         following format:
                //
                // $extra_headings = array(
                //     array(
                //       'align' => $alignment,    // One of 'center', 'right', or 'left' (optional)
                //       'text' => $value
                //     ),
                // );
                //
                // Note:  Be sure to check that the $p2/$extra_headings value is specifically (bool)false before initializing, since
                // multiple observers might be injecting content!
                //
                case 'NOTIFY_ADMIN_ORDERS_LIST_EXTRA_COLUMN_HEADING':
                    if ($p2 === false) {
                        $p2 = array();
                    }
                    $p2[] = array(
                        'align' => 'center',
                        'text' => MYPLUGIN_ORDERS_HEADING_STATUS
                    );
                    break;

  3. #3
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Strategy when multiple observers inject content in admin/orders.php

    Slick! I was thinking if--then--else, but your approach is better. Thanks!

 

 

Similar Threads

  1. Replies: 1
    Last Post: 9 Sep 2009, 12:11 PM
  2. Canada Post Mod vs SQL INJECT alert with SHOPPING_CART.php
    By imfsub12 in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 1 Oct 2008, 08:52 PM
  3. inject new order from outside php source
    By kender in forum General Questions
    Replies: 2
    Last Post: 8 Jun 2008, 02:08 PM
  4. How can I keep orders in admin in US$ when I offer multiple currencies in the store?
    By lankeeyankee in forum Customization from the Admin
    Replies: 2
    Last Post: 19 Mar 2008, 01:54 PM
  5. Using Observers instantiated from application-top.php?
    By enigmabomb in forum General Questions
    Replies: 7
    Last Post: 24 Jan 2008, 10:29 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR