tags:

views:

110

answers:

2

Hi,

How can I get the last running transaction Id ? (eg: 10000001) I've tried numerous ways, with no success.

+1  A: 

Try this:

$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
silvo
This works only if a valid checkout session is in progress (I hope I'm correct by saying this) - or in other words, it works when I invoke it from the checkout event.I wasn't clear on this in my question above, but I'm trying to get it without such a session in progress.
In this case you might try to get it directly from the db. I will post an example sql statement when I get back from work. In the meantime, could you state which magento version you're using?
silvo
+1  A: 

I was suddenly enlightened when I looked at the problem again at home. Why not get the last order increment id from the sales/order collection?

$orders = Mage::getModel('sales/order')->getCollection()
        ->setOrder('increment_id','DESC')
        ->setPageSize(1)
        ->setCurPage(1);

echo $orders->getFirstItem()->getIncrementId();

Tested and working on Magento 1.3.2.3

silvo
Amazing! I tried doing that, but was not successful. what does the setpageset do ?
setPageSize and setCurPage limit the number of items returned by the collection. In this case we just need one item - the one with the highest increment_id, so I've changed the page size to one item and requested only the first page.
silvo