Tags/topics: 
1
Answers
Vote up!
0
Vote down!

How to grant points to the product creator after the product is sold?

Hello everybody! How's goin'?
Can someone help me with the next, please!!!
What is wrong in my rule or component?
I would like to grant points to a product creator in amount of 90% of product price after product is sold.
1 point = 1 cent. I have a rule and part of component.
For points I created a field in user account. field_balance (price type)

    The rule

{ "rules_add_points" : {
    "LABEL" : "Add points",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Commerce Checkout" ],
    "REQUIRES" : [ "rules", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "completed" } }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [ { "component_rules_calc_points" : { "line_item" : [ "list-item" ] } } ]
        }
      }
    ]
  }
}
    Component

{ "rules_calc_points" : {
    "LABEL" : "Calculation of point",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "line_item" : { "label" : "lin item", "type" : "commerce_line_item" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "line-item" ], "field" : "commerce_product" } }
    ],
    "DO" : [
      { "data_calc" : {
          "USING" : {
            "input_1" : [ "line-item:commerce-product:commerce-price:amount-decimal" ],
            "op" : "*",
            "input_2" : "0.9"
          },
          "PROVIDE" : { "result" : { "points2add" : "Points 2 add" } }
        }
      },
      { "data_calc" : {
          "USING" : {
            "input_1" : [ "line-item:commerce-product:creator:field-balance:amount-decimal" ],
            "op" : "+",
            "input_2" : [ "points2add" ]
          },
          "PROVIDE" : { "result" : { "final_calculation" : "Final Calculation" } }
        }
      },
      { "data_set" : { "data" : [ "line-item:commerce-product:creator:field-balance" ] } }
    ]
  }
}

On the last step of component I can not set the calculated value.
I simply can not select this value, cause it is not available for selecting.

I have Drupal 7 installed.
Many thanks for any help in advance!!!
PLEASE HELP!

Malix
Asked by: Malix
on April 22, 2015

1 Answer

Vote up!
0
Vote down!

Done
Rule
{ "rules_add_points" : {
"LABEL" : "Add points",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "Commerce Checkout" ],
"REQUIRES" : [ "rules", "commerce_checkout" ],
"ON" : { "commerce_checkout_complete" : [] },
"DO" : [
{ "LOOP" : {
"USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "component_rules_calc_points" : { "line_item" : [ "list-item" ], "point" : "0.9" } }
]
}
}
]
}
}

Component
{ "rules_calc_points" : {
"LABEL" : "Calculation of point",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
"line_item" : { "label" : "lin item", "type" : "commerce_line_item" },
"point" : { "label" : "Points", "type" : "decimal" }
},
"IF" : [
{ "entity_has_field" : { "entity" : [ "line-item" ], "field" : "commerce_product" } }
],
"DO" : [
{ "data_calc" : {
"USING" : {
"input_1" : [ "line-item:commerce-unit-price:amount-decimal" ],
"op" : "*",
"input_2" : [ "point" ]
},
"PROVIDE" : { "result" : { "points2add" : "Points 2 add" } }
}
},
{ "data_calc" : {
"USING" : {
"input_1" : [ "line-item:commerce-product:creator:field-baly" ],
"op" : "+",
"input_2" : [ "points2add" ]
},
"PROVIDE" : { "result" : { "result2" : "Calculation result" } }
}
},
{ "data_set" : {
"data" : [ "line-item:commerce-product:creator:field-baly" ],
"value" : [ "result2" ]
}
}
]
}
}

Malix
Answer by: Malix
Posted: Apr 23, 2015