close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

eCart product options (older)

Thread began 3/15/2010 6:59 am by julie.skelton390139 | Last modified 5/13/2010 8:51 pm by Eric Mittman | 3438 views | 39 replies |

julie.skelton390139

eCart product options (older)

Sorry to jump in here, I was not sure whether to start a new thread but I am having a similar problem.

I will be selling photo prints in various sizes, the size effects the price. I have looked through all the various threads and the ecom recipes and just can't seem to figure this out. I have tried all of them out and am getting more and more confused! Seems like such a common thing to need to do on an ecom site but no clear way to do it.

eg of what I need:
Framed print available in small @ £49
medium @ £79
large @ £99
xlarge @ £110

all products will vary in exact size and price, some will not have an extra large version available.

Just read this post and thought it might work for me to add an additional column in the productOptions table for Price, and set these to £49, £79, £99 and £110 as couldn't work out how to add them to the base price. Managed to get the drop down to pick up the size options and tried using the value as the ProductID, but it doesn't pass over the option that the user chooses ie. small to the cart and it still seems to be taking in the base value for the price instead of the one in the productOptions table.

Sorry if this doesn't explain things well but hope you can understand what I need to achieve and how best to do it in detail as really struggling to understand this!

Sign in to reply to this post

Eric Mittman

I moved this post to a new thread so that the original one can be kept more organized, here is a link back to it:

showthread.php?t=11072

It sounds like you are very close to your solution, they key with this type of setup is making sure that you have another recordset on the page that will be filtered on the id of the size. Once you have the extra recordset like this you can edit your add to cart server behavior and in the bindings area pick the column from the cart and use the lightning bolt to select the corresponding value from the new filtered recordset.

Sign in to reply to this post

julie.skelton390139

Sorry I must have missed that my post had been moved so have only just found your reply.

I am still confused! I don't understand when you say about having a recordset that filters by the id of the size? Is this by the urlparameter??? and is this on the product details page or the cart page?

My recordset code is as follows:

<?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;
}
}

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;
}
}

$colname_prints = "-1";
if (isset($_GET['ProductID'])) {
$colname_prints = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductID']);
}
mysql_select_db($database_framed, $framed);
$query_prints = sprintf("SELECT * FROM products WHERE ProductID = %s", GetSQLValueString($colname_prints, "int"));
$prints = mysql_query($query_prints, $framed) or die(mysql_error());
$row_prints = mysql_fetch_assoc($prints);
$totalRows_prints = mysql_num_rows($prints);

$paramOptionID_optionsframed = "-1";
if (isset($_GET['ProductID'])) {
$paramOptionID_optionsframed = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductID']);
}
mysql_select_db($database_framed, $framed);
$query_optionsframed = sprintf("SELECT options.* FROM options INNER JOIN productoptions ON options.OptionID = productoptions.OptionID WHERE options.OptionGroupID = 1 AND productoptions.ProductID = %s", GetSQLValueString($paramOptionID_optionsframed, "int"));
$optionsframed = mysql_query($query_optionsframed, $framed) or die(mysql_error());
$row_optionsframed = mysql_fetch_assoc($optionsframed);
$totalRows_optionsframed = mysql_num_rows($optionsframed);

$colname_productoptions = "-1";
if (isset($_GET['ProductID'])) {
$colname_productoptions = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductID']);
}
mysql_select_db($database_framed, $framed);
$query_productoptions = sprintf("SELECT * FROM productoptions WHERE ProductID = %s", GetSQLValueString($colname_productoptions, "int"));
$productoptions = mysql_query($query_productoptions, $framed) or die(mysql_error());
$row_productoptions = mysql_fetch_assoc($productoptions);
$totalRows_productoptions = mysql_num_rows($productoptions);
?>


I don't know if any of the above is correct, especially the bit about joining the tables as this was taken from another forum thread when I was following a different route. I have tried setting the bindings of the add to cart price column to the field I added to the size options table - this field is called PriceIncrements (although now it is the actual price rather than an addition to the base price). I then went into my ecart options and on the calculations I have changed the TotalPrice to read [PriceIncrement] * [Quantity] - I have the same recordsets in my cart page (I think!) see following:

<?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;
}
}

$colname_photosales = "-1";
if (isset($_GET['ProductID'])) {
$colname_photosales = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductID']);
}
mysql_select_db($database_framed, $framed);
$query_photosales = sprintf("SELECT * FROM products WHERE ProductID = %s", GetSQLValueString($colname_photosales, "int"));
$photosales = mysql_query($query_photosales, $framed) or die(mysql_error());
$row_photosales = mysql_fetch_assoc($photosales);
$totalRows_photosales = mysql_num_rows($photosales);

