How to get is_active column value from quote table ? Magento2
سؤال
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
المحلول
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.
لا تنتمي إلى magento.stackexchange