Create a Pop-up Message for Items with Minimum Quantity Set

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:

  1. Navigate to Commerce > Site Builder > Item/Category Templates
  2. Item List Cell Template: Click Edit
  3. Look for a call to the getCurrentAttribute(‘item’,’addToCartListHtml’) tag
  4. 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-->
  1. Click Save
  2. Navigate to Commerce > Site Builder > Item/Category Templates
  3. Item Drilldown Template: Click Edit
  4. Look for a call to the getCurrentAttribute(‘item’,’addToCartDrillDownHtml’) tag
  5. Paste the same code in Step 4 after the tag call mentioned in Step 8
  6. Click Save

Note: An alternate place is just before the “END ADD TO CART” HTML comment in the templates mentioned

Leave a comment

Your email address will not be published. Required fields are marked *