Skip to content

Itemcollection get latest updated_at item – Magento 2.4

We use the following code, to get the last item that was most recent updated.

$itemsCollection = $cart->getQuote()->getItemsCollection();
$itemsCollection->getSelect()->order('updated_at DESC');
$latestItem = $itemsCollection->getLastItem();

But for some reason $latestItem does not return the last updated item, but the last created_at item.

How can we solve this?