PDA

View Full Version : Shirt Size Determines Price


chris199437
04-27-2009, 12:52 PM
I am using a static cart and I would like if the user chooses 2XL it would give them a different price than if they would have chose a Medium size from a drop list. Please help.

Ray Borduin
04-27-2009, 12:59 PM
I'd probably add a column called XLPrice to the cart, then update the price calculation to:

TotalPrice = (([Size]=="2XL")?[XLPrice]:[Price]) * [Quantity]

chris199437
04-27-2009, 01:32 PM
I can't seem to have my display page update the items except quantity. I have a product and when you choose size then color then quantity and add to cart it's fine. But when I click Continue shopping and it goes back to that page it will only update the quantity and not a different size or color on my display page?

chris199437
04-27-2009, 01:55 PM
Now it won't load the page and gives me an error on line 167. Here is what is on line 167

itmObj.TotalPrice = ((itmObj.Size=="2XL")?itmObj.XXLPrice:itmObj.Price) * itmObj.Quantity'c

Ray Borduin
04-27-2009, 02:29 PM
Do you have columns named "Size" and "XXLPrice"? This looks correct. What is the error you get?

chris199437
04-27-2009, 02:32 PM
Yes I do, here is the error

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
C:\INETPUB\VDWWWROOT\HOTCAKESINC.COM\FBB\../WA_eCart/FBB_Cart_Store_VB.asp, line 167, column 34

http://www.hotcakesinc.com/fbb/store1.asp

Ray Borduin
04-27-2009, 03:05 PM
oh... vbscript. My answer would work in php or javascript, but not vbscript.

vbscript would be:
TotalPrice = ((abs([Size]="2XL")*[XLPrice])+(abs([Size]<>"2XL")*[Price])) * [Quantity]

chris199437
04-27-2009, 03:23 PM
Well the page will load now but it still does not show $38.25 for a 2XL it shows it as the $35.25 price (which is set for Price) (I have a column call XXLPrice and set it to 38.25). Please help??

http://www.hotcakesinc.com/fbb/store1.asp

Ray Borduin
04-27-2009, 04:51 PM
OK, you probably want to add calculations like this:

TruePrice = ((abs([Size]="2XL")*[XLPrice])+(abs([Size]<>"2XL")*[Price]))
TotalPrice = ((abs([Size]="2XL")*[XLPrice])+(abs([Size]<>"2XL")*[Price])) * [Quantity]

Then on your page show the value of TruePrice instead of Price and it should work. Is the column total correct now?

Ray Borduin
04-27-2009, 04:53 PM
You will also want to mark size and color as unique columns in the cart columns section.

chris199437
04-28-2009, 06:03 AM
Mostly working. Now I need formulas for 2XL, 3XL, 4XL & 5XL options. I really appreciate it all the time you've spent helping a programmed challenged person like me. For some reason the Price is showing up as $0.00, but I'll try and look into that if you can help me out with those formulas. Thanks!

chris199437
04-28-2009, 06:27 AM
OK, stumped on why Price column doesn't show TruePrice, just $0.00

Ray Borduin
04-28-2009, 07:34 AM
What is the code you are using to display the TruePrice? Have you uploaded your cart files since updating it?

chris199437
04-28-2009, 07:39 AM
I have uploaded/updated store1.asp & store2.asp with asset files. Here is the code I have for the display cart Price area

<tr>
<td><%=WA_eCart_DisplayInfo(FBB_Cart_Store, "Name")%></td>
<td><%=WA_eCart_DisplayInfo(FBB_Cart_Store, "Description")%></td>
<td class="eC_PriceItem" ><%=WA_eCart_DisplayMoney(FBB_Cart_Store, WA_eCart_DisplayInfo(FBB_Cart_Store, "TruePrice"))%></td>
<td class="eC_FormItem" ><input type="text" name="FBB_Cart_Store_Quantity_<%=FBB_Cart_Store.DisplayIndex%>" size="3" value="<%=WA_eCart_DisplayInfo(FBB_Cart_Store, "Quantity")%>" /></td>
<td class="eC_FormItem" ><input type="checkbox" value="<%=WA_eCart_DisplayInfo(FBB_Cart_Store, "ID")%>" name="FBB_Cart_Store_Delete_<%=FBB_Cart_Store.DisplayIndex%>" /></td>
<td class="eC_PriceItem" ><%=WA_eCart_DisplayMoney(FBB_Cart_Store, WA_eCart_DisplayInfo(FBB_Cart_Store, "TotalPrice"))%></td>
</tr>

