0

How can I fetch the data in the quote_item table for a specific item ? I'm trying to get the product name with "gift" at the end.

2

You can get data of one quote_item table using this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$itemResourceModel = $objectManager->create('\Magento\Quote\Model\ResourceModel\Quote\Item');
$quoteItemFactory = $objectManager->create('\Magento\Quote\Model\Quote\ItemFactory ');


$itemId = your id here
$quoteItem = $quoteItemFactory->create();
$itemResourceModel->load($quoteItem, $itemId);

echo $quoteItem->getName();
echo $quoteItem->getProductId();

I am not recommending you to use the object manager instead inject two classes in a block class of this phtml file and use it here.

1
  • Works like a charm, thank you very much !
    – Badong
    Mar 5 '20 at 14:47
0

You can get data of quote_item table using

Magento\Quote\Model\ResourceModel\Quote\Item\Collection collection class

like this..

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$quoteItemCollection = $objectManager->create('\Magento\Quote\Model\ResourceModel\Quote\Item\Collection');

foreach ($quoteItemCollection as $quoteItem) 
{
    echo $quoteItem->getName();
    echo $quoteItem->getProductId();
    ......
}

I am not recommending you to use the object manager instead inject this collection class in a block class of this phtml file and use it here.

And please check refer :

Get data from Quote_items table in Magento 2

3
  • What if I want to get only one item with a given id ?
    – Badong
    Mar 5 '20 at 13:16
  • what want you get ?? Mar 5 '20 at 13:25
  • I want to get one item in the collection, not all of them. For example, I want to get the data associated with item_id equal to 164
    – Badong
    Mar 5 '20 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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