0){ $productinfo = mysql_fetch_array($result,MYSQL_ASSOC); } #get the product options, if they exist. $sql = "SELECT p1.id AS os_id, p2.id AS op_id, p1.name, p1.mandatory, p2.name AS o_name, p2.sku, p2.pricediff, p1.orderindex, p2.orderindex AS op_orderindex "; $sql .= "FROM com_product_option p1, com_product_option_value p2 "; $sql .= "WHERE p1.productid = '$id' AND p1.id = p2.productoptionid "; $sql .= "ORDER BY p1.orderindex, p1.id, p2.orderindex"; $result = mysql_query($sql); ShowDBError($sql); while($myrow=mysql_fetch_array($result,MYSQL_ASSOC)){ if ($myrow['name']!=$current_name){ $os_counter++; $op_counter = 1; $current_name = $myrow['name']; $optionsets[$myrow['os_id']]['name'] = $myrow['name']; $optionsets[$myrow['os_id']]['mandatory'] = $myrow['mandatory']; } $optionsets[$myrow['os_id']]['options'][$myrow['op_id']]['name'] = $myrow['o_name']; $optionsets[$myrow['os_id']]['options'][$myrow['op_id']]['pricediff'] = $myrow['pricediff']; $op_counter++; } #get the category name $sql = "SELECT section, name as category_name FROM com_productcategory WHERE id = '" . $productinfo['categoryid'] . "'"; $result = mysql_query($sql); ShowDBError($sql); if (mysql_affected_rows() > 0){ $myrow = mysql_fetch_array($result,MYSQL_ASSOC); $section = $myrow["section"]; $category_name = $myrow["category_name"]; } if ($_POST['submit']){ if (trim($quantity)==""){ $b_quantity_blank = true; }else{ $validregex = "^[[:digit:]]+$"; if (!preg_match('~'.$validregex.'~',$quantity)){ $b_quantity_invalid = true; } } if (!$b_quantity_blank and !$b_quantity_invalid){ #If there are option sets, make sure the mandatory ones are selected. if (is_array($optionsets)){ foreach($optionsets as $os_id=>$os_data){ if ($os_data['mandatory'] and !$_POST['s_optionsets'][$os_id]){ $empty_os_set[]=$os_id; } } } if (!is_array($empty_os_set)){ #Store the product w/selected options in the cart. if (is_array($_POST['s_optionsets'])){ foreach ($_POST['s_optionsets'] as $s_id=>$s_value){ if (!$s_value){ unset($_POST['s_optionsets'][$s_id]); } } if (!empty($_POST['s_optionsets'])){ ksort($_POST['s_optionsets']); } } if (is_array($_SESSION['cartvalues'])){ #See if this exact same product is already in the cart, with the exact same options selected, if so #remove the item from the cart foreach($_SESSION['cartvalues'] as $c_id=>$c_data){ if ($c_data['id']==$id){ if ($c_data['s_optionsets'] and is_array($_POST['s_optionsets']) and !empty($_POST['s_optionsets'])){ unset($os_comp1); unset($os_comp2); foreach($c_data['s_optionsets'] as $s_k=>$s_v){ $os_comp1 .= $s_k . ":" . $s_v . ":"; } foreach($_POST['s_optionsets'] as $s_k=>$s_v){ $os_comp2 .= $s_k . ":" . $s_v . ":"; } if ($os_comp1==$os_comp2){ unset($_SESSION['cartvalues'][$c_id]); } }elseif(!$c_data['s_optionsets'] and (!is_array($_POST['s_optionsets']) or empty($_POST['s_optionsets']))){ unset($_SESSION['cartvalues'][$c_id]); } } } } if (is_array($_SESSION['cartvalues']) and !empty($_SESSION['cartvalues'])){ #Re-index the array $counter = 1; foreach($_SESSION['cartvalues'] as $c_id=>$c_data){ $n_cartvalues[$counter] = $c_data; $counter++; } $_SESSION['cartvalues'] = $n_cartvalues; $cart_index = count($_SESSION['cartvalues']) + 1; }else{ $cart_index = 1; } $_SESSION['cartvalues'][$cart_index]['id'] = $id; $_SESSION['cartvalues'][$cart_index]['quantity'] = number_format($quantity); if (is_array($_POST['s_optionsets']) and !empty($_POST['s_optionsets'])){ $_SESSION['cartvalues'][$cart_index]['s_optionsets'] = $_POST['s_optionsets']; } if ($_REQUEST['return_page']){ $redirectlink = $_REQUEST['return_page']; }else{ $redirectlink = "/store/shoppingcart.php"; } redir($redirectlink); } } }else{ $quantity = 1; } if ($_SESSION['cartvalues']){ foreach($_SESSION['cartvalues'] as $c_id=>$c_data){ if ($c_data['quantity']){ $cart_quantity = $cart_quantity + $c_data['quantity']; }else{ $cart_quantity = 0; } } } include_once PROJECT_TMPL . "/store/product.tmpl"; ?>