Cart details not getting in mini cart
For some purpose (something like popup) I'm trying to fetch cart details in minicart.phtml from Magento2vendormagentomodule-checkoutviewfrontendtemplatescartminicart.phtml.
I directly modified core file just for checking purpose only. The point is cart details (from below code) are displaying only in cart page. It is not displaying in other pages like home page, product, category pages.I'm using default Magento EE 2.2.5 Luma theme. Any suggestion will be appreciated...
Below is my code (It's dirty, just for checking purpose),
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$cart = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$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();
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 />";
}
I tried with block also through the constructor (like proper way) magento2eevendormagentomodule-checkoutBlockOnepage.php
But same like working only in cart page. Not in other pages..
Update:
I'm just wondering below piece of code for fetching product details is working but not for cart.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->load();
foreach ($collection as $product){
echo 'Name = '.$product->getName().'<br>';
break;
}
magento2 blocks mini-cart
add a comment |
For some purpose (something like popup) I'm trying to fetch cart details in minicart.phtml from Magento2vendormagentomodule-checkoutviewfrontendtemplatescartminicart.phtml.
I directly modified core file just for checking purpose only. The point is cart details (from below code) are displaying only in cart page. It is not displaying in other pages like home page, product, category pages.I'm using default Magento EE 2.2.5 Luma theme. Any suggestion will be appreciated...
Below is my code (It's dirty, just for checking purpose),
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$cart = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$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();
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 />";
}
I tried with block also through the constructor (like proper way) magento2eevendormagentomodule-checkoutBlockOnepage.php
But same like working only in cart page. Not in other pages..
Update:
I'm just wondering below piece of code for fetching product details is working but not for cart.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->load();
foreach ($collection as $product){
echo 'Name = '.$product->getName().'<br>';
break;
}
magento2 blocks mini-cart
try with$objectManager->create
instead of$objectManager->get
– Keyur Shah
2 days ago
@KeyurShah Thanks for your comment, I tried with that also. But it doesn't work.
– Elavarasan
yesterday
add a comment |
For some purpose (something like popup) I'm trying to fetch cart details in minicart.phtml from Magento2vendormagentomodule-checkoutviewfrontendtemplatescartminicart.phtml.
I directly modified core file just for checking purpose only. The point is cart details (from below code) are displaying only in cart page. It is not displaying in other pages like home page, product, category pages.I'm using default Magento EE 2.2.5 Luma theme. Any suggestion will be appreciated...
Below is my code (It's dirty, just for checking purpose),
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$cart = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$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();
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 />";
}
I tried with block also through the constructor (like proper way) magento2eevendormagentomodule-checkoutBlockOnepage.php
But same like working only in cart page. Not in other pages..
Update:
I'm just wondering below piece of code for fetching product details is working but not for cart.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->load();
foreach ($collection as $product){
echo 'Name = '.$product->getName().'<br>';
break;
}
magento2 blocks mini-cart
For some purpose (something like popup) I'm trying to fetch cart details in minicart.phtml from Magento2vendormagentomodule-checkoutviewfrontendtemplatescartminicart.phtml.
I directly modified core file just for checking purpose only. The point is cart details (from below code) are displaying only in cart page. It is not displaying in other pages like home page, product, category pages.I'm using default Magento EE 2.2.5 Luma theme. Any suggestion will be appreciated...
Below is my code (It's dirty, just for checking purpose),
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$cart = $objectManager->get('MagentoCheckoutModelCart');
// get quote items collection
$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();
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 />";
}
I tried with block also through the constructor (like proper way) magento2eevendormagentomodule-checkoutBlockOnepage.php
But same like working only in cart page. Not in other pages..
Update:
I'm just wondering below piece of code for fetching product details is working but not for cart.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
->load();
foreach ($collection as $product){
echo 'Name = '.$product->getName().'<br>';
break;
}
magento2 blocks mini-cart
magento2 blocks mini-cart
edited yesterday
Elavarasan
asked 2 days ago
ElavarasanElavarasan
548420
548420
try with$objectManager->create
instead of$objectManager->get
– Keyur Shah
2 days ago
@KeyurShah Thanks for your comment, I tried with that also. But it doesn't work.
– Elavarasan
yesterday
add a comment |
try with$objectManager->create
instead of$objectManager->get
– Keyur Shah
2 days ago
@KeyurShah Thanks for your comment, I tried with that also. But it doesn't work.
– Elavarasan
yesterday
try with
$objectManager->create
instead of $objectManager->get
– Keyur Shah
2 days ago
try with
$objectManager->create
instead of $objectManager->get
– Keyur Shah
2 days ago
@KeyurShah Thanks for your comment, I tried with that also. But it doesn't work.
– Elavarasan
yesterday
@KeyurShah Thanks for your comment, I tried with that also. But it doesn't work.
– Elavarasan
yesterday
add a comment |
3 Answers
3
active
oldest
votes
Little Modifications in your code.
Not sure but it should work I had same issue while ago.
Little modifications in your method.
You can give a try with MagentoCheckoutModelSession
.
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
add a comment |
We are using below code on our custom phtml file which is located under
/view/frontend/templates/checkout/cart/custom.phtml
$om = MagentoFrameworkAppObjectManager::getInstance();
//Getting cart Item//
$quote = $om->create('MagentoCheckoutModelCart')->getQuote();
$quoteitems = $quote->getAllVisibleItems();
You can try this one.
New contributor
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
add a comment |
Get cart items from customer local storage.
And render it using knock out.
You can get Cart item details of the guest user also,
in your js file
define([
'jquery',
'knockout',
'Magento_Customer/js/customer-data',
'uiComponent'
], function ($, ko, customerData, Component) {
return Component.extend({
initialize: function () {
self = this;
self.cart = customerData.get('cart');
let cartData = self.cart().items ? self.cart().items: ;
cartData.map(function(item) {
console.log(item.product_id);
console.log(item.product_name);
console.log(item.product_sku);
});
},
});
});
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
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%2f257414%2fcart-details-not-getting-in-mini-cart%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
Little Modifications in your code.
Not sure but it should work I had same issue while ago.
Little modifications in your method.
You can give a try with MagentoCheckoutModelSession
.
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
add a comment |
Little Modifications in your code.
Not sure but it should work I had same issue while ago.
Little modifications in your method.
You can give a try with MagentoCheckoutModelSession
.
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
add a comment |
Little Modifications in your code.
Not sure but it should work I had same issue while ago.
Little modifications in your method.
You can give a try with MagentoCheckoutModelSession
.
Little Modifications in your code.
Not sure but it should work I had same issue while ago.
Little modifications in your method.
You can give a try with MagentoCheckoutModelSession
.
answered 2 days ago
VivekVivek
1,311324
1,311324
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
add a comment |
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
Thanks for your comment, but I already tried with Session also. Still it doesn't work
– Elavarasan
yesterday
add a comment |
We are using below code on our custom phtml file which is located under
/view/frontend/templates/checkout/cart/custom.phtml
$om = MagentoFrameworkAppObjectManager::getInstance();
//Getting cart Item//
$quote = $om->create('MagentoCheckoutModelCart')->getQuote();
$quoteitems = $quote->getAllVisibleItems();
You can try this one.
New contributor
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
add a comment |
We are using below code on our custom phtml file which is located under
/view/frontend/templates/checkout/cart/custom.phtml
$om = MagentoFrameworkAppObjectManager::getInstance();
//Getting cart Item//
$quote = $om->create('MagentoCheckoutModelCart')->getQuote();
$quoteitems = $quote->getAllVisibleItems();
You can try this one.
New contributor
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
add a comment |
We are using below code on our custom phtml file which is located under
/view/frontend/templates/checkout/cart/custom.phtml
$om = MagentoFrameworkAppObjectManager::getInstance();
//Getting cart Item//
$quote = $om->create('MagentoCheckoutModelCart')->getQuote();
$quoteitems = $quote->getAllVisibleItems();
You can try this one.
New contributor
We are using below code on our custom phtml file which is located under
/view/frontend/templates/checkout/cart/custom.phtml
$om = MagentoFrameworkAppObjectManager::getInstance();
//Getting cart Item//
$quote = $om->create('MagentoCheckoutModelCart')->getQuote();
$quoteitems = $quote->getAllVisibleItems();
You can try this one.
New contributor
edited yesterday
Piyush
4,76872053
4,76872053
New contributor
answered yesterday
ThamoThamo
112
112
New contributor
New contributor
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
add a comment |
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
I want to have with minicart.phtml so that it will available in all pages.
– Elavarasan
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
The main reason of not showing the data on minicart at other pages are coming from cache and you need to alter the mini cart content by using standard Knockout JS concept. Cart page wont come from cache and system is fetching and showing your information on the fly of render. Please refer the below post which may give some better idea. webkul.com/blog/…
– Thamo
yesterday
add a comment |
Get cart items from customer local storage.
And render it using knock out.
You can get Cart item details of the guest user also,
in your js file
define([
'jquery',
'knockout',
'Magento_Customer/js/customer-data',
'uiComponent'
], function ($, ko, customerData, Component) {
return Component.extend({
initialize: function () {
self = this;
self.cart = customerData.get('cart');
let cartData = self.cart().items ? self.cart().items: ;
cartData.map(function(item) {
console.log(item.product_id);
console.log(item.product_name);
console.log(item.product_sku);
});
},
});
});
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
add a comment |
Get cart items from customer local storage.
And render it using knock out.
You can get Cart item details of the guest user also,
in your js file
define([
'jquery',
'knockout',
'Magento_Customer/js/customer-data',
'uiComponent'
], function ($, ko, customerData, Component) {
return Component.extend({
initialize: function () {
self = this;
self.cart = customerData.get('cart');
let cartData = self.cart().items ? self.cart().items: ;
cartData.map(function(item) {
console.log(item.product_id);
console.log(item.product_name);
console.log(item.product_sku);
});
},
});
});
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
add a comment |
Get cart items from customer local storage.
And render it using knock out.
You can get Cart item details of the guest user also,
in your js file
define([
'jquery',
'knockout',
'Magento_Customer/js/customer-data',
'uiComponent'
], function ($, ko, customerData, Component) {
return Component.extend({
initialize: function () {
self = this;
self.cart = customerData.get('cart');
let cartData = self.cart().items ? self.cart().items: ;
cartData.map(function(item) {
console.log(item.product_id);
console.log(item.product_name);
console.log(item.product_sku);
});
},
});
});
Get cart items from customer local storage.
And render it using knock out.
You can get Cart item details of the guest user also,
in your js file
define([
'jquery',
'knockout',
'Magento_Customer/js/customer-data',
'uiComponent'
], function ($, ko, customerData, Component) {
return Component.extend({
initialize: function () {
self = this;
self.cart = customerData.get('cart');
let cartData = self.cart().items ? self.cart().items: ;
cartData.map(function(item) {
console.log(item.product_id);
console.log(item.product_name);
console.log(item.product_sku);
});
},
});
});
edited yesterday
answered yesterday
Devendra GuptaDevendra Gupta
715
715
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
add a comment |
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Thanks for your comment. But I'm considering Guest users also.
– Elavarasan
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
Bro you can get Cart item details of guest user also
– Devendra Gupta
yesterday
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%2f257414%2fcart-details-not-getting-in-mini-cart%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
try with
$objectManager->create
instead of$objectManager->get
– Keyur Shah
2 days ago
@KeyurShah Thanks for your comment, I tried with that also. But it doesn't work.
– Elavarasan
yesterday