Home > Software engineering >  shopping cart oscommerce
shopping cart oscommerce

Time:08-11

I want to retrieve products_tax_class_ids in checkout payment page in OSCommerce shopping cart software. E.g., the user has 20 items in his shopping cart and if any of product has products_tax_class_id = 30, the site will warn him.

This code is not working.

$tax = tep_db_query("select products_tax_class_id 
                    from " . TABLE_PRODUCTS . " 
                    where products_id = '".$card[$products_id]."'");

while ($warn = tep_db_fetch_array($tax)) {
    if (warn== '30') { 
        echo "attention ....";
    } 
    else { 
        echo "..."
    }
}

How can I compare tax_class_id of products?

CodePudding user response:

You didn't point name of field in while loop.

$tax = tep_db_query("select products_tax_class_id 
                    from " . TABLE_PRODUCTS . " 
                    where products_id = '".$card[$products_id]."'");

while ($warn = tep_db_fetch_array($tax)) {
    if ($warn['products_tax_class_id'] == '30') { 
        echo "attention ....";
    } 
    else { 
        echo "..."
    }
}

And word "card" should be a "cart" I think...

CodePudding user response:

/**************************************************************************/
//Add following function in includes/functions/general.php
/**************************************************************************/

function tep_get_products_tax($product_id) {
    global $languages_id;

    if (empty($language)) $language = $languages_id;

    $product_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '".$product_id."'");
    $product = tep_db_fetch_array($product_query);

    return $product['products_tax_class_id'];
  }


/**************************************************************************/
//Add following code in checkout_payment.php
/**************************************************************************/
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i  ) {
  if (tep_get_products_tax($products[$i]['id']) == 30) {
    echo "attention ....";
break
  }
}
/**************************************************************************/
//EOD
/**************************************************************************/  
  • Related