View Full Version : product option problems
stevesmith373400
03-31-2009, 03:07 PM
I am trying to put in product options. I have a table, "options" that lists all the options for every product. The options are identified by a group id # 1,2,3, etc. I am working on a category page and want the options to be shown here. Not every product on the page has options and there are different options for different products. When I do a recordset, "rsfoptions", it returns all of the options. When I look at the page in my browser every product has every option. I need help with the codinging . Ecart is not too user friendly on these things. I have pasted the recordset code below.
SELECT *
FROM options INNER JOIN items on items.optid=options.optgrpid
WHERE itemid=param
name=param
type=numeric
default value= 0
runtime value=$run_rsfrozen['itemid']
"itemid" is the pk column in the items (or product table). This table has a column identifing the option group id.
Any advice would be greatly appreciated.
stevesmith373400
04-01-2009, 08:58 AM
Are there any video tutorials available on this topic?
Ray Borduin
04-01-2009, 08:59 AM
You can't refer to a recordset value directly as a parameter in DW recordsets.
One technique I have used is to add code above the recordset like:
<?php
$_GET['tempitemid'] = $run_rsfrozen['itemid'];
?>
Then set the parameter runtime value to: $_GET['tempitemid']
stevesmith373400
04-01-2009, 09:44 AM
I have seen this before but it doesn't seem to work for me. I believe my tables are not set up right. Could you suggest a sample table set up using multiple products with multiple options. Some products with no options, some products with unique options and some with shared options. Just names and columns would help. I know it is asking a lot. I have a good handle on relational databases but this has me boggled.
Ray Borduin
04-01-2009, 09:51 AM
products table would have a productID autonumber and no reference to options as well as whatever other fields you want to track on a product by product basis.
optionsgroup table would have the option groupID autonumber and a groupName field, and that is it.
productoptions table would have the productOptionID autonumber, a productOptionGroupID (join to groupID) and optionProductID (join to products) and that is it.
options table would have an optionID autonumber and a optionGroupID (join to groupID) as well as any other information specific to this option.
This would give you complete flexability with regards to the database (and a relative nightmare when it comes to writing queries and a back end if you aren't experienced)
stevesmith373400
04-01-2009, 10:21 AM
Thanks. I will need to work through this. Let me ask you what may be a dumb question. I will have two recordsets per page. One that sorts the page to the right category and then one that will get the options. Even though I highlight the first recordset, I cannot determin in the code where one stops and the other begins in order to insert the get code you gave me.
Here is the code that highlights when either is selected. If you could indicate at what point I need to insert the " <?php
$_GET['tempitemid'] = $run_rsfrozen['itemid'];
?> " that would be great.
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_aysconn, $aysconn);
$query_rsfrozen = "SELECT * FROM items WHERE itemcatid = '9'";
$rsfrozen = mysql_query($query_rsfrozen, $aysconn) or die(mysql_error());
$row_rsfrozen = mysql_fetch_assoc($rsfrozen);
$totalRows_rsfrozen = mysql_num_rows($rsfrozen);
$param_rsfoptions = "0";
if (isset($run_rsfrozen['itemid'])) {
$param_rsfoptions = (get_magic_quotes_gpc()) ? $run_rsfrozen['itemid'] : addslashes($run_rsfrozen['itemid']);
}
mysql_select_db($database_aysconn, $aysconn);
$query_rsfoptions = sprintf("SELECT * FROM options INNER JOIN items on items.optid=options.optgrpid WHERE items.itemid=%s", GetSQLValueString($param_rsfoptions, "int"));
$rsfoptions = mysql_query($query_rsfoptions, $aysconn) or die(mysql_error());
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
$totalRows_rsfoptions = mysql_num_rows($rsfoptions);
?>
stevesmith373400
04-01-2009, 11:30 AM
I have redone my tables and they match the ecommerce recipe example, which was not very clear or helpful, exactly. (By the way, in their example they use the run time value of $run_rsfrozen['itemid'].) I have tried your method. I put the $_GET['tempitemid'] in the runtime value. I then put the other php code in every possible place at the top of the page. It makes no difference. Every item still shows every possible option intstead of the options that are set for it. Here is the code. What do you think?
<?php
//WA eCart Include
require_once("WA_eCart/ayscart_PHP.php");
?><?php require_once('Connections/aysconn.php'); ?>
<?php
$ayscart->GetContent();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_aysconn, $aysconn);
$query_rsfrozen = "SELECT * FROM items WHERE itemcatid = '9'";
$rsfrozen = mysql_query($query_rsfrozen, $aysconn) or die(mysql_error());
$row_rsfrozen = mysql_fetch_assoc($rsfrozen);
$totalRows_rsfrozen = mysql_num_rows($rsfrozen);
$param_rsfoptions = "0";
if (isset($_GET['tempitemid'] )) {
$param_rsfoptions = (get_magic_quotes_gpc()) ? $_GET['tempitemid'] : addslashes($_GET['tempitemid'] );
}
mysql_select_db($database_aysconn, $aysconn);
$query_rsfoptions = sprintf("SELECT * FROM itemopt INNER JOIN options on options.itemoptid=itemopt.itemoption WHERE itemitemid=%s", GetSQLValueString($param_rsfoptions, "int"));
$rsfoptions = mysql_query($query_rsfoptions, $aysconn) or die(mysql_error());
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
$totalRows_rsfoptions = mysql_num_rows($rsfoptions);
?>
<?php
// WA eCart AddToCart
if (isset($_POST["ayscart_1_ATC"]) || isset($_POST["ayscart_1_ATC_x"])) {
$ATC_itemID = $_POST["ayscart_1_ID_Add"];
$ATC_AddIfIn = 0;
$ATC_RedirectAfter = "cart.php";
$ATC_RedirectIfIn = "";
if (isset($totalRows_rsfrozen) && $totalRows_rsfrozen > 0) {
$row_rsfrozen = WAEC_findRecordMySQL($rsfrozen, "itemid", $ATC_itemID);
if ($row_rsfrozen) {
$ATC_itemName = "".$row_rsfrozen['itemname'] ."";// column binding
$ATC_itemDescription = "".$row_rsfrozen['itemshortdesc'] ."";// column binding
$ATC_itemWeight = floatval("0");// column binding
$ATC_itemQuantity = "".$_POST["ayscart_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_rsfrozen['itemprice'] ."");// column binding
$ATC_itemOption = "".$_POST["ayscart_1_Option_Add"] ."";// column binding
mysql_data_seek($rsfrozen, 0);
$row_rsfrozen = mysql_fetch_assoc($rsfrozen);
}
}
$ATC_itemQuantity = floatval($ATC_itemQuantity);
if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) {
$ayscart->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice, $ATC_itemOption);
if ($ATC_RedirectAfter != "" && $ayscart->redirStr == "") {
$ayscart->redirStr = $ATC_RedirectAfter;
}
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
}
else {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF'];
}
}
}
?>
<?php
// WA eCart Redirect
if ($ayscart->redirStr != "") {
header("Location: ".$ayscart->redirStr);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/cattemp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Frozen Foods</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="cartcss/tempcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header"><img src="Images/header.gif" /></div>
<div id="content">
<div id="CatSideBar"></div>
<div id="MBody"><!-- InstanceBeginEditable name="mbody" -->Please select your favorite frozen items to keep you cool during your stay.<p><table width="672" height="53" border="1">
<?php do { ?>
<tr>
<td width="205"><?php echo $row_rsfrozen['itemname']; ?></td>
<td width="100"><select name="ayscart_Option_list_<?php echo $ayscart->DisplayIndex; ?>" >
<?php
do {
?>
<option value="<?php echo $row_rsfoptions['optname']?>"><?php echo $row_rsfoptions['optname']?></option>
<?php
} while ($row_rsfoptions = mysql_fetch_assoc($rsfoptions));
$rows = mysql_num_rows($rsfoptions);
if($rows > 0) {
mysql_data_seek($rsfoptions, 0);
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
}
?>
</select></td>
<td width="150"><?php echo $row_rsfrozen['itemshortdesc']; ?></td>
<td width="189"><?php echo $row_rsfrozen['itemprice']; ?></td>
<td width="100"><form name="ayscart_1_ATC_<?php echo $row_rsfrozen["itemid"]; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<p>
<input type="hidden" name="ayscart_1_ID_Add" value="<?php echo $row_rsfrozen["itemid"]; ?>" >
<input type="text" name="ayscart_1_Quantity_Add" value="1" size="4" >
<select name="ayscart_1_Option_Add">
<?php
do {
?>
<option value="<?php echo $row_rsfoptions['optname']?>"><?php echo $row_rsfoptions['optname']?></option>
<?php
} while ($row_rsfoptions = mysql_fetch_assoc($rsfoptions));
$rows = mysql_num_rows($rsfoptions);
if($rows > 0) {
mysql_data_seek($rsfoptions, 0);
$row_rsfoptions = mysql_fetch_assoc($rsfoptions);
}
?>
</select>
<input type="image" src="WA_eCart/Images/Pacifica/Btn5_EN_addtocart.gif" border="0" value="Add to Cart" name="ayscart_1_ATC">
</p>
</form>
</td>
</tr>
<?php } while ($row_rsfrozen = mysql_fetch_assoc($rsfrozen)); ?>
</table>
</p><!-- InstanceEndEditable --></div>
</div>
<div id="footer"><img src="Images/footer-1.gif" /></div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsfrozen);
mysql_free_result($rsfoptions);
?>
Ray Borduin
04-01-2009, 02:06 PM
If that returns all results, then the query:
SELECT * FROM itemopt INNER JOIN options on options.itemoptid=itemopt.itemoption WHERE itemitemid = param
must return all results. Have you tested it in your mysql admin to see if your data is entered correctly. There doesn't appear to be a problem with this page.
You could add:
<?php echo($query_rsfoptions); ?>
This will tell you the exact query it is using. Why it returns so many results I guess could be a data integrity issue in the database.
stevesmith373400
04-02-2009, 11:59 AM
I spoke to the tech guys and basically they told me that you can't show options on a catalog page with out serious hand coding. So I am trying another tactic. I want to insert a text field in the add to cart button form that the customer can type in the desired option. I can insert the field but I can't seem to get the typed in result to show in the cart display page. Do you have any thoughts. I made sure the field was included in the ATC button form. I believe I bound it to the option column but it still does not produce the results. Any thoughts?
Ray Borduin
04-02-2009, 12:03 PM
A few possible problems:
1) You didn't upload your cart with the new column
2) You didn't update your add to cart server behavior
3) You didn't drag/drop the column onto the display page to be displayed
It is probably one of those.
A correction is that you really don't need hand coding to get options working. You need to use native DW functionality and hand written SQL to access your options from your database. No physical writing of php should be necessary, but that doesn't mean it isn't complex.
stevesmith373400
04-02-2009, 12:16 PM
I appreciate the help but the Web Assist technician said you can't put in an options recordset that keys off of a repeating region recordset through dreamweaver. The options recordset would only pick up the first entry as it is not in the repeat region loop. I am open for clear specific step by step instructions if it can be done though.
stevesmith373400
04-02-2009, 12:32 PM
I the customer added field to work so they can type in their options. I am running with this method but would be interested in any coding suggestions to make the other work.
Thanks again.
Ray Borduin
04-02-2009, 01:33 PM
Copy and paste the secondary recordset from the top of the page so that it is inside the repeat region so that each row can have its own results.
stevesmith373400
04-02-2009, 01:40 PM
The tech said that he has had mixed results with that method. Right now I am going to get the shop up and running with the method that I know will work then go back and play. I am against a major "seasonal" deadline. I will be uploading all of this to godaddy. Is there anything special about that process or is it straight forward?
Thanks again.
Ray Borduin
04-02-2009, 01:47 PM
Copy and pasting the recordset will work as long as you aren't trying to directly refer to the first recordset value in a parameter. You would need to store the parameter as a $_GET[] variable for instance temporarily to get around that problem. The tech guy rightly didn't want to walk you through it and debug it with you, but I assure you it is possible. His mixed results were probably as a result of users mixed abilities in following his instructions.
Unfortunately GoDaddy has some specific requirements because of some of their unique server settings.
What checkout provider and shipping providers are you using? It is likely you will need to cut and paste code into a particular location to get those working properly on GoDaddy. You should probably post a support incident when you are ready to go live including that information and they will guide you through the necessary updates.
stevesmith373400
04-02-2009, 02:22 PM
I will be using authorize.net for my provider. Please forward me the code if you can. I will play a little with the option code as well. Thanks .
Jason Byrnes
04-02-2009, 03:30 PM
in the WA_eCart/Adv_CO_Scripts/AuthNet_PHP.php file locate the following code:
curl_setopt($ch, CURLOPT_POST,1);
and add the following on a new line after it:
//curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, 101, 0);
curl_setopt($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.