1

I used below link to place an order, but in that, I cannot get any solution. how to add the tax or discount in order so anyone has done this thing?

please help to solve this issue.

http://www.blogtreat.com/programmatically-create-new-order-in-magento-2%EF%BB%BF/

1 Answer 1

4

Here I have share code to apply tax in your custom code:

$subTotal = 121;
$taxRate = .0825;
$taxAmount = $subTotal * $taxRate;
$shippingAmount = 15;
$totalAmount =  $subTotal + $taxAmount + $shippingAmount;

$order->setSubtotal($subTotal);
$order->setBaseSubtotal($subTotal);
$order->setGrandTotal($totalAmount);
$order->setBaseGrandTotal($totalAmount);
$order->setTaxAmount($taxAmount);
$order->setDiscountAmount(0);

If you found answer useful please accept it.

5
  • I tried this code but the discount code value did not into order. Jul 19, 2018 at 11:32
  • have you tried to "$order->setDiscountAmount(0);" change amount in this code?
    – P_U
    Jul 20, 2018 at 9:39
  • yes, I tried your code and it is working. thanks Jul 20, 2018 at 10:12
  • @P_U, how to add tax amount for quote item? here is my question regarding it, magento.stackexchange.com/questions/274520/… May 15, 2019 at 12:09
  • You saved my day, I can confirm it is working correctly in Magento 2.4.1. Thanks man Mar 2, 2021 at 5:57

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.