Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Common Notifier for all Pages?

    I've been working on a sidebox to allow selected customers to immediately download a free file. I've installed observer code to process the submit button that initiates the download and used header_start notifiers to kickoff the observer code. However, some page headers don't have a header_start notifier. The featured products page is one example of several page headers without a notifier. In addition, the list of header_start notifiers is long.

    Is there a single notifier common to all pages that exists before headers are written? If I pick say a notifier in the sidebox path, headers have already been written and I get a "headers already written" error.

    If not, can I add a header_start_xxx notifier in the header file of the pages that don't have notifiers? Do I just add the one line notifier call to the header files or are other files involved that need modification? I would also add the header_start_xxx notifier to the observer code. Must the notifier name be unique or can the same notifier exist in multiple files?

    Thanks,
    Dave

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,892
    Plugin Contributions
    96

    Default Re: Common Notifier for all Pages?

    There's (unfortunately) nothing set in the core-code. You could try an alternate path: create an init_include or (kind of cheating) an extra_functions file.

    If you go down the "proper" init_include route, you'll need to create an auto-loader for that file (/includes/auto_loaders/config.your_special_name.php) that (er) loads the initialization file (/includes/init_includes/your_special_name.php. You get to choose when it's loaded (code-point 200 is after all the Zen Cart core is loaded).

    If you go down the simpler extra_function route, all you need to create is the extra_functions php file. All the .php files present in /includes/functions/extra_functions are loaded prior to loading the header_php.php file for the active page (so, prior to headers being written). The limitation is that the extra_functions are loaded fairly early in the page-rendering process and you don't have control over when the file is loaded.

  3. #3
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Common Notifier for all Pages?

    You'd have more options if you were using v155 instead of v151.

    But one way to retrofit v151 to get a hook that happens before any of the header_php.php files fire is to copy the v155 version of /includes/init_includes/init_canonical.php and replace your v151 version with that one. It's backward-compatible, and offers a hook called NOTIFY_INIT_CANONICAL_FINAL
    Unfortunately v151 has less flexibility regarding passed variables, but it can at least listen for that hook, even though it can't pass any updates back.


    Or, you could just put a new file in the extra_functions folder, containing an "attach" to your own unique notifier hook. (Or Lat9's suggestions work too, but with more files)
    .

    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.

  4. #4
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Common Notifier for all Pages?

    Thank you both for your valuable suggestions; each is very elegant. I'm in the process of updating to v155 and can't wait to get there, but I need to complete this mod first. I'll report back with my results.
    Dave

  5. #5
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Common Notifier for all Pages?

    I decided to go with DrByte's init_canonical approach. Took just a few minutes to replace the file and change the notifier in the observer code. Worked perfectly! Thanks again.
    Dave

 

 

Similar Threads

  1. common or shared options for all products (in certain category)
    By sunraise2005 in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 13 Sep 2010, 07:13 AM
  2. Require location of common pages
    By jasonhoward64 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 2 Nov 2009, 03:57 AM
  3. Need EZ pages to be in common folder.
    By EZorb in forum General Questions
    Replies: 4
    Last Post: 9 Aug 2009, 11:52 PM
  4. Common image for all products in a category
    By camioman in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 14 May 2006, 01:34 AM

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