cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Maximum Order quantity in Hybris Commerce

0 Likes
2,676

Hi,

What is the maximum quantity of items that can be added to an order during checkout in Hybris Commerce B2B ? Is there a limitation of quantity by item or by total number of items in the order ?

Haseeb.

Accepted Solutions (0)

Answers (1)

Answers (1)

a_e_dubey
Active Participant
0 Likes

Hello ccd

I think you need to have one restriction on CartModel for limiting order quantity. But as far as I know you have one field at ProdutModel level i.e MaxOrderQuantity. And this as check in DefaultCommerceAddToCartStrategy.java and here if you try to add more than ProdutModel.MaxOrderQuantity , CommerceCartModificationStatus.MAX_ORDER_QUANTITY_EXCEEDED is thrown. I would suggest to dig in this and assuming this should work automatically. See complete ootb logic below.

DefaultCommerceAddToCartStrategy.java


protected String getStatusCodeForNotAllowedQuantityChange(final Integer maxOrderQuantity,
			final Integer cartLevelAfterQuantityChange)
	{


		if (isMaxOrderQuantitySet(maxOrderQuantity) && (cartLevelAfterQuantityChange.longValue() == maxOrderQuantity.longValue()))
		{
			return CommerceCartModificationStatus.MAX_ORDER_QUANTITY_EXCEEDED;
		}
		else
		{
			return CommerceCartModificationStatus.NO_STOCK;
		}
	}


	/**
	 * Do add to cart.
	 *
	 * @param parameter
	 *           the parameter
	 * @return the commerce cart modification
	 * @throws CommerceCartModificationException
	 *            the commerce cart modification exception
	 */
	protected CommerceCartModification doAddToCart(final CommerceCartParameter parameter) throws CommerceCartModificationException
	{
		CommerceCartModification modification;


		final CartModel cartModel = parameter.getCart();
		final ProductModel productModel = parameter.getProduct();
		final long quantityToAdd = parameter.getQuantity();
		final PointOfServiceModel deliveryPointOfService = parameter.getPointOfService();


		this.beforeAddToCart(parameter);
		validateAddToCart(parameter);


		if (isProductForCode(parameter).booleanValue())
		{
			// So now work out what the maximum allowed to be added is (note that this may be negative!)
			final long actualAllowedQuantityChange = getAllowedCartAdjustmentForProduct(cartModel, productModel, quantityToAdd,
					deliveryPointOfService);
			final Integer maxOrderQuantity = productModel.getMaxOrderQuantity();
			final long cartLevel = checkCartLevel(productModel, cartModel, deliveryPointOfService);
			final long cartLevelAfterQuantityChange = actualAllowedQuantityChange + cartLevel;


			if (actualAllowedQuantityChange > 0)
			{
				// We are allowed to add items to the cart
				final CartEntryModel entryModel = addCartEntry(parameter, actualAllowedQuantityChange);
				getModelService().save(entryModel);


				final String statusCode = getStatusCodeAllowedQuantityChange(actualAllowedQuantityChange, maxOrderQuantity,
						quantityToAdd, cartLevelAfterQuantityChange);


				modification = createAddToCartResp(parameter, statusCode, entryModel, actualAllowedQuantityChange);
			}
			else
			{
				// Not allowed to add any quantity, or maybe even asked to reduce the quantity
				// Do nothing!
				final String status = getStatusCodeForNotAllowedQuantityChange(maxOrderQuantity, maxOrderQuantity);


				modification = createAddToCartResp(parameter, status, createEmptyCartEntry(parameter), 0);


			}
		}
		else
		{
			modification = createAddToCartResp(parameter, CommerceCartModificationStatus.UNAVAILABLE,
					createEmptyCartEntry(parameter), 0);
		}


		return modification;
	}

Please analyse this logic during add to cart. And even you can customize this logic by keeping limit on quantity globally instead of product level. So this is for reference.

Please look at below links if you have access may be this can help you:

Topic

0 Likes

Hello a Dubey,

Thank you for the response. I checked all the links but unfortunately none of them is referring to Hybris Commerce order checkout.

Haseeb.

a_e_dubey
Active Participant
0 Likes

Hi ccd edited answer.

0 Likes

Hello a dubey,

Thank you again, I do not have a deep understanding of the code, however, it seems that we can put any limit on cart and product level for e.g. the ordered quantity could be of length 4 or even 5.

OOTB the max length is probably 3 but can be increased, am I right? if yes, is there any implication to the system performance or security if it's done ?

Haseeb.

a_e_dubey
Active Participant
0 Likes

Yes, The code I have shown is ootb and this is functional feature. So there is no implication to the system performance or security. You can use it. Accept answer if this helps you.