Closed (fixed)
Project:
Rules
Version:
7.x-2.x-dev
Component:
Rules Engine
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2011 at 13:54 UTC
Updated:
7 Mar 2011 at 09:21 UTC
Jump to comment: Most recent file
Comments
Comment #1
fagoHm, but if you define a new variable during the loop, it would be defined multiple times. So which variable should be provided then? Perhaps, you could provide a use case for that?
As work-a-round it should be possible to define a variable before going into the loop.
Comment #2
das-peter commentedThanks for your feedback fago.
Use case is to find e.g. the biggest integer to use them later on:
Current commerce project has fees which apply based on the longest duration of a product - I iterate over all line items in the cart, add dedicated fees and retrieve the duration of each line item product, if the value is bigger as the already stored one I replace the value in the variable.
Oh wait - now as I write this down I see an issue with the patch...
*patch rework in progress*
Ok, now the code updates the variables earlier so that the updated values are available in each iteration. And only variables which origin from the parent scope are registered back.
Comment #3
fago>And only variables which origin from the parent scope are registered back.
Oh, now I see the problem. If you change a not-wrapped variable, the changes would be lost. I agree that those changes should appear in the parent state though.
The parent vars must be the same as $state->variables, as $state2 contains all parent vars anyway. Then you are missing a space after foreach.
Also, let's add a short comment explaining what we are doing here.
Comment #4
das-peter commentedthanks for your feedback - patch updated.
Comment #5
fagothanks, committed.