Magento 2: Changing Price of Product in Controller doesn't work at the moment!

I get it, I think you are in the right way, but I think you have to save the quote. If you take a look on this class : \Magento\Checkout\Controller\Cart\Add you can see at Line 114 :

$this->cart->addProduct($product, $params);
            if (!empty($related)) {
                $this->cart->addProductsByIds(explode(',', $related));
            }

            $this->cart->save();

I change the price from the event which is called at the end of the addProduct() method, and Magento saves the cart at the end. So in your case, you have to save the quote in your controller.


I did a snippet which allows you to change the price. Actually, it changes the price after you add product in your basket. In other words, it changes the prices of your items in your quote. https://gist.github.com/0-Sony/d9d2ea792b5533bfeaff28827e6f207a

Hope it helps.


You want to update the row total and not the subtotal, use method $item->setRowTotal() or $item->setBaseRowTotal(). Also, it might help to add $item->save() before the end of the loop.

Subtotal is the order/cart subtotal.