Zen Cart Logo
Forums / Bug Reports / [Done v1.6.0] shopping_cart::get_product_id_list function

[Done v1.6.0] shopping_cart::get_product_id_list function

Views: 998

Results 1 to 4 of 4
31 Jul 2015, 3:20 PM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,096
Plugin Contributions:
56

[Done v1.6.0] shopping_cart::get_product_id_list function

The get_product_id_list function in /includes/classes/shopping_cart.php could, if called when the cart is empty, generate a PHP warning based on its call to substr:

  function get_product_id_list() {
    $product_id_list = '';
    if (is_array($this->contents)) {
      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
        $product_id_list .= ', ' . zen_db_input($products_id);
      }
    }
[B]    return substr($product_id_list, 2);[/B]
  }

To prevent the PHP warning+, the code should be changed to:

  function get_product_id_list() {
    $product_id_list = '';
    if (is_array($this->contents)) {
      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
        $product_id_list .= ', ' . zen_db_input($products_id);
      }
    }
[B]    return ($product_id_list == '') ? '' : substr($product_id_list, 2);[/B]
  }
1 Aug 2015, 9:51 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.6.0] shopping_cart::get_product_id_list function

I agree it needs fixing. It's not a critical bug since this function is not used anywhere in Zen Cart core code.

However, since you're clearly contemplating using it, presumably in a plugin, and I can see some value in its existence as a helper function I've submitted a patch for v160 here: https://github.com/zencart/zencart/pull/520 ... albeit I've chosen to fix it in a slightly different fashion than what you proposed.

2 Aug 2015, 12:23 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,096
Plugin Contributions:
56

Re: [Done v1.6.0] shopping_cart::get_product_id_list function

Thanks, DrByte! I'll incorporate your approach to my customizations.

3 Aug 2015, 4:22 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.6.0] shopping_cart::get_product_id_list function

Another update to the PR was made last night.