Get Quote_item table data
Question
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.
Solution
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.
OTHER TIPS
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 :
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange