0

I am using commerce_discount module to create a custom line item. Then inside my code I am creating a line item of type commerce_discount. I populate it and save it to order. It is saved but the line item total amount is not added to order total amount. The code is given below.

$line_item_new = commerce_line_item_new('commerce_discount', $order->order_id);

        $line_item_new->line_item_label = 'Discount';
        $line_item_new->quantity = 1;
        $line_item_new->commerce_unit_price['amount'] = $total_discount;
        $line_item_new->commerce_unit_price['currency'] = commerce_default_currency();
        $line_item_new->commerce_total['und'][0]['amount'] = -$amount;

        $order->commerce_line_items[] = $line_item_new;
        commerce_order_save($order);

  • Are you sure it's not a duplicate of drupal.stackexchange.com/questions/22614/… ? – Mołot Jun 10 '13 at 13:26
  • I've already opened that post, Let me try again with that. – rashidkhan Jun 10 '13 at 13:30
  • Try again? You don't like answer there? Or you feel it's not what you ask about? If the second, could you edit your question to show how your case is different? – Mołot Jun 10 '13 at 13:52
  • It's not working for me. I'm using line items of multiple types. like product, shipping, coupon and commerce_discount. The other are added, only commerce_discount is not added. – rashidkhan Jun 10 '13 at 14:07
  • If you add them the same way, I don't understand. Good luck. – Mołot Jun 10 '13 at 14:14

Your Answer

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

Browse other questions tagged or ask your own question.