-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rule condition to include other rules (for structured nesting). #2487
Conversation
78df06a
to
b27ab58
Compare
]); | ||
} | ||
while (!empty($unprocessedRules)) { | ||
foreach ($rules as $id => &$rule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be unreferenced using unset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
foreach ($rule as &$condition) { | ||
if ($condition['type'] === NestedRule::NAME) { | ||
$value = json_decode($condition['value'], true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw on error missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
if ($command instanceof UpdateCommand) { | ||
if ($command->hasField('value')) { | ||
$value = json_decode($command->getPayload()['value'], true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw on error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to skip requesting the changeset, if it's not the value we need, instead.
?string $code = null | ||
): ConstraintViolationInterface { | ||
return new ConstraintViolation( | ||
str_replace(array_keys($parameters), array_values($parameters), $messageTemplate), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array_values is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/** | ||
* @var EntityRepositoryInterface | ||
*/ | ||
private $ruleRepository; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
public function testIfRuleIsConsistent(): void | ||
{ | ||
$ruleId = Uuid::randomHex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idscollection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Codecov Report
@@ Coverage Diff @@
## trunk #2487 +/- ##
==========================================
- Coverage 61.95% 61.93% -0.03%
==========================================
Files 3467 3469 +2
Lines 75624 75778 +154
==========================================
+ Hits 46854 46932 +78
- Misses 28770 28846 +76
Continue to review full report at Codecov.
|
b27ab58
to
8dff736
Compare
* Detect cycles with existing rules in validation * Preprocess rules during indexing and embed nested rules inside NestedRule instance Co-authored-by: Uwe Kleinmann <u.kleinmann@kellerkinder.de> Co-authored-by: Jan Mallwitz <mallwitz@botschaft.digital>
8dff736
to
f4865b1
Compare
Hello, thank you for creating this pull request. Please use this issue to track the state of your pull request. |
This MR breaks the rule awareness feature: shopware/docs#446 and the app script conditions feature. |
Hey @kleinmann. I am sorry, that you PR is breaking an upcoming feature. Even I did not see the rule awareness feature coming. For now, I am closing this PR, thank you for contributing though 🎉 |
1. Why is this change necessary?
Lots of shops have repeating rules that they use in multiple rules, e.g. a rule excluding certain products from promotions which is used in different combinations with other conditions.
This PR adds a new rule condition to embed a separate rule to allow for extraction of common rule conditions and easier maintenance.
2. What does this change do, exactly?
It adds a new rule condition and changes the rule indexing such that nested rules are embedded in their corresponding NestedRule instances.
It also validates rule conditions to prevent creation of cycles in the nested rules.
3. Describe each step to reproduce the issue or behaviour.
4. Please link to the relevant issues (if any).
5. Checklist