1

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.

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

1 Answer 1

3

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;
   commerce_line_item_save($line_item);
}

10
  • i will try this
    – Richa
    Commented Feb 8, 2017 at 5:26
  • it is possible it's work when new commerce order because it work with add to cart
    – Richa
    Commented Feb 8, 2017 at 5:58
  • The question is about using the Rules module to get this to work. How does this answer help to do so? Commented Feb 8, 2017 at 8:24
  • btw this function work but i need when order place.
    – Richa
    Commented Feb 8, 2017 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
    Commented Feb 8, 2017 at 9:52

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.