Adding SKU Order Quantity Limits

Admin: eCommerce Admin
Page: Advanced Customization > Javascript Insertion
URL: {client_ID}.retailadmin.directscale.com/#/Insertion

Suppose you want to limit the amount of a particular inventory item a customer can add to their cart. Using JavaScript Insertions, you can implement this feature not currently available in the DirectScale Platform.



Before You Start

There are two ID types you must have available:

  • Cart IDs
  • Item IDs

Shopping Cart IDs

Each Shopping Cart type has an associated Cart ID. These IDs are the same for every client. Locate the Cart ID that you need and have it handy for later.

Retail Cart IDs

Shopping Carts

  • Enrollment Kit: 0067D89C-B8C6-4E2B-840D-16F8EFC0F946
  • Enrollment Order: 22162AC0-0C7E-4EAC-8B37-8985705D921F
  • Retail Shop Order: DEDAC5EA-9659-482F-8C97-0D5250E8B9D6

AutoOrder Carts

  • Retail Shop Autoship: 1C10056A-714E-4123-AA49-2E5CAF63B0C5
  • Enrollment Autoship: 3e1d5422-54e1-4903-a44b-654769a8b1be

Web Office Admin Cart IDs

Shopping Carts

  • Office Shopping Cart: 003afd4c-ecaa-4210-a494-ec11475b0da0
  • Enrollment Order: DEDAC5EA-9659-482F-8C97-0D5250E8B9D6
  • Enrollment Kit: 0067D89C-B8C6-4E2B-840D-16F8EFC0F946
  • Party Enrollment: 01a16933-06a1-4ed9-8848-bf7c21ed3c61
  • Office Party Cart: 200f53de-d16c-43ad-9ffa-648245170d97

AutoShip Carts

  • Enrollment Autoship: 1C10056A-714E-4123-AA49-2E5CAF63B0C5
  • Office Autoship: 3e1d5422-54e1-4903-a44b-654769a8b1be

You can also create a custom shopping cart and copy the resulting Cart ID. Learn how in Creating Custom Shopping Carts.


Inventory Item IDs

Each added inventory item is assigned an Item ID. You can find the Item ID on the inventory item's Detail configuration page, or by querying the recordnumber of the item's entry in the INV_Inventory table.



Adding an Insertion

  1. In the JavaScript Insertions page, click + ADD INSERTION.

  2. Select Custom Script from the Insertion Type menu.

  3. Enter a sort Name.

  4. In the JavaScript Code Editor, paste the following code:

    try {
     console.log('loaded custom insertion');
     var ct = window.customTriggers;
     var isDisabled = function (items, CartID, CurrentItem, Quantity, QuantityLimit, isPlaceOrder) {
         var limit = 0;
         var numsbroken = 0;
         var getItemLimit=function(CurrentItem){
           if(CartID === "45E7E662-E539-46F2-89C1-D4348C47BB44"){
              if (CurrentItem.ItemCode === "2446"
                 || CurrentItem.ItemCode === "2461") { 
                  return 2;
                }
          		if (CurrentItem.ItemCode === "2054") { 
                  return 10;
                }
           }
           else{
           return 0;}
         };
      if (isPlaceOrder) { //on place order check
          var CurrentQuantity = 0;
          var showDisable = false;
          for (i = 0; i < items.length; i++) {
              limit=getItemLimit(items[i]);
              CurrentQuantity = Number(items[i].Quantity);
              if ((limit != 0) && (limit < CurrentQuantity)) {
                    showDisable = true;
                }
            }
        			if (showDisable) {
                    return true;
                } else {
                    return false;
                }
         } else if (CurrentItem && Quantity) {  //on cart insertion check
             limit = getItemLimit(CurrentItem);
             if (Number(Quantity) < limit && limit > 0) {
                 return false;
             } else if ((Number(Quantity) >= limit && limit > 0)) {
                 return true;
             }
             else {
                 return false;
             }
         }
         else {
             return false;
         }
     }
     var tooltip = function (items, CartID, CurrentItem) {
       return 'Quantity exceeded for this item.';
    	}
    	customTriggers.setIncreaseQuantityDisabledTooltip(function () {
    return 'Quantity exceeded for this item.';
    });
     var alert = function (Items, CartID) {
         ct.showAlert('you are buying ' + (Items[0] && Items[0].Price) + ' from cart ' + CartID);
     }
     ct.addCheckoutDisabledQTYFilter(isDisabled);
     ct.addAddToCartDisabledQTYFilter(isDisabled);
     ct.addIncreaseQuantityDisabledQTYFilter(isDisabled);
     ct.addReviewOrderDisabledQTYFilter(isDisabled);
     ct.setReviewOrderDisabledQTYTooltip(tooltip);
     ct.setCheckoutDisabledTooltip(tooltip);
     ct.setCheckoutDisabledQTYTooltip(tooltip);
     ct.setAddToCartDisabledQTYTooltip(tooltip);
     ct.setIncreaseQuantityDisabledQTYTooltip(tooltip);
    }
    catch (e) {
     console.log('e', e);
    }
    

    There are a couple of variables in the example that you must customize to work for your system:

    • CartID === "45E7E662-E539-46F2-89C1-D4348C47BB44" - This is the Shopping Cart ID.
    • CurrentItem.ItemCode === "2446" - This is the Inventory Item ID.
    • return 2; - After setting the ItemCode, you return the amount that sets the limit. Update these numbers to your specified limit.
  5. Enable the Published toggle to activate the script after saving.

  6. Customize further with Multi-faceted Configuration.

  7. Click SAVE.