3

I have an online store using commerce and rules, with products that can be bought in different quantities. Commerce stores the line-items in an order as a list, but it stores the quantity-per-line-item as a flat number.

I have a rule that needs to fire once for each tangible product- ie. number of line-items x quantity.

Rules can loop over lists, but I don't have a way of representing the quantity as a list. Is there a way to loop using just a number? Is there a way to turn a raw number into a list Rules can loop over?

4

I ended up doing this with the 'execute custom PHP code' action. I created a 'Do Foo Once' component with the UI, and then added this to 'Do Foo N Times':

for ($i = $quantity; $i > 0; $i--) {
  rules_invoke_component('rules_do_foo_once', $i, $bar);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.