How do you perform a rules action by the quantity of a specific commerce product?
The quickest way to do this is with another custom action. Since you already wrote your own module, this shouldn't be a problem.

In your my_module.rules.inc file, do something like:

function my_module_rules_action_info() {
 return array(
  'my_module_loop_based_on_qty' =&gt; array(
    'label' =&gt; t('Execute a loop based on a quantity'),
    'parameter' =&gt; array(
      'quantity' =&gt; array(
        'type' =&gt; 'integer',
        'label' =&gt; t('Quantity added to cart'),
      ),
    ),
    'group' =&gt; t('My Module'),
  );
}

function my_module_loop_based_on_qty($qty) {
  // Loop based on the $qty variable
}


Provide whatever other parameters you need for the function as well. You can then pass it the quantity when you create the rule. That other rules action you already wrote can just be wrapped in a helper function that is then called by this new action.