Display data from Quote_item errorwhy getColumnValues('product_id') not work for Mage::getModel('sales/quote_item') collectionMagento 2 - Save value from custom input field to quote_itemHow to set additional data to quote_item table from controller in Magento 2?Get orderId from quote_itemMagento 2.3 Can't view module's front end page output?Magento 2.3 Error on Delete All Test Data from DatabaseData Migration > Eav step errorData migration from 1.9.2.4 to 2.3.1 - FailureHow to update custom column value in quote_item table magento 2How to display data from 2 tables that already have data on Magento 2.3
How to have a filled pattern
Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?
I'm feeling like my character doesn't fit the campaign
NOLOCK or Read Uncommitted locking / latching behaviours
Why did RFK loathe LBJ?
What does "spinning upon the shoals" mean?
Quotients of a ring of integers
Why SQL does not use the indexed view?
Troubling glyphs
How many Jimmys can fit?
Gory anime with pink haired girl escaping an asylum
What is the meaning of "prairie-dog" in this sentence?
Examples of fluid (including air) being used to transmit digital data?
What factors could lead to bishops establishing monastic armies?
How to evaluate the performance of open source solver?
Why am I getting unevenly-spread results when using $RANDOM?
How to gather entities into sets?
Is it acceptable that I plot a time-series figure with years increasing from right to left?
How to understand flavors and when to use combination of them?
Where are the Wazirs?
Sense of humor in your sci-fi stories
Passwordless authentication - how and when to invalidate a login code
When moving a unique_ptr into a lambda, why is it not possible to call reset?
Interpretation of non-significant results as "trends"
Display data from Quote_item error
why getColumnValues('product_id') not work for Mage::getModel('sales/quote_item') collectionMagento 2 - Save value from custom input field to quote_itemHow to set additional data to quote_item table from controller in Magento 2?Get orderId from quote_itemMagento 2.3 Can't view module's front end page output?Magento 2.3 Error on Delete All Test Data from DatabaseData Migration > Eav step errorData migration from 1.9.2.4 to 2.3.1 - FailureHow to update custom column value in quote_item table magento 2How to display data from 2 tables that already have data on Magento 2.3
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have tried to display the data from Quote_item table in the database to file .phtml but it shows this error
the code in Magento/MyHistory/Block/View.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
public function __constructor(
....
/Magento/Checkout/Model/Cart $cart
....)
...
$cart = $cart;
...
public function getCartData()
$data = $this->cart()->create()->getCollection()-
>addFieldToSelect('*');
return $data;
in Magento/MyHistory/view/frontend/template/index.phtml like this
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->create('MagentoCheckoutModelCart')-
>getCollection();
$orders->addFieldToSelect('*');
?>
<table class="data table" id="test-data-table">
<h2 style="color: red;">Your Order Detail</h2>
<caption class="table-caption">Look at this table</caption>
<thead>
<tr>
<th scope="col" class="col image">Image</th>
<th scope="col" class="col sku">Sku</th>
<th scope="col" class="col name">Name</th>
<th scope="col" class="col qty">Quantity</th>
<th scope="col" class="col created_at">Create at</th>
<th scope="col" class="col updated_at">Update at</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $item): ?>
<tr>
<td data-th="Title" class="col sku"><?php echo $item-
>getImage(); ?></td>
<td data-th="Title" class="col sku"><?php echo $item-
>getSku(); ?></td>
<td data-th="Author" class="col name"><?php echo $item-
>getName(); ?></td>
<td data-th="Content" class="col qty"><?php echo $item-
>getQty(); ?></td>
<td data-th="Date" class="col created_at"><?php echo
$item->getCreatedAt(); ?></td>
<td data-th="Date" class="col updated_at"><?php echo
$item->getUpdatedAt(); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Anyone can help me, please?
magento2.3 phtml quoteitem
add a comment |
I have tried to display the data from Quote_item table in the database to file .phtml but it shows this error
the code in Magento/MyHistory/Block/View.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
public function __constructor(
....
/Magento/Checkout/Model/Cart $cart
....)
...
$cart = $cart;
...
public function getCartData()
$data = $this->cart()->create()->getCollection()-
>addFieldToSelect('*');
return $data;
in Magento/MyHistory/view/frontend/template/index.phtml like this
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->create('MagentoCheckoutModelCart')-
>getCollection();
$orders->addFieldToSelect('*');
?>
<table class="data table" id="test-data-table">
<h2 style="color: red;">Your Order Detail</h2>
<caption class="table-caption">Look at this table</caption>
<thead>
<tr>
<th scope="col" class="col image">Image</th>
<th scope="col" class="col sku">Sku</th>
<th scope="col" class="col name">Name</th>
<th scope="col" class="col qty">Quantity</th>
<th scope="col" class="col created_at">Create at</th>
<th scope="col" class="col updated_at">Update at</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $item): ?>
<tr>
<td data-th="Title" class="col sku"><?php echo $item-
>getImage(); ?></td>
<td data-th="Title" class="col sku"><?php echo $item-
>getSku(); ?></td>
<td data-th="Author" class="col name"><?php echo $item-
>getName(); ?></td>
<td data-th="Content" class="col qty"><?php echo $item-
>getQty(); ?></td>
<td data-th="Date" class="col created_at"><?php echo
$item->getCreatedAt(); ?></td>
<td data-th="Date" class="col updated_at"><?php echo
$item->getUpdatedAt(); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Anyone can help me, please?
magento2.3 phtml quoteitem
Please add the code here
– Ravi Soni
Jun 28 at 7:19
please attached your code
– Rk Rathod
Jun 28 at 7:31
It seems like your collection object is blank. Please check that
– nishu
Jun 28 at 7:32
I do not understand it clearly. Can you explain it to me? I am new to Magento 2
– Kite Hany
Jun 28 at 7:34
add a comment |
I have tried to display the data from Quote_item table in the database to file .phtml but it shows this error
the code in Magento/MyHistory/Block/View.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
public function __constructor(
....
/Magento/Checkout/Model/Cart $cart
....)
...
$cart = $cart;
...
public function getCartData()
$data = $this->cart()->create()->getCollection()-
>addFieldToSelect('*');
return $data;
in Magento/MyHistory/view/frontend/template/index.phtml like this
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->create('MagentoCheckoutModelCart')-
>getCollection();
$orders->addFieldToSelect('*');
?>
<table class="data table" id="test-data-table">
<h2 style="color: red;">Your Order Detail</h2>
<caption class="table-caption">Look at this table</caption>
<thead>
<tr>
<th scope="col" class="col image">Image</th>
<th scope="col" class="col sku">Sku</th>
<th scope="col" class="col name">Name</th>
<th scope="col" class="col qty">Quantity</th>
<th scope="col" class="col created_at">Create at</th>
<th scope="col" class="col updated_at">Update at</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $item): ?>
<tr>
<td data-th="Title" class="col sku"><?php echo $item-
>getImage(); ?></td>
<td data-th="Title" class="col sku"><?php echo $item-
>getSku(); ?></td>
<td data-th="Author" class="col name"><?php echo $item-
>getName(); ?></td>
<td data-th="Content" class="col qty"><?php echo $item-
>getQty(); ?></td>
<td data-th="Date" class="col created_at"><?php echo
$item->getCreatedAt(); ?></td>
<td data-th="Date" class="col updated_at"><?php echo
$item->getUpdatedAt(); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Anyone can help me, please?
magento2.3 phtml quoteitem
I have tried to display the data from Quote_item table in the database to file .phtml but it shows this error
the code in Magento/MyHistory/Block/View.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
public function __constructor(
....
/Magento/Checkout/Model/Cart $cart
....)
...
$cart = $cart;
...
public function getCartData()
$data = $this->cart()->create()->getCollection()-
>addFieldToSelect('*');
return $data;
in Magento/MyHistory/view/frontend/template/index.phtml like this
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->create('MagentoCheckoutModelCart')-
>getCollection();
$orders->addFieldToSelect('*');
?>
<table class="data table" id="test-data-table">
<h2 style="color: red;">Your Order Detail</h2>
<caption class="table-caption">Look at this table</caption>
<thead>
<tr>
<th scope="col" class="col image">Image</th>
<th scope="col" class="col sku">Sku</th>
<th scope="col" class="col name">Name</th>
<th scope="col" class="col qty">Quantity</th>
<th scope="col" class="col created_at">Create at</th>
<th scope="col" class="col updated_at">Update at</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $item): ?>
<tr>
<td data-th="Title" class="col sku"><?php echo $item-
>getImage(); ?></td>
<td data-th="Title" class="col sku"><?php echo $item-
>getSku(); ?></td>
<td data-th="Author" class="col name"><?php echo $item-
>getName(); ?></td>
<td data-th="Content" class="col qty"><?php echo $item-
>getQty(); ?></td>
<td data-th="Date" class="col created_at"><?php echo
$item->getCreatedAt(); ?></td>
<td data-th="Date" class="col updated_at"><?php echo
$item->getUpdatedAt(); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Anyone can help me, please?
magento2.3 phtml quoteitem
magento2.3 phtml quoteitem
edited Jun 28 at 7:31
Kite Hany
asked Jun 28 at 7:18
Kite HanyKite Hany
589 bronze badges
589 bronze badges
Please add the code here
– Ravi Soni
Jun 28 at 7:19
please attached your code
– Rk Rathod
Jun 28 at 7:31
It seems like your collection object is blank. Please check that
– nishu
Jun 28 at 7:32
I do not understand it clearly. Can you explain it to me? I am new to Magento 2
– Kite Hany
Jun 28 at 7:34
add a comment |
Please add the code here
– Ravi Soni
Jun 28 at 7:19
please attached your code
– Rk Rathod
Jun 28 at 7:31
It seems like your collection object is blank. Please check that
– nishu
Jun 28 at 7:32
I do not understand it clearly. Can you explain it to me? I am new to Magento 2
– Kite Hany
Jun 28 at 7:34
Please add the code here
– Ravi Soni
Jun 28 at 7:19
Please add the code here
– Ravi Soni
Jun 28 at 7:19
please attached your code
– Rk Rathod
Jun 28 at 7:31
please attached your code
– Rk Rathod
Jun 28 at 7:31
It seems like your collection object is blank. Please check that
– nishu
Jun 28 at 7:32
It seems like your collection object is blank. Please check that
– nishu
Jun 28 at 7:32
I do not understand it clearly. Can you explain it to me? I am new to Magento 2
– Kite Hany
Jun 28 at 7:34
I do not understand it clearly. Can you explain it to me? I am new to Magento 2
– Kite Hany
Jun 28 at 7:34
add a comment |
3 Answers
3
active
oldest
votes
You can use the below code to get data from Quote Item
MagentoHistoryBlockView.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
protected $cart;
public function __constructor(
...
MagentoCheckoutModelCart $cart
...
)
$cart = $cart;
public function getCartData()
$itemsCollection = $cart->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
// get quote items array
$items = $cart->getQuote()->getAllItems();
return $items;
Magento/MyHistory/view/frontend/template/index.phtm
<?php $cartData = $block->getCartData(); ?>
Now here in the Phtml you can get your data with using this $cartData variable.
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
add a comment |
Try like this :
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$itemsCollection = $orders->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $orders->getQuote()->getAllVisibleItems();
// get quote items array
$items = $orders->getQuote()->getAllItems();
foreach($items as $item)
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
add a comment |
You get a fatol error for ->addFieldToSelect('*') you can use addFieldToSelect when you inject collection model in your construct. and also you don't have to use addFieldToSelect you can also get data without it.
app/code/Namespace/Modulename/Block/YourCustomBlock.php
class YourCustomBlock extends MagentoFrameworkViewElementTemplate
protected $_cart;
protected $_checkoutSession;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelCart $cart,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_cart = $cart;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
public function getCart()
return $this->_cart;
public function getCheckoutSession()
return $this->_checkoutSession;
Your phtml file should be like this
// Get all items in cart
$quote = $block->getCheckoutSession()->getQuote();
$items = $quote->getAllItems();
foreach($items as $item)
echo 'Product Id: ' . $item->getProductId() . '<br />';
echo 'Name: ' . $item->getName() . '<br />';
echo 'Sku: ' . $item->getSku() . '<br />';
echo 'Quantity: ' . $item->getQty() . '<br />';
echo 'Price: ' . $item->getPrice() . '<br />';
echo "<br /><br />";
// Get total items and total quantity in cart
$totalItems = $quote->getItemsCount();
$totalQuantity = $quote->getItemsQty();
//Get subtotal and grand total price of cart
$subTotal = $quote->getSubtotal();
$grandTotal = $quote->getGrandTotal();
//Get billing and shipping addresses
$billingAddress = $quote->getBillingAddress();
$shippingAddress = $quote->getShippingAddress();
Take reference from Get Shopping Cart Data (Items, Subtotal, Grand Total, Billing & Shipping Address) in Magento 2? and Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address
I hope it helps!
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
removevarandgeneratedfolder then check
– Chirag Patel
Jun 28 at 9:50
check error invar/logfile
– Chirag Patel
Jun 28 at 10:03
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280012%2fdisplay-data-from-quote-item-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the below code to get data from Quote Item
MagentoHistoryBlockView.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
protected $cart;
public function __constructor(
...
MagentoCheckoutModelCart $cart
...
)
$cart = $cart;
public function getCartData()
$itemsCollection = $cart->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
// get quote items array
$items = $cart->getQuote()->getAllItems();
return $items;
Magento/MyHistory/view/frontend/template/index.phtm
<?php $cartData = $block->getCartData(); ?>
Now here in the Phtml you can get your data with using this $cartData variable.
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
add a comment |
You can use the below code to get data from Quote Item
MagentoHistoryBlockView.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
protected $cart;
public function __constructor(
...
MagentoCheckoutModelCart $cart
...
)
$cart = $cart;
public function getCartData()
$itemsCollection = $cart->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
// get quote items array
$items = $cart->getQuote()->getAllItems();
return $items;
Magento/MyHistory/view/frontend/template/index.phtm
<?php $cartData = $block->getCartData(); ?>
Now here in the Phtml you can get your data with using this $cartData variable.
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
add a comment |
You can use the below code to get data from Quote Item
MagentoHistoryBlockView.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
protected $cart;
public function __constructor(
...
MagentoCheckoutModelCart $cart
...
)
$cart = $cart;
public function getCartData()
$itemsCollection = $cart->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
// get quote items array
$items = $cart->getQuote()->getAllItems();
return $items;
Magento/MyHistory/view/frontend/template/index.phtm
<?php $cartData = $block->getCartData(); ?>
Now here in the Phtml you can get your data with using this $cartData variable.
You can use the below code to get data from Quote Item
MagentoHistoryBlockView.php
<?php
namespace MagentoHistoryBlock;
class View extends MagentoFrameworkViewElementTemplate
protected $cart;
public function __constructor(
...
MagentoCheckoutModelCart $cart
...
)
$cart = $cart;
public function getCartData()
$itemsCollection = $cart->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
// get quote items array
$items = $cart->getQuote()->getAllItems();
return $items;
Magento/MyHistory/view/frontend/template/index.phtm
<?php $cartData = $block->getCartData(); ?>
Now here in the Phtml you can get your data with using this $cartData variable.
edited Jun 28 at 7:46
answered Jun 28 at 7:35
Ravi SoniRavi Soni
1,0315 silver badges18 bronze badges
1,0315 silver badges18 bronze badges
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
add a comment |
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
It's not working for me @Ravi Soni
– Kite Hany
Jun 28 at 7:43
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
I have updated my answer please check now.
– Ravi Soni
Jun 28 at 7:47
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Sorry, @Ravi Soni, it does not display any data for me.
– Kite Hany
Jun 28 at 7:55
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
Now what error you get can you please mention here.
– Ravi Soni
Jun 28 at 7:56
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
it does not display any data for me. Although I already echo the data it still displays an empty page
– Kite Hany
Jun 28 at 7:58
add a comment |
Try like this :
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$itemsCollection = $orders->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $orders->getQuote()->getAllVisibleItems();
// get quote items array
$items = $orders->getQuote()->getAllItems();
foreach($items as $item)
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
add a comment |
Try like this :
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$itemsCollection = $orders->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $orders->getQuote()->getAllVisibleItems();
// get quote items array
$items = $orders->getQuote()->getAllItems();
foreach($items as $item)
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
add a comment |
Try like this :
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$itemsCollection = $orders->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $orders->getQuote()->getAllVisibleItems();
// get quote items array
$items = $orders->getQuote()->getAllItems();
foreach($items as $item)
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
Try like this :
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$itemsCollection = $orders->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = $orders->getQuote()->getAllVisibleItems();
// get quote items array
$items = $orders->getQuote()->getAllItems();
foreach($items as $item)
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
answered Jun 28 at 7:52
fmsthirdfmsthird
3,4774 gold badges7 silver badges31 bronze badges
3,4774 gold badges7 silver badges31 bronze badges
add a comment |
add a comment |
You get a fatol error for ->addFieldToSelect('*') you can use addFieldToSelect when you inject collection model in your construct. and also you don't have to use addFieldToSelect you can also get data without it.
app/code/Namespace/Modulename/Block/YourCustomBlock.php
class YourCustomBlock extends MagentoFrameworkViewElementTemplate
protected $_cart;
protected $_checkoutSession;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelCart $cart,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_cart = $cart;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
public function getCart()
return $this->_cart;
public function getCheckoutSession()
return $this->_checkoutSession;
Your phtml file should be like this
// Get all items in cart
$quote = $block->getCheckoutSession()->getQuote();
$items = $quote->getAllItems();
foreach($items as $item)
echo 'Product Id: ' . $item->getProductId() . '<br />';
echo 'Name: ' . $item->getName() . '<br />';
echo 'Sku: ' . $item->getSku() . '<br />';
echo 'Quantity: ' . $item->getQty() . '<br />';
echo 'Price: ' . $item->getPrice() . '<br />';
echo "<br /><br />";
// Get total items and total quantity in cart
$totalItems = $quote->getItemsCount();
$totalQuantity = $quote->getItemsQty();
//Get subtotal and grand total price of cart
$subTotal = $quote->getSubtotal();
$grandTotal = $quote->getGrandTotal();
//Get billing and shipping addresses
$billingAddress = $quote->getBillingAddress();
$shippingAddress = $quote->getShippingAddress();
Take reference from Get Shopping Cart Data (Items, Subtotal, Grand Total, Billing & Shipping Address) in Magento 2? and Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address
I hope it helps!
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
removevarandgeneratedfolder then check
– Chirag Patel
Jun 28 at 9:50
check error invar/logfile
– Chirag Patel
Jun 28 at 10:03
add a comment |
You get a fatol error for ->addFieldToSelect('*') you can use addFieldToSelect when you inject collection model in your construct. and also you don't have to use addFieldToSelect you can also get data without it.
app/code/Namespace/Modulename/Block/YourCustomBlock.php
class YourCustomBlock extends MagentoFrameworkViewElementTemplate
protected $_cart;
protected $_checkoutSession;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelCart $cart,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_cart = $cart;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
public function getCart()
return $this->_cart;
public function getCheckoutSession()
return $this->_checkoutSession;
Your phtml file should be like this
// Get all items in cart
$quote = $block->getCheckoutSession()->getQuote();
$items = $quote->getAllItems();
foreach($items as $item)
echo 'Product Id: ' . $item->getProductId() . '<br />';
echo 'Name: ' . $item->getName() . '<br />';
echo 'Sku: ' . $item->getSku() . '<br />';
echo 'Quantity: ' . $item->getQty() . '<br />';
echo 'Price: ' . $item->getPrice() . '<br />';
echo "<br /><br />";
// Get total items and total quantity in cart
$totalItems = $quote->getItemsCount();
$totalQuantity = $quote->getItemsQty();
//Get subtotal and grand total price of cart
$subTotal = $quote->getSubtotal();
$grandTotal = $quote->getGrandTotal();
//Get billing and shipping addresses
$billingAddress = $quote->getBillingAddress();
$shippingAddress = $quote->getShippingAddress();
Take reference from Get Shopping Cart Data (Items, Subtotal, Grand Total, Billing & Shipping Address) in Magento 2? and Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address
I hope it helps!
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
removevarandgeneratedfolder then check
– Chirag Patel
Jun 28 at 9:50
check error invar/logfile
– Chirag Patel
Jun 28 at 10:03
add a comment |
You get a fatol error for ->addFieldToSelect('*') you can use addFieldToSelect when you inject collection model in your construct. and also you don't have to use addFieldToSelect you can also get data without it.
app/code/Namespace/Modulename/Block/YourCustomBlock.php
class YourCustomBlock extends MagentoFrameworkViewElementTemplate
protected $_cart;
protected $_checkoutSession;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelCart $cart,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_cart = $cart;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
public function getCart()
return $this->_cart;
public function getCheckoutSession()
return $this->_checkoutSession;
Your phtml file should be like this
// Get all items in cart
$quote = $block->getCheckoutSession()->getQuote();
$items = $quote->getAllItems();
foreach($items as $item)
echo 'Product Id: ' . $item->getProductId() . '<br />';
echo 'Name: ' . $item->getName() . '<br />';
echo 'Sku: ' . $item->getSku() . '<br />';
echo 'Quantity: ' . $item->getQty() . '<br />';
echo 'Price: ' . $item->getPrice() . '<br />';
echo "<br /><br />";
// Get total items and total quantity in cart
$totalItems = $quote->getItemsCount();
$totalQuantity = $quote->getItemsQty();
//Get subtotal and grand total price of cart
$subTotal = $quote->getSubtotal();
$grandTotal = $quote->getGrandTotal();
//Get billing and shipping addresses
$billingAddress = $quote->getBillingAddress();
$shippingAddress = $quote->getShippingAddress();
Take reference from Get Shopping Cart Data (Items, Subtotal, Grand Total, Billing & Shipping Address) in Magento 2? and Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address
I hope it helps!
You get a fatol error for ->addFieldToSelect('*') you can use addFieldToSelect when you inject collection model in your construct. and also you don't have to use addFieldToSelect you can also get data without it.
app/code/Namespace/Modulename/Block/YourCustomBlock.php
class YourCustomBlock extends MagentoFrameworkViewElementTemplate
protected $_cart;
protected $_checkoutSession;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelCart $cart,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_cart = $cart;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
public function getCart()
return $this->_cart;
public function getCheckoutSession()
return $this->_checkoutSession;
Your phtml file should be like this
// Get all items in cart
$quote = $block->getCheckoutSession()->getQuote();
$items = $quote->getAllItems();
foreach($items as $item)
echo 'Product Id: ' . $item->getProductId() . '<br />';
echo 'Name: ' . $item->getName() . '<br />';
echo 'Sku: ' . $item->getSku() . '<br />';
echo 'Quantity: ' . $item->getQty() . '<br />';
echo 'Price: ' . $item->getPrice() . '<br />';
echo "<br /><br />";
// Get total items and total quantity in cart
$totalItems = $quote->getItemsCount();
$totalQuantity = $quote->getItemsQty();
//Get subtotal and grand total price of cart
$subTotal = $quote->getSubtotal();
$grandTotal = $quote->getGrandTotal();
//Get billing and shipping addresses
$billingAddress = $quote->getBillingAddress();
$shippingAddress = $quote->getShippingAddress();
Take reference from Get Shopping Cart Data (Items, Subtotal, Grand Total, Billing & Shipping Address) in Magento 2? and Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address
I hope it helps!
answered Jun 28 at 9:10
Chirag PatelChirag Patel
3,6816 silver badges28 bronze badges
3,6816 silver badges28 bronze badges
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
removevarandgeneratedfolder then check
– Chirag Patel
Jun 28 at 9:50
check error invar/logfile
– Chirag Patel
Jun 28 at 10:03
add a comment |
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
removevarandgeneratedfolder then check
– Chirag Patel
Jun 28 at 9:50
check error invar/logfile
– Chirag Patel
Jun 28 at 10:03
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
Thank for the answer but its display it displays this Uncaught Error: Call to a member function getQuote() on null in C:xampphtdocsmagento2appcodeMagentoHistoryviewfrontendtemplatesindex.phtml:3 Stack trace: #0 C:xampphtdocsmagento2libinternalMagentoFrameworkViewTemplateEnginePhp.php(59): include() #1 C:xampphtdocsmagento2libinternalMagentoFrameworkViewElementTemplate.php(270): MagentoFrameworkViewTemplateEnginePhp->render(Object(MagentoFrameworkViewElementTemplate), 'C:/xampp/htdocs...', Array) #2
– Kite Hany
Jun 28 at 9:31
remove
var and generated folder then check– Chirag Patel
Jun 28 at 9:50
remove
var and generated folder then check– Chirag Patel
Jun 28 at 9:50
check error in
var/log file– Chirag Patel
Jun 28 at 10:03
check error in
var/log file– Chirag Patel
Jun 28 at 10:03
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f280012%2fdisplay-data-from-quote-item-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please add the code here
– Ravi Soni
Jun 28 at 7:19
please attached your code
– Rk Rathod
Jun 28 at 7:31
It seems like your collection object is blank. Please check that
– nishu
Jun 28 at 7:32
I do not understand it clearly. Can you explain it to me? I am new to Magento 2
– Kite Hany
Jun 28 at 7:34