Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I retrieve order info on checkout success page? 
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 

Hi there,

To integrate a third-party affiliation system I need to be able to get a few details about the order from the checkout success page. I can obviously get the order id, but I need to get the value of the order, and if a voucher was used, then the voucher details too.

I see that this is how to get the last order ID, but I can’t seem to understand where getLastRealOrderId() comes from?!?! Aaaargh:

Mage::getSingleton('checkout/session')->getLastRealOrderId()
 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

within checkout process the last order id was set to customer session. You can check block/sucess.php of onepage checkout, theres a method which loads RealOrderId by using Model of sales/order. You can extend this block and add needed methods to get additional datas from order.

cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 

Hi Stefan and thanks for that.

Now I’m using this to get the order total which is working fine.

$order Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$order->getGrandTotal();

My problem now is that I need to get the voucher code which I believe I would need to get from sales/quote rather than sales/order (at least it looks that way from the database). I can’t seem to pull back the details for giftcert_code field?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kenosis
Member
 
Total Posts:  45
Joined:  2008-03-14
 

We recently had to do something similar.  Perhaps this code snip will be of some help, although we didn’t need the giftcert_code field.

$_product = Mage::getModel(’catalog/product’);
$_order = Mage::getModel(’sales/order’);
$_order_id = Mage::getSingleton(’checkout/session’)->getLastOrderId();
$_order->load($_order_id);
$_items = $_order->getItemsCollection();
foreach ($_items as $_item):
$_sku_id = $_item->getSku();
$_product_id = $_product->getIdBySku($_sku_id);
$_product->load($_product_id);
// do something with the product info…
endforeach;

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

i checked database and giftcert_code is part of sales/order entity model.

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 
Wiseguy - 14 May 2008 07:26 AM

Hi Stefan and thanks for that.

Now I’m using this to get the order total which is working fine.

$order Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$order->getGrandTotal();

My problem now is that I need to get the voucher code which I believe I would need to get from sales/quote rather than sales/order (at least it looks that way from the database). I can’t seem to pull back the details for giftcert_code field?

Hi,

you have to check the model which contains your voucher code. Do you mean the coupon code? This code is also part of sales/order model. Try to print it by using $order->getCouponCode();

cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 

Sorry guys, after all that I was being an idiot!!!

I have been testing a coupon code rather than a gift certificate code hence it was blank!! This works a treat:

$order->getCouponCode()

I’ll debug more thoroughly next time starting at the obvious!

[edit]@zentrale - Looks like we posted at the same time wink []

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

look at my post before yours smile

cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 
[m><p> zentrale” date= -

look at my post before yours smile

cheers

Stefan

We must have been typing at the same time :D

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 

So just in case you need you stumble across this thread looking to do the same thing (most affiliation companies will want this), heres how to do it:

// Get the order id
$order_id Mage::getSingleton('checkout/session')->getLastRealOrderId();

// Set the order model
$order Mage::getModel('sales/order');

// Load the order with the successful order id
$order->loadByIncrementId($order_id);

// Get the order grand total
$order->getGrandTotal();

// Get any coupon codes
$order->getCouponCode()

// Get any gift certificate codes
$order->getGiftcertCode()
 
Magento Community Magento Community
Magento Community
Magento Community
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 

So just in case you need you stumble across this thread looking to do the same thing (most affiliation companies will want this), here’s how to do it:

// Get the order id
$order_id Mage::getSingleton('checkout/session')->getLastRealOrderId();

// Set the order model
$order Mage::getModel('sales/order');

// Load the order with the successful order id
$order->loadByIncrementId($order_id);

// Get the order grand total
$order->getGrandTotal();

// Get any coupon codes
$order->getCouponCode()

// Get any gift certificate codes
$order->getGiftcertCode()
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top