I try it with rules:
{ "rules_golden_user_price" : {
"LABEL" : "golden user price",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "uc_product", "rules" ],
"ON" : { "uc_product_load" : [] },
"IF" : [ { "node_is_product" : { "node" : [ "node" ] } } ],
"DO" : [
{ "data_calc" : {
"USING" : { "input_1" : [ "node:list-price" ], "op" : "*", "input_2" : "0.7" },
"PROVIDE" : { "result" : { "result" : "Calculation result" } }
}
},
{ "data_set" : { "data" : [ "node:price" ], "value" : [ "result" ] } },
{ "drupal_message" : { "message" : "abc123:[result:value]" } },
{ "entity_save" : { "data" : [ "node" ] } }
]
}
}
it seems that it does not work
Comments
Comment #1
g089h515r806 CreditAttribution: g089h515r806 commentedI try to set node->price = node->list_price * 0.7.
when i output node->price in node template, th value has not been changed by rules.
Comment #2
g089h515r806 CreditAttribution: g089h515r806 commentedList price: 29.80
sell price:19.80
I output it in node template using following code:
It seems that "$node->price;" is not been changed. it display: 19.80.
If I using following code:
it display: 20.86.
It is correct.
I think that $node->price and $price should keep the same at here. But they are different in node template.
Comment #3
g089h515r806 CreditAttribution: g089h515r806 commentedIn uc_product.module, function uc_product_view,
Add following code
below :
could fix this issue.
Comment #4
longwaveJust use
print $price;
in your template. You are not really supposed to print $node values directly from a template, at least without sanitizing/formatting them first, and we should not override the originals - what if someone else wants to display the original values?Also, you should not need to use the entity save action in your Rule, the price is calculated on load each time anyway.
Comment #5
g089h515r806 CreditAttribution: g089h515r806 commentedA lot developers use
instead of
It better to write some document about this:
$node->price maybe different with $price.
It looks very strange that in rules I changed the value of $node->price, but in node template, $node->price has not been changed.