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.
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.
You can get Customer id from order object as below.
$order = $this->_objectManager->create('\Magento\Sales\Model\Order')->load($id);
$customerId = $order->getCustomerId();
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;
}
}
?>
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()