Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default PHP Warning: Undefined variable

    Vanilla 1.5.8a installation running on PHP 8.1.13 logging the following:

    PHP Warning: Undefined variable $meta_products_price in /Users/zcdev/Sites/localhost/158atest/includes/modules/meta_tags.php on line 290.
    Managing Director of https://jsweb.uk

    Zen Cart developer since 2009

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,703
    Plugin Contributions
    123

    Default Re: PHP Warning: Undefined variable

    Are you sure includes/modules/YOURTEMPLATE/meta_tags.php is based on includes/modules/meta_tags.php ?
    I can't see a code path that yields this error.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default Re: PHP Warning: Undefined variable

    Quote Originally Posted by swguy View Post
    Are you sure includes/modules/YOURTEMPLATE/meta_tags.php is based on includes/modules/meta_tags.php ?
    I can't see a code path that yields this error.
    Agreed, that variable's initialized to an empty string on line 164 of the else clause that wraps line 290.

  4. #4
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: PHP Warning: Undefined variable

    Quote Originally Posted by swguy View Post
    Are you sure includes/modules/YOURTEMPLATE/meta_tags.php is based on includes/modules/meta_tags.php ?
    I can't see a code path that yields this error.
    It's a clean install of 158a using Responsive Classic.
    Managing Director of https://jsweb.uk

    Zen Cart developer since 2009

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

    Default Re: PHP Warning: Undefined variable

    Quote Originally Posted by lat9 View Post
    Agreed, that variable's initialized to an empty string on line 164 of the else clause that wraps line 290.
    i have my dev box running v158 with the responsive classic template; using php 8.1.12.

    i am not able to reproduce this error. nor do i see what url the OP used to recreate this error. i tested any number of pages, including product pages where in theory this code would get executed.

    in looking at the code, i agree that i do not understand how this var could potentially be undefined.

    i also do not understand how a ZC developer since 2009 could not figure this one out on their own.

    perhaps i am missing something?
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  6. #6
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: PHP Warning: Undefined variable

    Quote Originally Posted by carlwhat View Post

    i also do not understand how a ZC developer since 2009 could not figure this one out on their own. ?
    Perhaps you would prefer that I fix any potential bugs in core code or modules myself and never bother to advise the dev team or original module author? That completely goes against the ethos of open source coding.

    Reporting something doesn't imply that I can't "figure it out", and indeed, the variable shouldn't get to a situation where it is undefined, but clearly it is as it's there in the logs. I'll look into it further and when I find the cause I'll deal with it.
    Managing Director of https://jsweb.uk

    Zen Cart developer since 2009

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

    Default Re: PHP Warning: Undefined variable

    Quote Originally Posted by strelitzia View Post
    I'll look into it further and when I find the cause I'll deal with it.
    given that 3 contributors to his project have weighed in on this issue, i would hope that once you find the cause, you would share your findings here.

    i can only speak for myself, and i know i am interested... and it would seem to be the ethical thing to do.

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

  8. #8
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: PHP Warning: Undefined variable

    Quote Originally Posted by carlwhat View Post
    given that 3 contributors to his project have weighed in on this issue, i would hope that once you find the cause, you would share your findings here.

    i can only speak for myself, and i know i am interested... and it would seem to be the ethical thing to do.

    best.
    It IS possible for $meta_products_price to be undefined.

    Code:
    if (META_TAG_INCLUDE_PRICE == '1' and !strstr($_GET['main_page'], 'document_general')) {
            error_log("point 1");
            if ($product_info_metatags->fields['product_is_free'] != '1') {
              error_log("point 2");
              if (zen_check_show_prices() == true) {
                error_log("point 3");
                $meta_products_price = zen_get_products_actual_price($product_info_metatags->fields['products_id']);
                $prod_is_call_and_no_price = ($product_info_metatags->fields['product_is_call'] == '1' && $meta_products_price == 0);
                $meta_products_price = (!$prod_is_call_and_no_price ? SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($product_info_metatags->fields['products_tax_class_id'])) : '');
              }
            } else {
              error_log("point 4");
              $meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT;
            }
          } else {
            error_log("point 5");
            $meta_products_price = '';
          }
    When testing the scenario, only point 1 and point 2 get logged which means that in this test instance
    Code:
    if (zen_check_show_prices() == true) {
    is obviously not true.
    In those circumstances, nothing defines $meta_products_price

    $meta_products_price also needs to be defined if
    Code:
    zen_check_show_prices()
    is false.

    On the test site, users are required to login to see pricing.
    Last edited by strelitzia; 8 Jun 2023 at 04:54 PM.
    Managing Director of https://jsweb.uk

    Zen Cart developer since 2009

  9. #9
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: PHP Warning: Undefined variable

    The simple fix required is to add an else to the
    Code:
    if (zen_check_show_prices() == true) {
    check so that you end up with
    Code:
    if (META_TAG_INCLUDE_PRICE == '1' and !strstr($_GET['main_page'], 'document_general')) {
            if ($product_info_metatags->fields['product_is_free'] != '1') {
              if (zen_check_show_prices() == true) {
                $meta_products_price = zen_get_products_actual_price($product_info_metatags->fields['products_id']);
                $prod_is_call_and_no_price = ($product_info_metatags->fields['product_is_call'] == '1' && $meta_products_price == 0);
                $meta_products_price = (!$prod_is_call_and_no_price ? SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($product_info_metatags->fields['products_tax_class_id'])) : '');
              } else {
                $meta_products_price = '';
              }
            } else {
              $meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT;
            }
          } else {
            $meta_products_price = '';
          }
    Managing Director of https://jsweb.uk

    Zen Cart developer since 2009

  10. #10
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default Re: PHP Warning: Undefined variable

    Er, the bit that you missed in the first code block you posted is highlighted below (that's line 264 that I referenced above):
    Code:
        } else {
          $meta_products_price = '';
    
          // build un-customized meta tag
          if (META_TAG_INCLUDE_PRICE == '1' and !strstr($_GET['main_page'], 'document_general')) {
            if ($product_info_metatags->fields['product_is_free'] != '1') {
              if (zen_check_show_prices() == true) {
                $meta_products_price = zen_get_products_actual_price($product_info_metatags->fields['products_id']);
                $prod_is_call_and_no_price = ($product_info_metatags->fields['product_is_call'] == '1' && $meta_products_price == 0);
                $meta_products_price = (!$prod_is_call_and_no_price ? SECONDARY_SECTION . $currencies->display_price($meta_products_price, zen_get_tax_rate($product_info_metatags->fields['products_tax_class_id'])) : '');
              }
            } else {
              $meta_products_price = SECONDARY_SECTION . META_TAG_PRODUCTS_PRICE_IS_FREE_TEXT;
            }
          }
    
          if (META_TAG_INCLUDE_MODEL == '1' && !empty($product_info_metatags->fields['products_model'])) {
            $meta_products_name = $product_info_metatags->fields['products_name'] . ' [' . $product_info_metatags->fields['products_model'] . ']';
          } else {
            $meta_products_name = $product_info_metatags->fields['products_name'];
          }
          $meta_products_name = zen_clean_html($meta_products_name);
    
          $meta_products_description = zen_truncate_paragraph(strip_tags(stripslashes($product_info_metatags->fields['products_description'])), MAX_META_TAG_DESCRIPTION_LENGTH);
    
          $meta_products_description = zen_clean_html($meta_products_description);
    
          define('META_TAG_TITLE', str_replace('"','',$review_on . $meta_products_name . $meta_products_price . PRIMARY_SECTION . TITLE . TAGLINE));
          define('META_TAG_DESCRIPTION', str_replace('"','',TITLE . ' ' . $meta_products_name . SECONDARY_SECTION . $meta_products_description . ' '));
          define('META_TAG_KEYWORDS', str_replace('"','',$meta_products_name . METATAGS_DIVIDER . KEYWORDS));
    
        } // CUSTOM META TAGS

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v158 PHP Warning: Undefined variable
    By rattell in forum General Questions
    Replies: 7
    Last Post: 23 Apr 2024, 09:07 PM
  2. v157 PHP Warning: Undefined variable $show_top_submit_button
    By wsworx in forum General Questions
    Replies: 3
    Last Post: 27 Jun 2022, 11:17 AM
  3. v157 Undefined index and undefined variable errors in paypalwpp
    By Dave224 in forum PayPal Express Checkout support
    Replies: 9
    Last Post: 7 Jan 2022, 05:11 PM
  4. Replies: 9
    Last Post: 9 Aug 2021, 06:00 AM
  5. PHP Warning: Use of undefined constant
    By keneso in forum General Questions
    Replies: 5
    Last Post: 24 Aug 2020, 03:48 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