PHP Magento Tips

Get Last Order ID and Last Shipping Address of Customer In Magento

Rate this posting:
{[['']]}

With Below code you will get last order ID and last shipping Adress of Logged in Customer in Magento.

<?php

if ($this->isCustomerLoggedIn()) {
  
 $customerId = $this->getCustomer()->getId();
  
 $orders = Mage::getResourceModel('sales/order_collection')
 ->addFieldToSelect('*')
 ->addFieldToFilter('customer_id', $customerId)
 ->addAttributeToSort('created_at', 'DESC')
 ->setPageSize(1);
  
 $numOfOrders = $orders->getSize();
 if ($numOfOrders >= 1){
  
  // Last order ID
  $last_orderId = $orders->getFirstItem()->getId();
   
  $lastShippingAddressId = $orders->getFirstItem()->getShippingAddressId();

  $order = Mage::getModel('sales/order')->load($last_orderId);
  $address = $order->getShippingAddress();
  //$custName = $address->getName();
  //$custAddr = $address->getStreetFull();
  //$region = $address->getRegion();
  //$country = $address->getCountry();
  // Shipping Address oneline
  $onelineaddress = $address->format('oneline');
 }   
}
?>
Tag : Magento
0 Comments On "Get Last Order ID and Last Shipping Address of Customer In Magento"

Back To Top