skip to Main Content

EDIT: Got it, can’t believe I missed it –

$HTTP_POST_VARS isn’t global, changed it to a parameter to be passed in.

I normally use $_POST but in oscommerce the default is this and so I used that to maintain similarity.

I cannot get this code to work and I have no idea why.

   function check_product_available() {

global $cart;
$products = $cart->get_products();

  //product exclusion
    //check to see if the product is in one of the limited categories
    $check_product_query = tep_db_query( $sql = 'SELECT products_id
                                                 FROM discount_coupons_to_products
                                                 WHERE coupons_id="'.tep_db_input( $HTTP_POST_VARS['couponcart'] ).'"' );
    $exlproducts = array();
    if( tep_db_num_rows( $check_product_query ) > 0 ) {
      while( $products = tep_db_fetch_array( $check_product_query ) ) {
        $exlproducts[] = $products['products_id'];
      }
  }
        for ($i=0, $n=sizeof($products); $i<$n; $i++) {
    if( in_array( $products[$i]['id'], $exlproducts ) ) {
      //use this to debug exclusions:
      return false;
    } 
    }
    return true;
  }
  //end product exclusion

I have tried moving the loops around and it still always returns true. I have echoed out the products array and id is in there and ran the sql query hardcoding the coupon id and it also works fine.

2

Answers


  1. Chosen as BEST ANSWER

    Got it....

    $HTTP_POST_VARS isn't global, changed it to a parameter to be passed in.


  2. Your for loop makes no sense as it will only loop one time. Returning a value will end all other execution. What you probably want is to return false when it is in the array and true in all other conditions.

    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
        if( in_array( $products[$i]['id'], $exlproducts ) ) {
            //use this to debug exclusions:
            return false;
        }
    }
    return true;
    

    Edit: You really should not use $HTTP_POST_VARS anymore.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search