Get last order or items of customer in magento

$_customer = Mage::getSingleton('customer/session')->getCustomer();
$orders = Mage::getResourceModel('sales/order_collection')
    ->addFieldToSelect('*')
    ->addFieldToFilter('customer_id', $_customer->getId())
    ->addAttributeToSort('created_at', 'DESC')
    ->setPageSize(1);
$items = Mage::getModel('sales/order')->getCollection()
    ->addFieldToSelect('*')
    ->join(array('item' => 'sales/order_item'), 'main_table.entity_id = item.order_id')
    ->addFieldToFilter('customer_id', $_customer->getId())
    ->addAttributeToSort('item.created_at', 'DESC')
    ->setPageSize(1);
var_dump($items->getData());die();


你可能感兴趣的:(Get last order or items of customer in magento)