close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

List values in relation to price variants . . .

Thread began 7/17/2009 6:17 pm by wetware | Last modified 7/20/2009 7:01 am by wetware | 6095 views | 14 replies |

wetware

List values in relation to price variants . . .

Kid's Life Vests - three (3) "Sizes" ("Size" column in eCart Object). Infant is $20/ea.; Child & Youth are $17/ea. As of now, the "Value" (below) shows up in the Shopping Cart under "Size" (which is desired), but the prices need to be translated separately into the "Price" column individually (Add to Cart "Price" default is now set to $20).
Here's the existing code in the "Form" area:
<input type="hidden" name="eCart1_1_ID_Add" value="0" >
<input type="text" name="eCart1_1_Quantity_Add" value="1" size="4" >
<select name="eCart1_1_Size_Add">
<option value="Size" selected="selected">Select Size</option>
<option value="Infant">Infant</option>
<option value="Child">Child</option>
<option value="Youth">Youth</option>
</select>
Thanks in advance . . .

Sign in to reply to this post

bjgarner241692

You need a database
But you can probably make this work if you put the price in the VALUE part of your Select List and then set Price to the Select field in your Add to Cart Behaviour.

Storing this info in a db will make your management of the data much easier in the future and it makes working with eCart easier too.

Sign in to reply to this post

wetware

Echoing the Value field . . .

. . . the "Value" field is what is shown in the "Size" column in the Shopping Cart - it's necessary to show the "Size", not the price there.
Of course, I don't know what is meant by "set the Price to the Select field". I'm attempting to understand the theories of PHP, but . . .

Sign in to reply to this post

CraigRBeta Tester

Not sure if I understand correctly, but..

could you not concatenate the size and price in the dropdown as the 'label' and the price as the 'value' ?

or if you have a url I may understand better.

Sign in to reply to this post

wetware

Hi there . . .

. . . concatenate is something I've read/seen, but applying it here is another kettle of fish. It's used to put two string values together(?), but I do not know how that applies here . . .
The page in question is:
TWF_Product_RevereDetail-002.php
Everything rolls through fine, as long as the price for each of the three (3) selections in the list are the same (default Price in Add to Cart bindings being $20, or whatever). But, the Shopping Cart needs to continue to display the text description in the "Size" column, while translating the price differences to the "Price" column.
I am unable to achieve this, because (mainly) I do not know/understand how to construct, let alone place, the PHP in the page . . .
The following may/may not be part way there:
<?php
$Infant-20;
$Child=17;
$Youth=17;
?>
Thanks again for taking the time!

Sign in to reply to this post

CraigRBeta Tester

retrieve list/menu label value ?

Ok, ignore the concatenate thing for now, it is generally cosmetic.

what i think you are trying to achieve is have a list/menu in your add to cart form, having the price as the value and the size as the label.

when you submit the form, you want to retrieve both the selected size AND the price, to pass into your cart.

I have done this with a javascript function before, but my javascript isn't my strong point. I think Ray Borduin showed me the syntax a while ago.

if this looks like the thing, i'll take a proper look.

regards

Sign in to reply to this post

wetware

Hi there!

Yeah, mon - price as the value and the size as the label . . .
These days the only thing that I specialize in is re-reading others' posts & trying to adapt. I'm an old prepress operator who has a design biz & is trying to tie together some programming skills.
Thanks, again . . .

Sign in to reply to this post

CraigRBeta Tester

try this...

You need to store the label string value as a hidden field in the add to cart form, setting a default value, (this value is only updated onchange in this example).

eg <input type="hidden" name="label" value="Small" >

In this example, the list/menu is called listsize and calls a js function called 'getlabelstring' as follows....

<select name="listsize" onchange="getlabelstring()">
<option value="10">Small</option>
<option value="20">Medium</option>
<option value="30">Large</option>
</select>

the javascript function to retrieve the list label should go in the head section of your page.

the function has the general structure as below, just substitute the formname, listbox name and hidden fields accordingly

document.formname.label.value=document.formname.listbox.options[document.formname.listbox.selectedIndex].text

in this example, my add to cart form is called gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?> the listbox is called listsize, the label is called label, so the function is like this...

<script type="text/javascript">
/* <![CDATA[ */
function getlabelstring(){

document.gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?>.label.value = document.gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?>.listsize.options[document.gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?>.listsize.selectedIndex].text;

}
/* ]]> */
</script>


now set the size in the add to cart behavior... $ATC_itemSize = "".$_POST["label"] ."";// column binding#



if you wish to display the price as well as the size in the list label, eg

<select name="listsize" onchange="getlabelstring()">
<option value="10">Small ($10.00)</option>
<option value="20">Medium ($20.00)</option>
<option value="30">Large ($30.00)</option>
</select>

you would need to do some string manipulation to extract the appropriate substring from the label.

eg to extract all characters until the space

<script type="text/javascript">
/* <![CDATA[ */
function getlabelstring(){

var firstbit = document.gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?>.listsize.options[document.gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?>.listsize.selectedIndex].text;

firstbit = firstbit.split(" ");

document.gallerybasket_1_ATC_<?php echo $row_rsdetail["ID"]; ?>.label.value = firstbit[0];

}
/* ]]> */
</script>

(I haven't tested this if js is disabled, the price will still calculate ok, but I presume that the size info from the label will not.)

:)

Sign in to reply to this post

wetware

Wow!

It's gonna take a second (study & implement), but I'll get back to you with results!
Thanks, man . . .

Sign in to reply to this post

wetware

Results . . .

. . . with the following code:
•HTML head:
<script type="text/javascript">
/* <![CDATA[ */
function getlabelstring(){

document.eCart1_1_ATC_0<?php echo $row_rsdetail["ID"]; ?>.label.value = document.eCart1_1_ATC_0<?php echo $row_rsdetail["ID"]; ?>.listsize.options[document.eCart1_1_ATC_0<?php echo $row_rsdetail["ID"]; ?>.listsize.selectedIndex].text;

}
/* ]]> */
</script>
•HTML body:
<!--storing label string value in a hidden field in the Add to Cart form - this value is only updated onchange
-->
<input type="hidden" name="label" value="Select Size" >
<!--list/menu is called listsize and calls a js function called getlabelstring
-->
<select name="listsize" onchange="getlabelstring()">
<option selected="selected">Select Size</option>
<option value="20">Infant</option>
<option value="17">Child</option>
<option value="17">Youth</option>
</select>
•Add to Cart "Size" binding (default value):
<?php echo $_POST["eCart1_1_Size_Add"]; ?>
•Live Result:
The "Size" column is displayed correctly (Infant, Child, or Youth) but the "Price" column says "0" . . .
I'm thinking that a javascript term is used incorrectly?
TWF_Product_RevereDetail-002.php

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...