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

g089h515r806’s picture

I 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.

g089h515r806’s picture

List price: 29.80
sell price:19.80

I output it in node template using following code:

print $node->price;

It seems that "$node->price;" is not been changed. it display: 19.80.

If I using following code:

print $price;

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.

g089h515r806’s picture

In uc_product.module, function uc_product_view,
Add following code


  foreach (array('price', 'model', 'list_price', 'cost', 'sell_price', 'weight', 'length', 'width', 'height', 'length_units') as $property) {
    if (isset($variant->{$property})) {
      $node->{$property} = $variant->{$property};
    }
  }
 

below :

$node->content['dimensions'] = array(
    '#theme' => 'uc_product_dimensions',
    '#length' => $variant->length,
    '#width' => $variant->width,
    '#height' => $variant->height,
    '#units' => $variant->length_units,
    '#view_mode' => $view_mode,
  );

could fix this issue.

longwave’s picture

Category: Feature request » Support request
Status: Active » Closed (works as designed)

Just 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.

g089h515r806’s picture

A lot developers use

  print $node->price;

instead of

  print $price;

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.