To nopcart.js add the following:
- Code: Select all
//-----------------------------------------------------------||
// FUNCTION: AddOneOfManyToCart ||
// PARAMETERS: Form Object PRODUCTSELECTOR ||
// RETURNS: Product parameters to order form ||
// PURPOSE: selects one of many products with different size, ||
// cost, shipping and/or tax to add to shopping cart ||
//-----------------------------------------------------------||
function AddOneOfManyToCart(formToUpdate)
{
selectedObj = formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex];
nameVal = selectedObj.getAttribute("name");
if (nameVal == "select") {
alert('Please select an option');
return false;
}
formToUpdate.NAME.value = nameVal;
costVal = selectedObj.getAttribute("cost");
formToUpdate.PRICE.value = costVal;
id_numVal = selectedObj.getAttribute("id_num");
formToUpdate.ID_NUM.value = id_numVal;
shippingVal = selectedObj.getAttribute("shipping");
formToUpdate.SHIPPING.value = shippingVal;
switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) {
}
AddToCart(formToUpdate);
}
//-----------------------------------------------------------||
Then to your product page add this
- Code: Select all
<!-- -=#=-=#=- start of item -->
<A name="33251"></A>
<IMG src="./images/CB500b.jpg" alt="Sheep Dip" width="100" height="145" border="0"><BR>
<B>Product Selector Mod & & $1.00 and $10.00</B>
This product tests the AddOneOfManyToCart(this.form) function<BR><BR>
<!--Shopping Cart Begin-->
<form name=order>
<input name="PRICE" type=hidden id="PRICE" value="">
<input name=NAME type=hidden id="NAME" value="">
<input name=ID_NUM type=hidden id="ID_NUM" value="">
<input type=hidden name="SHIPPING" value="0.00">
<select name="PRODUCTSELECTOR">
<option selected name="select">Please select size</option>
<option cost="1.00" id_num="33251" name="1L bottle Sheep Dip" shipping="1.00">1 Litre bottle $1.00 Shipping $1.00 </option>
<option cost="1.00" id_num="33253" name="1L bag Sheep Dip" shipping="1.50">1 Litre bag $1.00 shipping $1.50 </option>
<option cost="3.00" id_num="33252" name="4L can Sheep Dip" shipping="2.00">4 Litre can $3.00 Shipping $2.00 </option>
<option cost="10.00" id_num="33254" name="205L Drum Sheep Dip" shipping="120.00">205 Litre (45 Gal/55 US Gal) Drum $200.00 Shipping $120.00</option>
</select><BR>
Quantity: <input type=text size=2 maxlength=3 name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1"> & &
<input type="image" onClick='AddOneOfManyToCart(this.form)' src="./images/a2_cart.gif" name="buy" WIDTH="38" HEIGHT="30" border=0 value="Add to Cart" ALT="Add to Cart" align=top>
</form>
<!--Shopping Cart End -->
<BR><BR>
<!-- -=*=-=*=- End of item -->
NOTE:
In the selction use lower case. The function will then "translate" for you.
cost becomes PRICE, id_num = ID_NUM, name = NAME and shipping=SHIPPING.
The form action is onClick='AddOneOfManyToCart(this.form)' this translates your selection into the proper format and then automatically goes to the "AddToCart" function.
for more discussion on this mod search for "different prices", or see this post:
http://www.nopdesign.com/forum/viewtopic.php?t=1908
This is not a new mod, but brings together the instructions in one post.
R