0

Is there anyway I could print out in a table in phtml the following: Entity_id , is_active and store Is it possible to get all active quote within a customer_id?

I want to show this in a table I was taking a look at quote DB and I can see all the details there but not sure how to show this in a phtml

1 Answer 1

2

To get quote items of a customer please use below code. You can pass customer object also in place of customer id.

<?php 
protected $quoteModel;

public function __construct(
    ...
    \Magento\Quote\Model\QuoteFactory $quoteFactory,
    \Magento\Quote\Model\ResourceModel\Quote $quoteModel
    ....
) {
    ....
    $this->quoteFactory = $quoteFactory;
    $this->quoteModel=$quoteModel;
    ....

}

$quote = $this->quoteFactory->create();
$customerQuote=$this->quoteModel->loadByCustomerId($quote,$customerId); // where `$customerId` is your `customer id`
$items=$customerQuote->getAllItems();
?>

Hope it will help Thanks

4
  • Would I be able to get is_active? I haven’t used this Jan 3, 2020 at 19:00
  • Yes you can get is_active for that you have to use quote item collection. 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); Jan 3, 2020 at 19:15
  • Let me know if my answer is helpful@Jack Brooks Jan 3, 2020 at 19:18
  • Hi @ManishChaubey I will get back to you soon as I tried this and thank you Jan 4, 2020 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.