Ray Borduin
04-28-2009, 07:45 AM
That looks correct, so what does the code look like where those two columns are defined?

TotalPrice seems to work, so it is something wrong with the TruePrice calculation.

chris199437
04-28-2009, 07:48 AM
<tr>
<td><%=WA_eCart_DisplayInfo(FBB_Cart_Store, "Name")%></td>
<td><%=WA_eCart_DisplayInfo(FBB_Cart_Store, "Description")%></td>
<td class="eC_PriceItem" ><%=WA_eCart_DisplayMoney(FBB_Cart_Store, WA_eCart_DisplayInfo(FBB_Cart_Store, "TruePrice"))%></td>
<td class="eC_FormItem" ><input type="text" name="FBB_Cart_Store_Quantity_<%=FBB_Cart_Store.DisplayIndex%>" size="3" value="<%=WA_eCart_DisplayInfo(FBB_Cart_Store, "Quantity")%>" /></td>
<td class="eC_FormItem" ><input type="checkbox" value="<%=WA_eCart_DisplayInfo(FBB_Cart_Store, "ID")%>" name="FBB_Cart_Store_Delete_<%=FBB_Cart_Store.DisplayIndex%>" /></td>
<td class="eC_PriceItem" ><%=WA_eCart_DisplayMoney(FBB_Cart_Store, WA_eCart_DisplayInfo(FBB_Cart_Store, "TotalPrice"))%></td>
</tr>

chris199437
04-28-2009, 07:50 AM
Sorry, is this what you needed:

class FBB_Cart_Store_ItemDefinition
'columns
public ID'n√
public Name't
public Description't
public Weight'w
public Quantity'n
public Price'c
public Size't√
public Color't√
public XXLPrice'c
'calculations
public TotalWeight'w
public TotalPrice'c
public TruePrice'c
public FullDetails't
end class
%>
<%
function FBB_Cart_Store_ResetCalculations(itmObj)
itmObj.TotalWeight = itmObj.Weight * itmObj.Quantity'w
itmObj.TotalPrice = ((abs(itmObj.Size="2XL")*itmObj.XXLPrice)+(abs(itmObj.Size<>"2XL")*itmObj.Price)) * itmObj.Quantity'c
itmObj.TruePrice = ((abs(itmObj.Size="2XL")*itmObj.XXLPrice)+(abs(itmObj.Size<>"2XL")*itmObj.Price))'c
itmObj.FullDetails = itmObj.Quantity & " " & itmObj.Name & " (" & itmObj.ID & ")"'t
set FBB_Cart_Store_ResetCalculations = itmObj
end function

chris199437
04-28-2009, 08:00 AM
Obviously I make columns for each one. But what would be the calculation forumla I would need to use. Also, Can I use the same calculation formula if I offered 4xL & 5xL or if those options were not allowed on an item?

Ray Borduin
04-28-2009, 08:18 AM
Well... now that you tell me that you want to support 3XL, 4XL, and 5XL, I might do this differently to make it easier.

To prevent confusing the forumulas and creating so many extra columns and calculations, I would probably use a hidden field and some javascript on the form to greatly simplify what I need to do in the cart.

You could remove all of the XXLPrice columns and TruePrice calculation fields entirely and change TotalPrice back to [Price] * [Quantity].

Then go to your form and add a hidden form element for the size and change the values in the size dropdown list so that they pass the price like:

<hidden name="FBB_Cart_Store_1_Size_Add" id="FBB_Cart_Store_1_Size_Add" value="Small">
<select name="FBB_Cart_Store_1_Price_Add" onchange="document.getElementById('FBB_Cart_Store_1_Size_Add ').value = this.options[this.selectedIndex].text">
<option value="35.25" selected>Small</option>
<option value="35.25">Medium</option>
<option value="35.25">Large</option>
<option value="35.25">XL</option>
<option value="38.25">2XL</option>
</select>


Then use the lightning bolt to set the value of the price field to come from the list.

This way the correct price is passed in directly instead of being calculated.

chris199437
04-28-2009, 08:56 AM
I'm sorry:
Here is my form code:
<form name="FBB_Cart_Store_1_ATC_1" method="POST" action="<%=cStr(Request.ServerVariables("SCRIPT_NAME"))%><%=WA_eCart_IIf((Request.ServerVariables("QUERY_STRING") <> ""), "?" & Request.ServerVariables("QUERY_STRING"), "")%>">
<input type="hidden" name="FBB_Cart_Store_1_ID_Add" value="1" >
<input type="text" name="FBB_Cart_Store_1_Quantity_Add" value="1" size="4" >

