문제

I am new to Magento 2 so I do not understand much about select data from the table in Localhost also which file I need to create

I want to display data from Quote_item table

enter image description here

in the .phtml file, and What I need to do in Block and xml file

If anyone can help me step by step, it's very useful for me

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top