Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,682
    Plugin Contributions
    9

    Default encapsulated plugins require question....

    using a v157 base install.... i'm working on new admin plugin...

    lets say there i have a class file, that is in:

    zc_plugins/myplugin/1.0.0/admin/includes/classes/class.php

    i now want to require() a new script in this class file. previously i might do something like

    PHP Code:
    require_once DIR_FS_ADMIN .  'includes/classes/other_class.php'
    when i look at the $_SERVER vars, available to me, nothing pinpoints where i am in the file system to refer to new files that ideally i would like to keep in my encapsulated plugin.

    is there an easy way to accomplish this goal? i'm guessing there is a ZC var that knows where i am. as i do not...

    thanks in advance.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: encapsulated plugins require question....

    There isn't any special function or variable for that as far as I recall.

    But if the file is in the same or nearby directory structure, you could explore using relative paths with ../.. etc.

    However, your post raises a question, and understanding context would help:
    WHY are you requiring another file from within a class? Perhaps it's better to put your other desired file code into a class of its own and then simply refer to the class?
    .

    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
    Nov 2005
    Location
    los angeles
    Posts
    2,682
    Plugin Contributions
    9

    Default Re: encapsulated plugins require question....

    Quote Originally Posted by DrByte View Post
    There isn't any special function or variable for that as far as I recall.

    But if the file is in the same or nearby directory structure, you could explore using relative paths with ../.. etc.

    However, your post raises a question, and understanding context would help:
    WHY are you requiring another file from within a class? Perhaps it's better to put your other desired file code into a class of its own and then simply refer to the class?
    drByte, thanks for the input. it seems:

    PHP Code:
    $path_info pathinfo(__FILE__)['dirname']; 
    works.

    as far as why... whole other can of worms...

    using api wrappers for some of the heavy lifting on common carrier codes rather than hand coding seems to make much more sense to me. and it is actually not within the class, but extending the class prior to the class declaration. ie:

    PHP Code:
    <?php

        $path_info 
    pathinfo(__FILE__)['dirname'];
        if (!
    file_exists($sdk_loader =  $path_info '/prose/vendor/autoload.php')) {
            return 
    false;
        }
        require 
    $sdk_loader;
        require_once 
    $path_info '/prose/shipping.php';

        class 
    ups extends shipping
        
    {
    does that make sense?
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  4. #4
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,682
    Plugin Contributions
    9

    Default Re: encapsulated plugins require question....

    i suppose my next question is whether observers work within the encapsulated plugin?

    my initial testing suggests they do not. or perhaps it is just the auto loading observers that do not work?

    i will try to manually load it.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  5. #5
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,682
    Plugin Contributions
    9

    Default Re: encapsulated plugins require question....

    Quote Originally Posted by carlwhat View Post
    i suppose my next question is whether observers work within the encapsulated plugin?

    my initial testing suggests they do not. or perhaps it is just the auto loading observers that do not work?

    i will try to manually load it.
    i can not get any observers to load from within an observers directory structure. which i suppose is why it is not listed here:

    https://docs.zen-cart.com/dev/plugin...ory_structure/

    it seems that the auto_loaders operates a little differently from within the zc_plugins directory that outside of it.

    it seems that i can make do using a few hacks, but i think being able to load an observer from within the encapsulated directory structure would be a good idea.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: encapsulated plugins require question....

    Quote Originally Posted by carlwhat View Post
    i suppose my next question is whether observers work within the encapsulated plugin?

    my initial testing suggests they do not. or perhaps it is just the auto loading observers that do not work?

    i will try to manually load it.
    In observing did you both load the observer class and instantiate it as well as ensure that the observer is loaded/instantiated before the trigger point of the notifier is reached?

    Also as to the require type condition as DrByte was discussing, the initial portion of the path is not mandated. Note how the admin's index.php file has in it a require includes/application_top.php and not an "admin" related prefix (which of course also doesn't exist at that point in loading the file).
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: encapsulated plugins require question....

    Quote Originally Posted by carlwhat View Post
    PHP Code:
        class ups extends shipping 
    Be careful about declaring a new class named `ups` if the store might already have a `ups` module installed.
    .

    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.

  8. #8
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,682
    Plugin Contributions
    9

    Default Re: encapsulated plugins require question....

    Quote Originally Posted by mc12345678 View Post
    In observing did you both load the observer class and instantiate it as well as ensure that the observer is loaded/instantiated before the trigger point of the notifier is reached?

    Also as to the require type condition as DrByte was discussing, the initial portion of the path is not mandated. Note how the admin's index.php file has in it a require includes/application_top.php and not an "admin" related prefix (which of course also doesn't exist at that point in loading the file).
    i turned the DEBUG_AUTOLOAD on. and i could not get the proper file path to come up with for an observer from within the encapsulated directory. so instantiating it is kind of besides the point.

    file paths are much trickier from within the encapsulated plugins. i'm not sure how much you have played with them. the auto load does a whole bunch of different things which unfortunately i do not have time to debug and play with.

    my testing suggests that currently you will have to do some tricky things from within the auto_loaders config file to get to an observer from within an encapsulated plugin.

    would love for you to prove me wrong or show me the way!

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  9. #9
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: encapsulated plugins require question....

    v158 will support auto-loaded observers
    (https://github.com/zencart/zencart/b..._observers.php)

    But v157 does not.
    For v157 you could use the auto_loaders config files to declare which files/classes to load/instantiate "the old way".
    .

    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.

  10. #10
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: encapsulated plugins require question....

    Quote Originally Posted by DrByte View Post
    There isn't any special function or variable for that as far as I recall.
    zcwilt just mentioned that there does exist a getPluginVersionDirectory() function:

    https://github.com/zencart/zencart/b...ginManager.php

    which is also used in the various methods of
    https://github.com/zencart/zencart/b...InitSystem.php
    .

    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.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v150 Security Question - Letting someone else install plugins
    By mrdmorrison in forum General Questions
    Replies: 6
    Last Post: 5 Aug 2012, 03:44 PM
  2. How do I require an account to use my ask a question addon?
    By eric engler in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 2 Mar 2012, 11:05 PM
  3. Require login to browse question
    By ebaobao in forum General Questions
    Replies: 14
    Last Post: 18 Sep 2010, 07:25 PM
  4. Require new registrants to answer secret question?
    By tsav87 in forum Basic Configuration
    Replies: 2
    Last Post: 21 Jul 2010, 05:30 PM
  5. Adding 'When do you require your order?' question
    By helenthemum in forum Customization from the Admin
    Replies: 0
    Last Post: 11 Oct 2007, 10:22 PM

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