3

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();
1
  • 1
    Try with $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customer = $objectManager->create('Magento\Quote\Model\Quote')->load($customerId);
    – Jackson
    Dec 28, 2016 at 6:08

1 Answer 1

3

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;
}

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.