$colname_productoptions = "-1";
if (isset($_GET['ProductOptionID'])) {
$colname_productoptions = (get_magic_quotes_gpc()) ? $_GET['ProductOptionID'] : addslashes($_GET['ProductOptionID']);
}
mysql_select_db($database_framed, $framed);
$query_productoptions = sprintf("SELECT * FROM productoptions WHERE ProductOptionID = %s", GetSQLValueString($colname_productoptions, "int"));
$productoptions = mysql_query($query_productoptions, $framed) or die(mysql_error());
$row_productoptions = mysql_fetch_assoc($productoptions);
$totalRows_productoptions = mysql_num_rows($productoptions);
?>
<?php
// WA eCart Update
if (isset($_POST["eCart1_Update_100"]) || isset($_POST["eCart1_Update_100_x"])) {
$eCart1->UpdateCart();
$Redirect_redirStr="";
if ($Redirect_redirStr != "") {
$eCart1->redirStr = $Redirect_redirStr;
}
$eCart1->cartAction = "Update";
}
?>


However no price is being taken over to the cart page it is displaying as £0 and also the size is not displaying in the cart? Please help! Getting really lost in this and need a solution quickly.

Sign in to reply to this post

Eric Mittman

I will review the steps that need to be take to implement this, please respond to the step you are on currently and let us know what you have done and what the result is.

1) first make sure that the price for the option is stored in the db, the best would probably be to store it with the record for a particular option, like size large has an extra cost of $x.

2) once you are storing the price along with the option you will need to get your add to cart page setup. You should get this page working without the options affecting the price first.

3) when the add to cart page is working you will want to modify it. The first thing you will do is add a recordset to select the product options. Next you will add in a select list inside of the add to cart form. When you add this list you will populate it from the just created recordset.

4) you should now have a working add to cart page that has a select list for the options. You should ensure that the select list is using the records id as the value and the name of the option as the label.

5) with your options select list on the page you will add another recordset to the page, this new recordset will be like the last options recordset you have on the page but it will be filtered by the posted option id from the options select list.

6) finally, after you have your new filtered recordset in place you will have the options values available to the code on the page. You can get back any info about the option by referencing the newly filtered recordset on the page. You can add the price to the price of the item, or use the options price in place of the regular price, however you would like it to work.

Please review these steps and post back about the one you are at currently. Please post back and let us know what you have tried for that step and the result you are getting. You should not move to the next step until you finish all previous steps.

Sign in to reply to this post

julie.skelton390139

Thanks for your reply. I had already attempted most of what you have outlined although I am concerned some of my recordsets may have been set up incorrectly as I tried to follow some methods in other posts.

so to make things simple, I started again with a new product page and have successfully got up to step 3. I am now going to continue to attempt step 3.

Sign in to reply to this post

julie.skelton390139

just had a go at step 3, I set this up as follows:

Recordset Name: options
Table: productoptions
Columns: All
Filter: ProductID = URL Parameter -ProductID

I assumed last value needed to filter the info otherwise I presume I would end up with all the entries that are in the productoptions table displaying in my dropdown? Is this correct.

With the above I tested my page and the product details page shows the drop down with the 3 size options available for that print.

Moving on to step 5, I am unsure what you mean by:
"this new recordset will be like the last options recordset you have on the page but it will be filtered by the posted option id from the options select list."

What should I select in the Filter dropdowns for this recordset?

Sign in to reply to this post

julie.skelton390139

Ok, had a go at step 5,

I added a third recordset as follows:

Name: Recordset1
Table: productoptions
Columns: All
Filter: ProductOptionID = Form Variable - ProductOptionID

Then in my Add to Cart bindings I set the Size column to <?php echo $row_options['size']; ?> and my PriceIncrement column to <?php echo ((isset($_POST["options"]))?$_POST["options"]:""); ?>

I then added a calculation for RealPrice:
[PriceIncrement] + [Price]

and changed Price to:
[PriceIncrement] + [Price] * [Quantity]

Now the cart page is taking the PriceIncrement from the size option that is selected and then adding these to to give a RealPrice which is displaying in the Price column. However one thing I can't seem to do is get the Size that is chosen to display in the Cart details? Have I done the above correct?

Sign in to reply to this post

Eric Mittman

It looks like you are setting the size column in the cart to the size from your options recordset, instead you will need to bind it to your newly created recordset1. It is the recordset1 that contains the details about the size that the user selected.

This should go for the price increment as well, you should be binding it to the price column from your recordset1 since this is the information for the selected option. If you post back with a copy of this page I can take a look and let you know what I think about the setup.

Sign in to reply to this post

julie.skelton390139

Didn't get your message until just now but have made a bit of progress with trial and error over the last few days.

I changed the drop down manually so it carries over the price and size. I am pretty sure I already tried doing it so that it used recordset1 but that didn't work.

I now have the following for my dropdown:
<option value="<?php echo $row_options['OptionPriceIncrement']?> <?php echo $row_options['size']?>"<?php if (!(strcmp($row_options['OptionPriceIncrement'], $row_Recordset1['size']))) {echo "selected=\"selected\"";} ?>><?php echo $row_options['size']?> - &pound;<?php echo $row_options['OptionPriceIncrement']?></option>

This seems to be working so far, but got to set up the checkout pages next. does the above look ok to you?

Sign in to reply to this post

Eric Mittman

It seems like it is ok to me, it looks like you are dynamically selecting the option based on what is in the recordset though, not sure if this is necessary when a user is making the selections before adding to the cart.

If you are getting the rite result in your cart for the options you are selecting then I would say that it is fine and you are ok to move on to your checkout. Let us know if you have any issues or questions about any of this.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...