Users can create a pop-up message if the shopper has entered a quantity less than the minimum set in the Item record. This is an alternate and less complicated version to Scriptable Messaging.
To create pop-up message , see below:
- Navigate to Commerce > Site Builder > Item/Category Templates
- Item List Cell Template: Click Edit
- Look for a call to the getCurrentAttribute(‘item’,’addToCartListHtml’) tag
- Paste the following code after the tag call:
< !--NLHIDE:script type="text/javascript">< !-- function checkquantitytoadd<%=getCurrentAttribute('item', 'internalid')%>(minquantity2) {
var __FormItem1<%=getCurrentAttribute('item', 'internalid')%>=document.forms["form<%=getCurrentAttribute('item', 'internalid')%>"];
if(__FormItem1<%=getCurrentAttribute('item', 'internalid')%>.elements["qty"].value < minquantity2) {
alert("The minimum quantity that can be ordered for this item is " + minquantity2);
}
/*end if*/
else {
document.forms['form<%=getCurrentAttribute(' item', ' internalid')%>'].submit();
}
/*end else*/
}
/*end checkquantitytoadd*/
var str<%=getCurrentAttribute('item', 'internalid')%>="<%=getCurrentAttribute('item', 'minimumquantity')%>";
if(str<%=getCurrentAttribute('item', 'internalid')%>.indexOf("not found") !=-1) {
/*alert (" There is a minimum quantity field found");*/
}
/*End if*/
else {
if(str<%=getCurrentAttribute('item', 'internalid')%>.length>0) {
var oForm<%=getCurrentAttribute('item', 'internalid')%>=document.forms["form<%=getCurrentAttribute('item', 'internalid')%>"];
oForm<%=getCurrentAttribute('item', 'internalid')%>.elements["addtocart"].onclick=new Function("checkquantitytoadd<%=getCurrentAttribute('item', 'internalid')%>(" +str<%=getCurrentAttribute('item', 'internalid')%>+")");
}
/*end inner if*/
}
/*end of else*/
//--> </script:NLHIDE-->
- Click Save
- Navigate to Commerce > Site Builder > Item/Category Templates
- Item Drilldown Template: Click Edit
- Look for a call to the getCurrentAttribute(‘item’,’addToCartDrillDownHtml’) tag
- Paste the same code in Step 4 after the tag call mentioned in Step 8
- Click Save
Note: An alternate place is just before the “END ADD TO CART” HTML comment in the templates mentioned