Cart details not getting in mini cart












0















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;
}









share|improve this question

























  • 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
















0















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;
}









share|improve this question

























  • 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














0












0








0


1






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;
}









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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










3 Answers
3






active

oldest

votes


















1














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.






share|improve this answer
























  • Thanks for your comment, but I already tried with Session also. Still it doesn't work

    – Elavarasan
    yesterday



















1














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.






share|improve this answer










New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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



















0














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);
});

},

});
});





share|improve this answer


























  • 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











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
});


}
});














draft saved

draft discarded


















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









1














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.






share|improve this answer
























  • Thanks for your comment, but I already tried with Session also. Still it doesn't work

    – Elavarasan
    yesterday
















1














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.






share|improve this answer
























  • Thanks for your comment, but I already tried with Session also. Still it doesn't work

    – Elavarasan
    yesterday














1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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













1














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.






share|improve this answer










New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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
















1














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.






share|improve this answer










New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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














1












1








1







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.






share|improve this answer










New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










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.







share|improve this answer










New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited yesterday









Piyush

4,76872053




4,76872053






New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered yesterday









ThamoThamo

112




112




New contributor




Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Thamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • 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











  • 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











0














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);
});

},

});
});





share|improve this answer


























  • 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
















0














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);
});

},

});
});





share|improve this answer


























  • 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














0












0








0







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);
});

},

});
});





share|improve this answer















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);
});

},

});
});






share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

An IMO inspired problem

Management

Has there ever been an instance of an active nuclear power plant within or near a war zone?