Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default including constants and arrays from Catalog into Admin: breaking change in ZC157 ?

    Messy to describe, but here goes....

    I have a constants file in catalog extra_definitions which contains an array list of constant names, and the corresponding constant definitions.
    eg:

    PHP Code:
    descr_stringlist = ["ATEQ_TPMS_UPDATE""ATEQ_TPMS_COMPANY"
    (with 300+ constant names).

    Product descriptions use these constant names and when a product is viewed, the description is parsed and these constant names are replaced by their text definitions: they are used for boilerplate functionality.
    The parsing is done by a function in catalog.
    This is working in shopfront.

    In admin, when trying to display the parsed/replaced description in product preview, I have an error as the array of the constants "does not exist".
    The catalog constants file is included in the admin by a file in

    admin1\includes\languages\english\extra_definitions\boilerplate_text_pointer.php

    It is correctly found and included, as a constant used from the same file can be used, but the array defined in that file "does not exist".
    It's as though the array is being unset/not allowed/sanitised??

    It works in ZC156.

    This chunk from ZC156 is missing from init_languages in ZC157:
    if ($za_dir = @dir(DIR_WS_LANGUAGES . $_SESSION['language'] . '/extra_definitions')) {
    while ($zv_file = $za_dir->read()) {
    if (preg_match('~^[^\._].*\.php$~i', $zv_file) > 0) {
    require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/extra_definitions/' . $zv_file);
    }
    }
    $za_dir->close();
    }
    But since the catalog file IS being loaded via /extra_definitions, I assume this functionality is implemented elsewhere and I presume where the array is being unset...but I don't see where.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

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

    Default Re: including constants and arrays from Catalog into Admin: breaking change in ZC157

    Quote Originally Posted by torvista View Post
    Messy to describe, but here goes....

    I have a constants file in catalog extra_definitions which contains an array list of constant names, and the corresponding constant definitions.
    eg:

    PHP Code:
    descr_stringlist = ["ATEQ_TPMS_UPDATE""ATEQ_TPMS_COMPANY"
    (with 300+ constant names).
    steve,
    i acknowledge i do a log of "messy" stuff, so i would like to help.

    what you have described above is not a constant. constants are defined by a define statement. i would review:

    https://www.php.net/manual/en/language.constants.php

    you example above looks to be a variable; but it is missing a `$` before the name, so your code example would fail to me. constants can not be reset; vars can be.

    Quote Originally Posted by torvista View Post
    In admin, when trying to display the parsed/replaced description in product preview, I have an error as the array of the constants "does not exist".
    The catalog constants file is included in the admin by a file in

    admin1\includes\languages\english\extra_definitions\boilerplate_text_pointer.php

    It is correctly found and included, as a constant used from the same file can be used, but the array defined in that file "does not exist".
    It's as though the array is being unset/not allowed/sanitised??

    It works in ZC156.

    This chunk from ZC156 is missing from init_languages in ZC157:

    But since the catalog file IS being loaded via /extra_definitions, I assume this functionality is implemented elsewhere and I presume where the array is being unset...but I don't see where.
    if you do not see an unset, it is not happening where you do not see it. i would be highly surprised if the code posted is the piece that is causing you your grief...

    my understanding on sanitizing is that only happens on $_GET and $_POST vars; it will not happen from vars from within a script. if not true, perhaps someone with more knowledgeable can chime in...

    the idea that it works on v156 but not on v157.... i'm sure there is a page somewhere on the docs that can tell you the difference....

    if you have positively identified that the code from the catalog side is properly loaded (could the var defined in that file in fact have been defined in some other random file on the admin side), i would look closely at the definitions and then look to see where it might be getting unset if that is in fact what is happening. unless your var has a common name used elsewhere in ZC,i find it unlikely that ZC is un-setting it.

    hope that helps.

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

  3. #3
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: including constants and arrays from Catalog into Admin: breaking change in ZC157

    thanks

    but it is missing a `$` before the name
    My typo, it is $desc_stringlist.

    So to be more concise, the file structure is

    descr_stringlist = ["CONSTANT_123", "CONSTANT_124", ......]
    followed by
    define ('CONSTANT_123', 'text for 123');
    define ('CONSTANT_124', 'text for 124');
    etc.

    So if I include the catalog file from admin product preview, all works.
    So if I include the catalog file from a file in admin\includes\languages\english\extra_definitions\, the constants get included, but the variable not.

    Not a deal breaker, but in my experience investigating these oddities is often of value in itself.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

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

    Default Re: including constants and arrays from Catalog into Admin: breaking change in ZC157

    Quote Originally Posted by torvista View Post
    Not a deal breaker, but in my experience investigating these oddities is often of value in itself.
    hardly an oddity. this is a scoping issue.

    exploring the scope and how it may have changed from 1 version to another; well that would all be in the auto loaders of zc.

    i think understanding scoping is of more value and solving your issue.

    https://www.php.net/manual/en/langua...nts.syntax.php

    you might be able to define your array as another constant as constants can be arrays. else u can use the super global as var, of which i am personally not a fan.

    else u can refactor your code to only include your vars when you need them.

    learning about php variable scoping could be of value.

    https://phppot.com/php/variable-scope-in-php/

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

  5. #5
    Join Date
    Jul 2012
    Posts
    16,719
    Plugin Contributions
    17

    Default Re: including constants and arrays from Catalog into Admin: breaking change in ZC157

    Quote Originally Posted by torvista View Post
    Messy to describe, but here goes....

    I have a constants file in catalog extra_definitions which contains an array list of constant names, and the corresponding constant definitions.
    eg:

    PHP Code:
    descr_stringlist = ["ATEQ_TPMS_UPDATE""ATEQ_TPMS_COMPANY"
    (with 300+ constant names).

    Product descriptions use these constant names and when a product is viewed, the description is parsed and these constant names are replaced by their text definitions: they are used for boilerplate functionality.
    The parsing is done by a function in catalog.
    This is working in shopfront.

    In admin, when trying to display the parsed/replaced description in product preview, I have an error as the array of the constants "does not exist".
    The catalog constants file is included in the admin by a file in

    admin1\includes\languages\english\extra_definitions\boilerplate_text_pointer.php

    It is correctly found and included, as a constant used from the same file can be used, but the array defined in that file "does not exist".
    It's as though the array is being unset/not allowed/sanitised??

    It works in ZC156.

    This chunk from ZC156 is missing from init_languages in ZC157:

    But since the catalog file IS being loaded via /extra_definitions, I assume this functionality is implemented elsewhere and I presume where the array is being unset...but I don't see where.
    Quote Originally Posted by carlwhat View Post
    hardly an oddity. this is a scoping issue.

    exploring the scope and how it may have changed from 1 version to another; well that would all be in the auto loaders of zc.

    i think understanding scoping is of more value and solving your issue.

    https://www.php.net/manual/en/langua...nts.syntax.php

    you might be able to define your array as another constant as constants can be arrays. else u can use the super global as var, of which i am personally not a fan.

    else u can refactor your code to only include your vars when you need them.

    learning about php variable scoping could be of value.

    https://phppot.com/php/variable-scope-in-php/

    best.
    To go with this, on the admin side, the LanguageLoader class "becomes" responsible for loading the language files as incorporated at the end of admin/includes/init_includes/init_languages.php:
    Code:
    // include the language translations
    $languagePage = ($PHP_SELF == 'home.php') ? 'index.php' : $PHP_SELF;
    $languageLoader = new LanguageLoader($installedPlugins, $languagePage);
    $languageLoader->loadlanguageDefines();
    What this does (somewhat unfortunately for the current code in your language file), is to require_once the extra_definitions files from within a method of the class. (The LanguageLoader class can be found at includes/classes/ResourceLoaders/LanguageLoader.php)

    In order for such a variable (which is not a define) to come into the global space, it must be brought into the global space by at least either of two means within your language file:
    Code:
    global $descr_stringlist;
    
    $descr_stringlist = ["ATEQ_TPMS_UPDATE", "ATEQ_TPMS_COMPANY"];

    or:
    Code:
    $GLOBALS['descr_stringlist'] = ["ATEQ_TPMS_UPDATE", "ATEQ_TPMS_COMPANY"];
    Either of these would be backwards compatible as well.
    The only "issue" with making the variable into define arrays is that they will become "locked" as compared to the use of an array which can have items replaced/overloaded...
    Last edited by mc12345678; 9 Nov 2020 at 04:05 PM.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: including constants and arrays from Catalog into Admin: breaking change in ZC157

    thanks, much food for thought there.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  7. #7
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: including constants and arrays from Catalog into Admin: breaking change in ZC157

    In the end I settled for
    - defining the array of the constant names in a file in /extra_datafiles
    - defining the constants in a language file, not auto-included to prevent unnecessary loading
    - using a function to include and parse those constants for descriptions, only when required.

    So everything non-core is in plain sight for upgrades.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

 

 

Similar Threads

  1. v151 Order Total GV Not Working and Breaking in Admin
    By philip937 in forum General Questions
    Replies: 13
    Last Post: 29 Oct 2013, 07:59 PM
  2. v151 php arrays for inserting into one database field
    By delia in forum General Questions
    Replies: 8
    Last Post: 11 Sep 2013, 03:27 PM
  3. Replies: 7
    Last Post: 14 Jul 2008, 01:39 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