This question was asked by Sven in Zulip.
His question: In Ubercart, he wants to limit the number of a specific product a user can add to the cart. In theory, you can do that with a Rule that's already provided by Ubercart, or by using the module UC Restrict Quantity. The problem is that both solutions will fail when your product has attributes. Ubercart will create separate Cart Items for each product depending on its attribute. See image (same product, two different attributes). See my solution in the reply below.
Comments
The solution I proposed was to implement two hooks in a small custom module: hook_uc_add_to_cart (to prevent the user from adding products with the Add to cart button), and hook_form_uc_cart_view_form_alter (to prevent the user from modifying the quantity of a product through the cart form).
This sample code below hard-codes the "3" limit and only for product with nids 7 and 8, so, ideally, you'd create a config file and admin ui to enter the maximum, and also to select the target nid of the product. Or you can create a "product feature".
You also need to create a .info file for this, and save as uc_restrict_by_nid.info
So, this is only a STARTING POINT for a better solution.