Requiring a Minimum Product Quantity in ShopSite
This topic contains 0 replies, has 1 voice, and was last updated by Anonymous 19 years, 5 months ago.
-
AuthorPosts
-
April 26, 2006 at 5:57 pm #48520
There may be several instances when you would like to be able to force your shoppers to purchase a minimum amount of a particular product. Here are the steps to force a minimum quantity for a specific product in either ShopSite Manager or Pro:
1. Prevent the user from changing the quantity in the cart:
Commerce Setup -> Order System -> Shopping Cart: Check the box “Quantity cannot be changed”.2. Use a separate product template for each minimum that you want for each product (e.g. prod_no_min, prod_min10, prod_min11, etc…). Alternatively, if you have ShopSite Pro, you can achieve this with one template in conjunction with one of the extra product fields, which you can use to set the quantity.
3. In the template, modify the line to include the following ‘name=order’ and ‘onsubmit’ parts (replace XXX accordingly):
<form name=order action="http://www.XXX.com/cgi-XXX/sb/order.cgi" method=post onsubmit="return validateFields();">
4. Put the following JavaScript near the top of the template to validate fields:
<script language="JavaScript" type="text/javascript"> function GetFieldValue(FieldName) { // Get the value of a field even if the field name has weird characters var NumElements=document.order.elements.length; var TheValue=''; for (i=0; i<NumElements;i++) // go through all the elements till we find the correct field { var obj = document.order.elements[i]; if (obj.name==FieldName) // we found it. { // it's the right field. TheValue = obj.value; break; } } return TheValue; } function validateFields() { var checkvalue = GetFieldValue('[-- PRODUCT.RecordNumber --]:qnty'); if (checkvalue < X or [-- PRODUCT.FieldX --]) { alert ('A minimum quantity of X is required.'); return false; } return true; } </script>
In the above code, replace X with the minimum quantity or FieldX with the appropriate Field number. These two fields are mutually exclusive, and the or statement should be removed, such that this line of code will look like either:
if (checkvalue < X) {
or
if (checkvalue < [-- PRODUCT.FieldX --]) {
This JavaScript check ensures that the user has selected at least the minimum amount of a particular product. If less than the minimum amount is selected, the JavaScript pops up an alert message informing the shopper that they do not have an appropriate quantity to add to their cart. This framework can also be used to set a maximum allowable quantity if so desired.
-
AuthorPosts
You must be logged in to reply to this topic.