I want to order the CITEM quantity more than 10, and also need to use the Cart functionality.

Siddhesh Wani1
Tera Guru

I have a new requirement where users need to order a catalog item with a quantity greater than 10. Currently, we are using the cart functionality, and there is a limit of 10 choices. For our process, we need to implement some customizations while still leveraging as much out-of-the-box functionality as possible. Order quantity is not fix it can be more than 1000 also. 

I would appreciate your guidance on the recommended approach and a better understanding of the process for this requirement. Additionally, the sc_cart page appears to have multiple widgets linked to it, and I am having difficulty identifying which widget should be updated to handle this change.

3 REPLIES 3

Chanuka
Tera Guru

Hi @Siddhesh Wani1 ,


Give a try on this way.

 

Step 1: Create a Custom variable.

Here we can create a new custom variable for Order quantity.

 

1. Type: Single Line Text. 
2. Name: 'Order Quantity'.
3. Validation: Type Specifications -> Number 

 

a.png

 

 

b.png

 

Step 2: Hide the Default cart Quantity.

You can hide the Default dropdown so users can only see your new field.

 

1. Open the Catalog Item u want to use.

2. Uncheck the 'Use cart layout box', If this is not visible in the form u can add it from the Form Layout.
 (If this is checked, it hides the next checkbox you need).

3. Check the 'No quantity box', If this also not visible add it from the Form Layout.

(If still OOTB 'Quantity' (1-10) field is visible u can run 'cache.do' and refresh your portal)

 

c.png

 

Step 3: Create a BR to map the Variable to the RITM.

Now you can map your custom variable to the Default RITM quantity field. 

 

1. Create a new Business Rule on the Requested Item (sc_req_item) table.
2. Give a name 'Set Custom Order Quantity'
3. Check 'Advanced'.
4. When to run -> Before -> Insert. 
5. Conditions: 'Item' is 'enter your cat item'
6. Script:

 

(function executeRule(current, previous /*null when async*/) {

current.quantity = current.variables.order_quantity;

})(current, previous);
 

Step 4: Hide the Custom Order Quantity field from the RITM.

 

If we missed this step, two fields will contain the same values.

 

We only want to keep the Default Quantity field.

1. Create a new Catalog UI Policy on your cat item.
2. Leave the conditions 'empty'.
3. Uncheck 'Applies on a Catalog Item view'.
4. Check 'Applies on Requested Items'.
5. Create a UI Policy Action for `order_quantity` and set Visible to 'False'.

 

d.png


Step 5: Validate the Input Limits.

 

Let's ensure users don't order '0' or negative amounts or exceed the maximum limit.

 

1. Create a Catalog Client Script.
2. Type: onChange
3. Variable:''order_quantity`.

 

e.png

4. Script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   
   var qty = parseInt(newValue, 10);
   
   if (qty <= 0) {
      g_form.clearValue('order_quantity'); 
      g_form.showFieldMsg('order_quantity', 'Please enter a positive number greater than 0.', 'error');
   } else if (qty > 1500) {
      g_form.clearValue('order_quantity'); 
      g_form.showFieldMsg('order_quantity', 'The maximum allowed quantity per order is 1500.', 'error');
   }
}
 

If this helped point you in the right direction, please mark it as Helpful or Accept as Solution!

Siddhesh Wani1
Tera Guru

Hi @Chanuka ,

I want some solution for Cart page, if we use the custom variable for the Quantity, then on the cart page the quantity field is not working properly. 

lauri457
Tera Sage

The cart gets its choices from the choice list for the [sc_cart_item].quantity field. I'd say adding new choices to this would be the suggested approach.

 

To create some kind of conditional logic you'd have to clone the SC Shopping Cart with the angular templates and edit the template that you are using.

 

For example this is from the large_shopping_cart.html, see the ng-repeat directive on the option element:

          <td headers="id-header-quantity" data-th="Quantity" class="break-word hidden-xs wrapper">
            <select ng-if="c.showQuantity(item) && !item.read_only_quantity"
                    id="{{item.sys_id}}"
                    title="{{c.getQuantityTitle(item)}}"
                    class="scBasicSelect"
                    ng-disabled="(item.order_guide && !item.show_quantity_guide_item) || !item.can_order"
                    ng-model="item.quantity"
                    ng-change="c.updateQuantity(item)">
                     <option ng-repeat="num in data.choiceListQuantity" value={{::num.value}}>{{::num.label}}</option>
                  </select>
            <span ng-if="::(!item.show_quantity || (item.read_only_quantity && item.sys_class_name != 'sc_cat_item_producer'))">{{::item.show_quantity ? item.quantity : '--'}}</span>
          </td>

How choiceListQuantity is assigned to the data object in the widget server script:

	if(!localInput){
		var clGenerator = new GlideChoiceList();
		var choiceListQuantity = clGenerator.getChoiceList("sc_cart_item", "quantity");
		var choicelistQuantityData = [];
		for (var i = 0; i < choiceListQuantity.size(); i++) {
			var choice = choiceListQuantity.get(i);
			if (!isNaN(choice.getValue()))
            choicelistQuantityData.push({
                value: parseInt(choice.getValue()),
                label: choice.getLabel()
            });
		}
		data.choiceListQuantity = choicelistQuantityData;
	}

It would be trivial to edit these but if you are unable to figure out how a widget works it might be best not to clone it