Skip to content
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

Ability to pass parameters into the Rule variables #55

Open
sshegheva opened this issue Nov 13, 2019 · 1 comment
Open

Ability to pass parameters into the Rule variables #55

sshegheva opened this issue Nov 13, 2019 · 1 comment

Comments

@sshegheva
Copy link

Hi, I have been trying to evaluate business rules for a project that I am working on, and I can't figure out how to parametrize a rule:

For example, I want to trigger the rule if it matches a specific configuration. A product has category, and the category is books, and frequency is 1.

     { "name": "attribute_frequency",
        "operator": "less_than_or_equal_to",
        "value": {"key": "category", "value": "books", "max_frequency": 1},
      },

It is not possible to pass a more complex objects into the rule variables? Or pass parameters?

How do you address that?

Thank you!

@bhargavrpatel
Copy link

bhargavrpatel commented Jan 5, 2020

You can instead create multiple conditions such that one condition is for the category and other is for its frequency. The "all" clause will ensure that the condition rule is satisfied iff both of these are true.

Edit: Addendum: A pseudo example below.

rule = {
    "conditions": {
        "all": [
            {"name": "category", "operator": "equal_to", "value": "book"},
            {"name": "attribute_frequency", "operator": "equal_to", "value": 1},
        ]
    },
    "actions": [{"name": "give_basket_discount", "params": {"amount": 2},}],
}

Also note that you should separate out the category into a different variable. Think of variables as smallest divisible units of potential business logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants