0

Let's say i have a product content type. It has a title, body and price field.

In a view (or in the node page) in addition to these fields I would like to have a multiple of the price field ?

Example :

  • Title : Red tshirt
  • Body : Tshirt description
  • Price : $9,95
  • Extra field : $99,5 ( Price x 10 )
6
  • Do you need to calculate the extra field once and store it in the database, or do you want to calculate it on the fly, every time the node is viewed? May 24, 2013 at 20:53
  • Prices change. It makes more sense to maintain a single data item than having to maintain two. Calculating it on the fly would have the least maintenance impact.
    – Triskelion
    May 24, 2013 at 21:01
  • @marcvangend I don't know really, i'm still trying to figure this out so i'm looking for ideas and suggestions. Triskelion suggested the Computed Field module so i'll give it a try and see if it does the job.
    – FlashSP
    May 24, 2013 at 21:51
  • Marcellus Wallace: Computed Field is a good module, so I support Triskelion's answer. It offers both options (db-stored and on-the-fly). @Triskelion: I don't quite understand your comment. I know prices change, and I never proposed a solution which involves maintaining two fields. Storing in the db has its advantages, such as using the field data in views as a sort criterion. May 25, 2013 at 10:26
  • My comment was in response to @marcvangend. And you can always sort by Price.
    – Triskelion
    May 25, 2013 at 13:09

1 Answer 1

1

The easiest way would be to use the Computed Field module. Use something like:

if ( isset($entity->field_price)){
  $entity_field[0]['value'] = ($entity->field_price[0]['value'] * 10);
}

in the Computed Code (PHP) box.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.