Magento – How to get quote object through customer id in magento2

magento2quote

When customer login through customer id i have to get quote object.
In magento i have written this code.but in magento2 how to get quote collection.or quote id of that customer.

$quoteCollection = Mage::getModel('sales/quote')->getCollection()
                ->addFieldToFilter('customer_id', $customerId)
                ->addFieldToFilter('store_id', $store)
                ->addOrder('updated_at');
            $quote = $quoteCollection->getFirstItem();
            $quoteId = (int) $quote->getId();

Best Answer

First you need to create Quote Collection object

public function __construct(Template\Context $context,\Magento\Quote\Model\QuoteFactory $quoteFactory, array $data = [])
{
    parent::__construct($context, $data);
    $this->quoteFactory = $quoteFactory;
    $this->_isScopePrivate = true;
}

After that you need to filter Collation by customer id

public function getQuoteCollection($customerId)
{
    $quote = $this->quoteFactory->create()->getCollection()->addFieldToFilter('customer_id',$customerId);
    return $quote;
}