<input type= "hidden" name="FBB_Cart_Store_1_Size_Add" id="FBB_Cart_Store_1_Size_Add" value="Small">
<select name="FBB_Cart_Store_1_Price_Add" onchange= "document.getElementById('FBB_Cart_Store_1_Size_Add ').value = this.options[this.selectedIndex].text">
<option value="35.25" selected>Small</option>
<option value="35.25">Medium</option>
<option value="35.25">Large</option>
<option value="35.25">XL</option>
<option value="38.25">2XL</option>
</select>
<select name="FBB_Cart_Store_1_Color_Add">
<option value="White" selected>White</option>
<option value="Black">Black</option>
</select>
<input type="submit" value="Add to Cart" name="FBB_Cart_Store_1_ATC">
</form>

Now how do I get it to pass the Size along with the correct price? Do I go to my display on store2.asp and set the bindings to what? Everything comes up as size Small.

Ray Borduin
04-28-2009, 09:02 AM
This is because of the space in:

onchange="document.getElementById('FBB_Cart_Store_ 1_Size_Add').value

I guess the forum added that in my sample code to help with line breaks or maybe I had a typo.

chris199437
04-28-2009, 09:31 AM
Thank you ray!!!!

lee365928
08-31-2009, 09:08 AM
You start out giving help based on PHP but then change to vbscript. Will the following code work for both? If not, what would I need to change to make it work in PHP?

<hidden name="my_site_1_Size_Add" id="my_site_1_Size_Add" value="Small">
<select name="my_site_1_Price_Add" onchange="document.getElementById('my_site_1_Size_Add').valu e = this.options[this.selectedIndex].text">
<option value="35.25" selected>Small</option>
<option value="35.25">Medium</option>
<option value="35.25">Large</option>
<option value="35.25">XL</option>
<option value="38.25">2XL</option>
</select>

Ray Borduin
08-31-2009, 09:24 AM
This code is all html and javascript, so the server language wouldn't matter.

lee365928
09-02-2009, 11:52 AM
When I add the above code to my page, it doesn't change the price. It always displays the price that was defined in the add to cart server behavior. Is there something else I need to add? It's also a static cart (mysql/php).

Ray Borduin
09-02-2009, 12:45 PM
You would have to update your add to cart server behavior so that the price was set from the list you added. That list will submit different prices and it can be used to update the cart.

lee365928
09-03-2009, 06:34 AM
How would I go about doing that? When I click on the Add to Cart server behavior, the following code is now listed under the size option. "<?php echo $_POST["mycart_1_Size_Add"]; ?>"

What should I change that to? I also assume I need to change the price variable?

Thanks again.

Ray Borduin
09-03-2009, 08:18 AM
I thought we were talking about making sure your price was set correctly, not the size?

You would want to update your price to:
<?php echo $_POST["my_site_1_Price_Add"]; ?>

lee365928
09-03-2009, 09:04 AM
We were. When I added the hidden field code and then clicked on my add to cart server behavior, that code was now listed as my size variable.

Ray Borduin
09-03-2009, 09:06 AM
That looks right for your size variable, but you will have to use client size javascript to populate the hidden size field onchange of the list.

lee365928
09-03-2009, 09:25 AM
Sorry, but I'm getting confused. Here is my code as it stands now.

<form name="mycart_1_ATC_137" 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="mycart_1_ID_Add" value="146" />
<strong class="Grey_Links"> Size</strong><span class="Grey_Links"><strong>
<hidden name="mycart_1_Size_Add" id="mycart_1_Size_Add" value="Small">
<select name="mycart_1_Price_Add" onchange="document.getElementById('mycart_1_Size_Add').value = this.options[this.selectedIndex].text">
<option value="18.00">Small</option>
<option value="18.00">Medium</option>
<option value="18.00" selected="selected">Large</option>
<option value="18.00">Extra Large</option>
<option value="18.00">2X Large</option>
<option value="19.00">3X Large</option>
</select>
<br />
<br />
Quantity</strong></span>
<input type="text" name="mycart_1_Quantity_Add" value="1" size="4" >
</p>
<p>&nbsp;</p>
<p>
<input type="image" src="WA_eCart/Images/Pacifica/Btn1_EN_addtocart.gif" border="0" value="Add to Cart" name="mycart_1_ATC" alt="Add to Cart">
</p>
</form>

Ray Borduin
09-04-2009, 04:22 PM
The problem probably started when jumping in to someone elses post and trying to use a code chunk defined for their specific scenario.

The add to cart works with the form and the server code in conjunction. I can't spot a problem with one without looking at both and even then a description of the precise problem and what you need help on is usually necessary.