Get data from Quote_items table in Magento 2
-
06-03-2021 - |
Frage
Lösung
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 recommend you to use object manager instead inject this collecton class in block class of this phtml file and use it here.
Andere Tipps
You can get quote item collection by quote id using this below way :
protected $quoteFactory;
public function __construct(
.....
\Magento\Quote\Model\QuoteFactory $quoteFactory
......
){
$this->quoteFactory = $quoteFactory;
}
public function yourFunction()
{
$quote = $this->quoteFactory->create()->load($quoteId);
$items = $quote->getAllItems();
foreach ($items as $item)
{
echo $item->getId()."<br>";
echo $item->getName()."<br>";
echo $item->getProductId()."<br>";
}
}
Now, print $items. You'll get data. Hope, it will helpful for you.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange