0

Please Help me on this , i want get full customer data using order id.

1) I have a order id in my phtml file i want to get whole data using block class and phtml file.

2

3 Answers 3

0

You can get Customer id from order object as below.

$order = $this->_objectManager->create('\Magento\Sales\Model\Order')->load($id);
$customerId = $order->getCustomerId();
0

you can get the customer id from order like below :

$order = $this->_objectManager->create('\Magento\Sales\Model\Order')->load($id);
$customerId = $order->getCustomerId();

and then use customer id to fetch customer details using api factory like below :

<?php

namespace Yourcompany\Customer\Helper {

/**
 * Eav data helper
 */
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $customerRepository;

    public function __construct(
        \Magento\Customer\Api\CustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
        $this->customerRepository = $customerRepositoryFactory->create();
    }

    public function LoadCustomerById($customerId) {
         $cst = $this->customerRepository->getById($customerId);
         return $cst;
    } 

}

?>
0

You can use this below code :

protected $salesOrderFactory;

protected $customerRepositoryFactory;

public function __construct(
    ......
    \Magento\Sales\Model\OrderFactory $salesOrderFactory,
    \Magento\Customer\Api\CustomerRepositoryInterfaceFactory $customerRepositoryFactory
    ......
){
    ......
    $this->salesOrderFactory = $salesOrderFactory;
    $this->customerRepositoryFactory = customerRepositoryFactory;
    ......
}

public function yourFunction()
{
    $salesData = $this->salesOrderFactory->create()->load($id);
    $customerId = $salesData->getCustomerId();
    $customerInstance = $this->customerRepository->getById($customerId);
    return $customerInstance;
}

Note: Avoid to use \Magento\Framework\App\ObjectManager::getInstance()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.