Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Mar 2004
    Posts
    201
    Plugin Contributions
    0

    Default question about debug HP Warning: Invalid argument supplied for foreach() php

    here is my debug file and i am wondering if this will effect any orders i may have come in..
    [08-Dec-2021 13:11:48 UTC] Request URI: /index.php?main_page=shopping_cart, IP address: 114.119.140.196
    #1 require(/includes/templates/kandi/templates/tpl_shopping_cart_default.php) called at [/includes/templates/kandi/common/tpl_main_page.php:181]
    #2 require(/includes/templates/kandi/common/tpl_main_page.php) called at [/index.php:94]
    --> PHP Warning: Invalid argument supplied for foreach() in /includes/templates/kandi/templates/tpl_shopping_cart_default.php on line 69.
    THis is line 69 of the tpl-shopping_cart_default.php
    foreach ($productArray as $product) {
    thank you
    noppie
    My Multi_Site Zen Carts
    http://herasonlinemarket.com

  2. #2
    Join Date
    Jul 2012
    Posts
    16,488
    Plugin Contributions
    17

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Quote Originally Posted by noppie View Post
    here is my debug file and i am wondering if this will effect any orders i may have come in..

    THis is line 69 of the tpl-shopping_cart_default.php


    thank you
    noppie
    The expectation is no, it should not prevent a customer that has product in their cart from being able to make a purchase/order to come in. That said, continued logging of this issue *may* result in a problem that prevents customer use of the site by filling the logs folder and meeting/exceeding a limit set by the host.

    Somewhat surprising to see is how $productArray may not be defined as an array (basic issue being reported). $productArray is populated in includes/modules/pages/shopping_cart/header_php.php **WHEN** the cart includes one or more product. In absence of a product in the cart, visiting index.php?main_page=shopping_cart results in $productArray not being declared as anything which will cause the issue reported as logged.

    It appears that prior to for loop within includes/modules/pages/shopping_cart/header_php.php, the variable $productArray should be assigned to an empty array. This way visiting the shopping cart page with no product in the cart will not provide the logged issue identified.

    Perhaps for others reviewing this thread, it may be helpful if you were to identify the PHP version that is also being used. In earlier PHP versions, this would not have been identified as a logged error in normal operation (a notice would be generated, but ignored because it was only a notice)...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,427
    Plugin Contributions
    11

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Quote Originally Posted by mc12345678 View Post

    Somewhat surprising to see is how $productArray may not be defined as an array (basic issue being reported). $productArray is populated in includes/modules/pages/shopping_cart/header_php.php **WHEN** the cart includes one or more product. In absence of a product in the cart, visiting index.php?main_page=shopping_cart results in $productArray not being declared as anything which will cause the issue reported as logged.

    It appears that prior to for loop within includes/modules/pages/shopping_cart/header_php.php, the variable $productArray should be assigned to an empty array. This way visiting the shopping cart page with no product in the cart will not provide the logged issue identified.
    while in theory true, in looking at the code, i would say the template is at fault.

    this rudimentary error would easily have been caught if in fact it was part of a generic ZC install and would not be part of the base.

    this line here:

    https://github.com/zencart/zencart/b...efault.php#L16

    in the default template ensures that the foreach does not get run.

    whether this specific template has that check remains to be seen.

    as to whether initializing an empty array to ensure an error does not happen on a particular template.... meh.

    as to refactoring the whole repo so that all vars get properly initialized (and then remove all the count and empty checks), could be an interesting discussion that i doubt will prove fruitful....
    mxWorks now has premium plugins
    are you using square? have you shown any appreciation with cake on venmo or on paypal?
    called the savior by the chief bottle washer...

  4. #4
    Join Date
    Jul 2012
    Posts
    16,488
    Plugin Contributions
    17

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Quote Originally Posted by carlwhat View Post
    while in theory true, in looking at the code, i would say the template is at fault.

    this rudimentary error would easily have been caught if in fact it was part of a generic ZC install and would not be part of the base.

    this line here:

    https://github.com/zencart/zencart/b...efault.php#L16

    in the default template ensures that the foreach does not get run.

    whether this specific template has that check remains to be seen.

    as to whether initializing an empty array to ensure an error does not happen on a particular template.... meh.

    as to refactoring the whole repo so that all vars get properly initialized (and then remove all the count and empty checks), could be an interesting discussion that i doubt will prove fruitful....
    Can't argue there, though could be the actual tpl_ file, the header_php.php file, a plugin that observes the notifier(s), etc...

    As to initialization allowing other code removal, not likely. The code tends to be written/rewritten so that either side of the issue can be "updated" to an out-dated data set. Yes, I did focus in *a lot* on the one variable and I missed the cross assignment variable that seems like it could show up while distracted. It is obvious that there is some level of modification the that associated file because it is copied over to the template path.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Mar 2004
    Posts
    201
    Plugin Contributions
    0

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    this is the php verison is PHP Version 7.4.26

    and the template version is
    responsive_classic that came with the zencart 1.5.7c

    Quote Originally Posted by mc12345678 View Post
    Can't argue there, though could be the actual tpl_ file, the header_php.php file, a plugin that observes the notifier(s), etc...

    As to initialization allowing other code removal, not likely. The code tends to be written/rewritten so that either side of the issue can be "updated" to an out-dated data set. Yes, I did focus in *a lot* on the one variable and I missed the cross assignment variable that seems like it could show up while distracted. It is obvious that there is some level of modification the that associated file because it is copied over to the template path.
    My Multi_Site Zen Carts
    http://herasonlinemarket.com

  6. #6
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,427
    Plugin Contributions
    11

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Quote Originally Posted by noppie View Post
    ...
    [08-Dec-2021 13:11:48 UTC] Request URI: /index.php?main_page=shopping_cart, IP address: 114.119.140.196
    #1 require(/includes/templates/kandi/templates/tpl_shopping_cart_default.php) called at [/includes/templates/kandi/common/tpl_main_page.php:181]
    #2 require(/includes/templates/kandi/common/tpl_main_page.php) called at [/index.php:94]
    Quote Originally Posted by noppie View Post
    and the template version is responsive_classic that came with the zencart 1.5.7c
    your debug log would suggest otherwise. see bold.
    mxWorks now has premium plugins
    are you using square? have you shown any appreciation with cake on venmo or on paypal?
    called the savior by the chief bottle washer...

  7. #7
    Join Date
    Jul 2012
    Posts
    16,488
    Plugin Contributions
    17

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    I was going to add: I'm not going to argue about the current template, but as pointed out, the log file clearly identifies that the name of the template that was active at the time is something else (kandi). Whether the files in that template were copied from the responsive_classic folder or not, or modified or not. That all is information that is to be provided. Please note that by always addressing the items in the posting tips, response time and problem solution can be much faster/easier...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Mar 2004
    Posts
    201
    Plugin Contributions
    0

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Quote Originally Posted by carlwhat View Post
    your debug log would suggest otherwise. see bold.
    so the template name can not be changed for easier use.. it is the responsive template.. the NAME WAS CHANGED. the template is the exact responsive template that came with 1.5.7c
    for . I am pretty sure that i would know what template i used. and this is the only error or warning on in my debug file.
    My Multi_Site Zen Carts
    http://herasonlinemarket.com

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

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Quote Originally Posted by noppie View Post
    so the template name can not be changed for easier use.. it is the responsive template.. the NAME WAS CHANGED. the template is the exact responsive template that came with 1.5.7c
    for . I am pretty sure that i would know what template i used. and this is the only error or warning on in my debug file.
    noppie,
    while what you say may be true, please tell me how we are supposed to know that? we are merely going off the logs that you posted. simple.

    you are more than welcome to change the template name. and if you are adept at changing the name that you should be adept at debugging your problem as there is plenty of data in this thread to help.

    perhaps someone else can help you. a default install of ZC using the responsive classic should not ever hit line 69; but yet you are.

    i would suggest re-reading all of the helpful data in this thread and see if you can figure out where you went astray.
    mxWorks now has premium plugins
    are you using square? have you shown any appreciation with cake on venmo or on paypal?
    called the savior by the chief bottle washer...

  10. #10
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    8,973
    Plugin Contributions
    119

    Default Re: question about debug HP Warning: Invalid argument supplied for foreach() php

    Going off Zen Cart 1.5.7c with the responsive_classic template:
    tpl_shopping_cart_default.php line 19 does a check for a non-empty cart:

    if ($flagHasCartContents) {

    this `if` branch includes the line that's showing an error

    foreach ($productArray as $product) {

    but you should not be entering this branch if you have an empty cart.
    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.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 3 Jul 2013, 04:00 AM
  2. Replies: 7
    Last Post: 4 Jan 2013, 09:21 PM
  3. Debug: USPS.php PHP Warning: Invalid argument supplied for foreach()
    By divinelighting in forum Addon Shipping Modules
    Replies: 2
    Last Post: 11 Jun 2011, 03:17 AM
  4. Warning: Invalid argument supplied for foreach
    By harlyman in forum General Questions
    Replies: 9
    Last Post: 23 Aug 2006, 11:39 AM
  5. Replies: 7
    Last Post: 31 Jul 2006, 04:03 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