0

how to get quote item of the current quote? i have already get the quote i'll share some code .

$quote = $this->quoteFactory->create()->load(13);
//echo "<pre>";print_r($collection->getData());
$shippingAddress = $quote->getShippingAddress();

//form data
$firstname = $quote->getCustomerFirstname();
$lastname = $quote->getCustomerLastname();
$mail = $quote->getcustomer_email();
//shipping Address
$city = $shippingAddress->getCity();
$address1 = $shippingAddress->getStreet(1); // Get the first line of the street address
$address2 = $shippingAddress->getStreet(1);
//$address2 = $shippingAddress->getAddress2(); // Region code
//$postcode = $shippingAddress->getPostcode();
//$country = $shippingAddress->getCountry();
$phone = $shippingAddress->getTelephone();
$state = $shippingAddress->getRegion();
$zip= $shippingAddress->getPostcode();

here i get the quote now i also want to get the quote item

2 Answers 2

0

Try Below code.

<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend'); // or 'adminhtml' if you're running the code in the admin area

// Get the current quote
$quote = $objectManager->get('\Magento\Checkout\Model\Session')->getQuote();

// Get quote items
$items = $quote->getAllVisibleItems();

// Loop through each item
foreach ($items as $item) {
    // Get item details
    $itemId = $item->getId();
    $productName = $item->getName();
    $productPrice = $item->getPrice();
    // Additional item details can be obtained using other methods of $item object
    
    // Do something with the item details
    echo "Item ID: $itemId, Product Name: $productName, Price: $productPrice <br>";
}

THANKS.

0

To get the quote item of the current quote you can use the Here's how you can do it

$quoteId = 13; // Your quote ID
$quote = $this->quoteFactory->create()->load($quoteId);

    // Check if the quote is loaded successfully
    if ($quote->getId()) {
        // Get the items of the quote
        // Depending on the use case, you can use \Magento\Quote\Model\Quote::getAllItems or \Magento\Quote\Model\Quote::getAllVisibleItems
        $items = $quote->getAllVisibleItems();
    
        // Loop through the items to perform your operations
        foreach ($items as $item) {
             // Access individual item data
             $itemId = $item->getId();
             $productName = $item->getName();
        }
    } else {
           // Quote with the specified ID not found
           echo "Quote not found!";
    }

Your Answer

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

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