Magento 2 – How to Fetch Customer ID from Quote Object

magento2quote

I have my Quote object, I just want to fetch customer id from it.

Here is how I loaded the quote object,

protected $quoteRepository;

public function __construct(
    ...
    \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
    ....
) {
    ....
    $this->quoteRepository = $quoteRepository;
    ....
}

$quote = $this->quoteRepository->get($quoteId);

Best Answer

You can get the customer Id as follows.

$customerId = $quote->getCustomer()->getId();
Related Topic