Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Posts
    342
    Plugin Contributions
    7

    Default PHP Warning Account_notification/header_php

    PHP version 7.3 Zencart 1.56c

    Getting the following PHP warning:
    --> PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/domain/httpdocs/includes/modules/pages/account_notifications/header_php.php on line 48.

    Line 48 } elseif (sizeof($products) > 0)

    PHP Code:
    <?php/** * Header code file for the Account Notifications page * * @package page * @copyright Copyright 2003-2019 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: mc12345678 2019 Apr 30 Modified in v1.5.6b $ */// This should be first line of the script:$zco_notifier->notify('NOTIFY_HEADER_START_ACCOUNT_NOTIFICATION');
    if (!zen_is_logged_in()) {  $_SESSION['navigation']->set_snapshot();  zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));}
    require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
    $global_query = "SELECT global_product_notifications                 FROM   " . TABLE_CUSTOMERS_INFO . "                 WHERE  customers_info_id = :customersID";
    $global_query = $db->bindVars($global_query, ':customersID',$_SESSION['customer_id'], 'integer');$global = $db->Execute($global_query);
    if (isset($_POST['action']) && ($_POST['action'] == 'process')) {  if (isset($_POST['product_global']) && is_numeric($_POST['product_global'])) {    $product_global = zen_db_prepare_input($_POST['product_global']);  } else {    $product_global = '0';  }
      (array)$products = $_POST['notify'];
      if ($product_global != $global->fields['global_product_notifications']) {    $product_global = (($global->fields['global_product_notifications'] == '1') ? '0' : '1');
        $sql = "UPDATE " . TABLE_CUSTOMERS_INFO . "            SET    global_product_notifications = :globalProductNotifications            WHERE  customers_info_id = :customersID";
        $sql = $db->bindVars($sql, ':globalProductNotifications',$product_global, 'integer');    $sql = $db->bindVars($sql, ':customersID',$_SESSION['customer_id'], 'integer');    $db->Execute($sql);
      } elseif (sizeof($products) > 0) {    $products_parsed = array();
        foreach ($products as $parse_entry) {      if (is_numeric($parse_entry)) {        $products_parsed[] = $parse_entry;      }    }
        if (sizeof($products_parsed) > 0) {      $check_query = "SELECT count(*) AS total                      FROM   " . TABLE_PRODUCTS_NOTIFICATIONS . "                      WHERE  customers_id = :customersID                      AND    products_id NOT IN (:productsParsed)";
          $check_query = $db->bindVars($check_query, ':customersID',$_SESSION['customer_id'], 'integer');      $check_query = $db->bindVars($check_query, ':productsParsed',implode(',', $products_parsed), 'csv');      $check = $db->Execute($check_query);
          if ($check->fields['total'] > 0) {        $sql = "DELETE FROM " . TABLE_PRODUCTS_NOTIFICATIONS . "                WHERE       customers_id = :customersID                AND         products_id NOT IN (:productsParsed)";
            $sql = $db->bindVars($sql, ':customersID',$_SESSION['customer_id'], 'integer');        $sql = $db->bindVars($sql, ':productsParsed',implode(',', $products_parsed), 'csv');        $db->Execute($sql);      }    }  } else {    $check_query = "SELECT count(*) AS total                    FROM   " . TABLE_PRODUCTS_NOTIFICATIONS . "                    WHERE  customers_id = :customersID";
        $check_query = $db->bindVars($check_query, ':customersID',$_SESSION['customer_id'], 'integer');    $check = $db->Execute($check_query);
        if ($check->fields['total'] > 0) {      $sql = "DELETE FROM " . TABLE_PRODUCTS_NOTIFICATIONS . "              WHERE       customers_id = :customersID";
          $sql = $db->bindVars($sql, ':customersID',$_SESSION['customer_id'], 'integer');      $db->Execute($sql);    }  }
      $messageStack->add_session('account', SUCCESS_NOTIFICATIONS_UPDATED, 'success');
      zen_redirect(zen_href_link(FILENAME_ACCOUNT, '', 'SSL'));}
    /*$products_check_query = "SELECT count(*) AS total                         FROM   " . TABLE_PRODUCTS_NOTIFICATIONS . "                         WHERE  customers_id = :customersID";
    $products_check_query = $db->bindVars($products_check_query, ':customersID',$_SESSION['customer_id'], 'integer');$products_check = $db->Execute($products_check_query);if ($products_check->fields['total'] > 0) $flag_products_check = true;*/
    $counter = 0;$notificationsArray = array();$products_query = "SELECT pd.products_id, pd.products_name                   FROM   " . TABLE_PRODUCTS_DESCRIPTION . " pd,                          " . TABLE_PRODUCTS_NOTIFICATIONS . " pn                   WHERE  pn.customers_id = :customersID                   AND    pn.products_id = pd.products_id                   AND    pd.language_id = :languagesID                   ORDER BY pd.products_name";
    $products_query = $db->bindVars($products_query, ':customersID',$_SESSION['customer_id'], 'integer');$products_query = $db->bindVars($products_query, ':languagesID',$_SESSION['languages_id'], 'integer');$products = $db->Execute($products_query);while (!$products->EOF) {  $notificationsArray[] = array('counter'=>$counter,                                'products_id'=>$products->fields['products_id'],                                'products_name'=>$products->fields['products_name']);  $counter++;  $products->MoveNext();}$flag_products_check = sizeof($notificationsArray);

    $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_ACCOUNT, '', 'SSL'));$breadcrumb->add(NAVBAR_TITLE_2);
    // This should be last line of the script:$zco_notifier->notify('NOTIFY_HEADER_END_ACCOUNT_NOTIFICATION');?>
    Can anyone help thank you

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,522
    Plugin Contributions
    127

    Default Re: PHP Warning Account_notification/header_php

    Edit https://www.zen-cart.com/showthread....ion-header_php
    and change

    } elseif (sizeof($products) > 0) {

    to


    } elseif (!empty($products) > 0) {
    That Software Guy. My Store: Zen Cart Support
    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
    Nov 2005
    Location
    los angeles
    Posts
    2,912
    Plugin Contributions
    13

    Default Re: PHP Warning Account_notification/header_php

    Quote Originally Posted by swguy View Post
    Edit https://www.zen-cart.com/showthread....ion-header_php
    and change

    } elseif (sizeof($products) > 0) {

    to


    } elseif (!empty($products) > 0) {
    • i think your edit url is wrong. were you planning on pointing to the github? as your url is just pointing right back to here.
    • your code correction is confusing. why would you first question if it is not empty, and then compare if it is greater than 0? it seems the greater than 0 is not necessary.
    • is it not possible to properly initialize these vars instead of testing them for what they are supposed to be prior to using? see snippet below.


    PHP Code:
    // change line 35 from:
    (array) $products $_POST['notify'];

    // to:
        
    $products = [];
        if (isset(
    $_POST['notify'])) {
            
    $products $_POST['notify'];
        } 
    the casting to an array is not done when the POST is null. from a code readability, this correction seems better to me. both do work. but i see no need for the greater than 0.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,522
    Plugin Contributions
    127

    Default Re: PHP Warning Account_notification/header_php

    Ugh sorry typing too fast.

    Edit includes/modules/pages/account_notifications/header_php.php

    and change

    } elseif (sizeof($products) > 0) {

    to


    } elseif (!empty($products)) {
    That Software Guy. My Store: Zen Cart Support
    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.

  5. #5
    Join Date
    Jul 2007
    Posts
    342
    Plugin Contributions
    7

    Default Re: PHP Warning Account_notification/header_php

    Thanks to both of you for the help

 

 

Similar Threads

  1. v150 questions about code - header_php.php & main_template_vars.php
    By barricades in forum General Questions
    Replies: 3
    Last Post: 8 May 2012, 06:44 AM
  2. Warning: main(/web/zen-cart/includes/languages/english/modules/payment/header_php.php
    By Coffee1 in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 16 Jul 2009, 07:37 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