I'm currently trying to adjust the line items in a particular cart/order after an event is triggered.
I've got:
use craft\commerce\Plugin as CommercePlugin;
$this->requirePostRequest();
$request = Craft::$app->getRequest();
$cart = CommercePlugin::getInstance()->getCarts()->getCart(true);
$lineItem = CommercePlugin::getInstance()->getLineItems()->getLineItemById($cart->lineItems[0]->id);
$lineItem->price = 100.0000;
$lineItem->salePrice = 100.0000;
$lineItem->qty = 1;
$lineItem->note = '';
$cart->addLineItem($lineItem);
$cart->email = $request->getParam('orderEmail');
if (!Craft::$app->getElements()->saveElement($cart)) {
return false;
}
But this seems to not do anything, except update $lineItem
and not update the line item when the cart is then saved.