0

Let's say I have an Entity with a custom integer field added. Let's call the field Global Total (field_global_total)

On some event, I want to

  • get the existing value of that field and store it in a variable

  • get the value of another integer field (from another entity) and store that in a variable

  • add the two variables together

  • save that sum as the new value of "Global Total"

Ultimately I want to learn this generically so I can build more complex rules. For example, I don't know how to create a variable, but when I do, is that variable confined to the scope of that rule? Or can I pass it around to any subsequent rule? And if I can, how do I access it in other rules?

But if it helps, this is my specific use case.

My goal is, in Commerce, I have Product A. Product A has an integer field called "Total Sold to Date" (field_total_sold_to_date). Let's say that the current value is 15.

Event

Item is added to cart. Quantity field is updated to 20. User checks out.

Condition

Entity has field

Action

-- get Quantity value and store it in variable 'this_quantity'

-- get Total_sold_to_date value and store it in 'ttstd'

-- add the two together

-- save the entity so that the sum is the new value of the product's field_total_sold_to_date value

Please note that I do not want to use an extra module like compute fields or math or commerce reports. I feel like this can be done out of the box. Thanks!

3
  • I'm having trouble finding tutorials or complete documentation about the Calculate a Value and Set a Value selectors for Rules. If you have any, please post them here in the comments.
    – blue928
    Commented Sep 14, 2021 at 16:30
  • built components, first component, calculate anything you neeed, and return result, second component, same thing, now in your rule call your comonents, since both returned a value, in rules do: a+b=c
    – pinueve
    Commented Sep 14, 2021 at 17:16
  • 1
    search in this tutorial, its easy, goog luck youtube.com/watch?v=QL1Rp69Lq80&list=PL84B6FFA4F7ACAD57
    – pinueve
    Commented Sep 14, 2021 at 17:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.