Question

I want to get the value of the is_active column through the method $this-> getQuoteCollection ($customerId) -> getLastItem (), I used getColumnValues('is_active'), but it doesn't return the last column (is_active) of the element

Was it helpful?

Solution

There are two options to get is_active quote. 1) Load checkout session and get active quote id and base on that id you can load quote.

protected $_checkoutSession;

public function __construct (
    \Magento\Checkout\Model\Session $_checkoutSession
    ) {
    $this->_checkoutSession = $_checkoutSession;
}

public function execute(\Magento\Framework\Event\Observer $observer)
{
  $cartData = $this->_checkoutSession->getQuote()->getAllVisibleItems();
  $cartDataCount = count( $cartData );
}

2) Load quote collection factory, use addfieldtofilter and get is_active quote.

use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory as   QuoteFactory;

public function __construct(
    QuoteFactory $quoteFactory
) {
    $this->quoteFactory = $quoteFactory;

}
 $this->quoteFactory->create()->addFieldToFilter('quote_id',$quoteId)->addFieldToFilter('is_active',1);

Hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top