Magento 2.4 - add custom discount amount and tax amount to each cart item when an order is created programmatically
-
15-04-2021 - |
Question
I'm creating an order programmatically and I would like to add a custom discount to each quote item.
I have something like this ...
$quote = $this->_quote->create();
...
foreach($products as $item) {
....
$quoteItem = $quote->addProduct($productBySku, intval($item->quantity));
$quoteItem->setCustomPrice($item->price);
$quoteItem->setOriginalCustomPrice($item->price);
$quoteItem->setDiscountAmount(5);
$quoteItem->setTaxAmount(5);
....
}
I'm not interested in verifying totals and others, because I set the totals by myself after the quote is saved and the order is created. This is an order migration script and I would very much like to set the discount amount and tax for each row, but it doesn't work.
I also tried to set the quote item discounts after the quote is saved, but it doesn't work as well.
Can you help me with this?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange