Here my query is that, I have created one field in product type "Time(Interval)" and another field created in Line item types "(Default Time)" field. My requirement is when user saves a new commerce order, Product type (Time(Interval) field) value auto saves in Line item field (Default Time) value. how we can do this, any idea.

  • Richa, can you please share what you tried and where you got stuck doing it with rules? – arpitr Feb 8 '17 at 6:25
  • no i am using drupal7 – Richa Feb 8 '17 at 7:10
  • i agree, ok i will with rules – Richa Feb 8 '17 at 9:36

You can implement hook_commerce_cart_product_add() The product which user is adding to cart and the line item is available with in this hook. you can fetch the Time(Interval) field value from product and save it to line item.

function my_module_commerce_cart_product_add($order, $product, $quantity, $line_item) {
   $commerce_line_item = commerce_line_item_load($line_item->line_item_id);
   $product_time = $product->time_interval['und'][0]['value'];
   $line_item->default_time = $product_time;

  • i will try this – Richa Feb 8 '17 at 5:26
  • it is possible it's work when new commerce order because it work with add to cart – Richa Feb 8 '17 at 5:58
  • The question is about using the Rules module to get this to work. How does this answer help to do so? – Pierre.Vriens Feb 8 '17 at 8:24
  • btw this function work but i need when order place. – Richa Feb 8 '17 at 9:37
  • @Pierre.Vriens "Don't use rules, do it this way because it's better, simpler and more performant" is a perfectly acceptable answer to "how do I do x with rules" – Clive Feb 8 '17 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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