Magento 2 get cart items in block class The Next CEO of Stack OverflowContent block not showingMagento 2 RC - Invalid block typeAdding a css class / div wrapper to a blockBlock Template not LoadingMagento 2 Mini Cart Plugin di.xml doesn't pass attribute informationMagento2: How to show subtotal in minicartConditionally Add Body Class Within Module Block?Magento 2 in minicart popup need qty incrementer and decrementer$block Class Some Method is won't appear in get_class_methods() call
How to set page number in right side in chapter title page?
"Eavesdropping" vs "Listen in on"
What happened in Rome, when the western empire "fell"?
Do scriptures give a method to recognize a truly self-realized person/jivanmukta?
Can this note be analyzed as a non-chord tone?
What difference does it make using sed with/without whitespaces?
TikZ: How to fill area with a special pattern?
Can I calculate next year's exemptions based on this year's refund/amount owed?
How did Beeri the Hittite come up with naming his daughter Yehudit?
Can I use the word “Senior” as part of a job title directly in German?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Won the lottery - how do I keep the money?
IC has pull-down resistors on SMBus lines?
Can Sneak Attack be used when hitting with an improvised weapon?
Where do students learn to solve polynomial equations these days?
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
Decide between Polyglossia and Babel for LuaLaTeX in 2019
Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?
Which one is the true statement?
I dug holes for my pergola too wide
Is it convenient to ask the journal's editor for two additional days to complete a review?
Is there such a thing as a proper verb, like a proper noun?
How to explain the utility of binomial logistic regression when the predictors are purely categorical
Can I board the first leg of the flight without having final country's visa?
Magento 2 get cart items in block class
The Next CEO of Stack OverflowContent block not showingMagento 2 RC - Invalid block typeAdding a css class / div wrapper to a blockBlock Template not LoadingMagento 2 Mini Cart Plugin di.xml doesn't pass attribute informationMagento2: How to show subtotal in minicartConditionally Add Body Class Within Module Block?Magento 2 in minicart popup need qty incrementer and decrementer$block Class Some Method is won't appear in get_class_methods() call
I have created block for sidebar.
I have added below code in my block for compare products. It's working fine
<div class="block widget block-compare">
<div class="block-title">
</div>
block class="MagentoFrameworkViewElementTemplate" name="catalog.compare.sidebar" template="Magento_Catalog::product/compare/sidebar.phtml" /
</div>
I got output like this: http://prntscr.com/n4jcsj
Now i want to show shopping cart items there above compare. Can anyone help me with this.
I also try with minicart but it is not working as per my requirement. It gives me only link of minicart. I need to show content of minicart. I used this code in block.
<div class="minicart">
<div>
block class="MagentoCheckoutBlockCartSidebar" name="mini_cart" template="Magento_Checkout::cart/minicart.phtml"
</div>
</div>
Which gives me output like this : https://prnt.sc/n3h35j
Please help me if anyone has some idea about this.
magento2 blocks
add a comment |
I have created block for sidebar.
I have added below code in my block for compare products. It's working fine
<div class="block widget block-compare">
<div class="block-title">
</div>
block class="MagentoFrameworkViewElementTemplate" name="catalog.compare.sidebar" template="Magento_Catalog::product/compare/sidebar.phtml" /
</div>
I got output like this: http://prntscr.com/n4jcsj
Now i want to show shopping cart items there above compare. Can anyone help me with this.
I also try with minicart but it is not working as per my requirement. It gives me only link of minicart. I need to show content of minicart. I used this code in block.
<div class="minicart">
<div>
block class="MagentoCheckoutBlockCartSidebar" name="mini_cart" template="Magento_Checkout::cart/minicart.phtml"
</div>
</div>
Which gives me output like this : https://prnt.sc/n3h35j
Please help me if anyone has some idea about this.
magento2 blocks
But i want to add it in block.
– Khooshbu Patel
2 days ago
means i don't understand
– Rakesh Donga
2 days ago
Can we add this code in static block ?
– Khooshbu Patel
2 days ago
Yes, exactly same
– Khooshbu Patel
2 days ago
I added this code in static block and got this output : prntscr.com/n4jw9r
– Khooshbu Patel
2 days ago
add a comment |
I have created block for sidebar.
I have added below code in my block for compare products. It's working fine
<div class="block widget block-compare">
<div class="block-title">
</div>
block class="MagentoFrameworkViewElementTemplate" name="catalog.compare.sidebar" template="Magento_Catalog::product/compare/sidebar.phtml" /
</div>
I got output like this: http://prntscr.com/n4jcsj
Now i want to show shopping cart items there above compare. Can anyone help me with this.
I also try with minicart but it is not working as per my requirement. It gives me only link of minicart. I need to show content of minicart. I used this code in block.
<div class="minicart">
<div>
block class="MagentoCheckoutBlockCartSidebar" name="mini_cart" template="Magento_Checkout::cart/minicart.phtml"
</div>
</div>
Which gives me output like this : https://prnt.sc/n3h35j
Please help me if anyone has some idea about this.
magento2 blocks
I have created block for sidebar.
I have added below code in my block for compare products. It's working fine
<div class="block widget block-compare">
<div class="block-title">
</div>
block class="MagentoFrameworkViewElementTemplate" name="catalog.compare.sidebar" template="Magento_Catalog::product/compare/sidebar.phtml" /
</div>
I got output like this: http://prntscr.com/n4jcsj
Now i want to show shopping cart items there above compare. Can anyone help me with this.
I also try with minicart but it is not working as per my requirement. It gives me only link of minicart. I need to show content of minicart. I used this code in block.
<div class="minicart">
<div>
block class="MagentoCheckoutBlockCartSidebar" name="mini_cart" template="Magento_Checkout::cart/minicart.phtml"
</div>
</div>
Which gives me output like this : https://prnt.sc/n3h35j
Please help me if anyone has some idea about this.
magento2 blocks
magento2 blocks
edited 2 days ago
Rakesh Donga
2,258316
2,258316
asked 2 days ago
Khooshbu PatelKhooshbu Patel
255
255
But i want to add it in block.
– Khooshbu Patel
2 days ago
means i don't understand
– Rakesh Donga
2 days ago
Can we add this code in static block ?
– Khooshbu Patel
2 days ago
Yes, exactly same
– Khooshbu Patel
2 days ago
I added this code in static block and got this output : prntscr.com/n4jw9r
– Khooshbu Patel
2 days ago
add a comment |
But i want to add it in block.
– Khooshbu Patel
2 days ago
means i don't understand
– Rakesh Donga
2 days ago
Can we add this code in static block ?
– Khooshbu Patel
2 days ago
Yes, exactly same
– Khooshbu Patel
2 days ago
I added this code in static block and got this output : prntscr.com/n4jw9r
– Khooshbu Patel
2 days ago
But i want to add it in block.
– Khooshbu Patel
2 days ago
But i want to add it in block.
– Khooshbu Patel
2 days ago
means i don't understand
– Rakesh Donga
2 days ago
means i don't understand
– Rakesh Donga
2 days ago
Can we add this code in static block ?
– Khooshbu Patel
2 days ago
Can we add this code in static block ?
– Khooshbu Patel
2 days ago
Yes, exactly same
– Khooshbu Patel
2 days ago
Yes, exactly same
– Khooshbu Patel
2 days ago
I added this code in static block and got this output : prntscr.com/n4jw9r
– Khooshbu Patel
2 days ago
I added this code in static block and got this output : prntscr.com/n4jw9r
– Khooshbu Patel
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
Create Block file
<?php
namespace VendorModuleBlock;
class ShoppingCart extends MagentoFrameworkViewElementTemplate
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_checkoutSession = $checkoutSession;;
parent::__construct($context, $data);
/**
* Get quote object associated with cart. By default it is current customer session quote
*
* @return MagentoQuoteModelQuote
*/
public function getQuoteData()
$this->_checkoutSession->getQuote();
if (!$this->hasData('quote'))
$this->setData('quote', $this->_checkoutSession->getQuote());
return $this->_getData('quote');
Call in template(.phtml) file,
<?php
// Get all visible items in cart
$quote = $block->getQuoteData();
foreach($quote->getAllVisibleItems() 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 'Product Type: '.$_item->getProductType().'<br/>';
echo 'Discount: '.$_item->getDiscountAmount();echo "<br/>";
echo "<br/>";
i think issue in implementing
– Rakesh Donga
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
yesterday
add a comment |
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%2f267928%2fmagento-2-get-cart-items-in-block-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create Block file
<?php
namespace VendorModuleBlock;
class ShoppingCart extends MagentoFrameworkViewElementTemplate
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_checkoutSession = $checkoutSession;;
parent::__construct($context, $data);
/**
* Get quote object associated with cart. By default it is current customer session quote
*
* @return MagentoQuoteModelQuote
*/
public function getQuoteData()
$this->_checkoutSession->getQuote();
if (!$this->hasData('quote'))
$this->setData('quote', $this->_checkoutSession->getQuote());
return $this->_getData('quote');
Call in template(.phtml) file,
<?php
// Get all visible items in cart
$quote = $block->getQuoteData();
foreach($quote->getAllVisibleItems() 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 'Product Type: '.$_item->getProductType().'<br/>';
echo 'Discount: '.$_item->getDiscountAmount();echo "<br/>";
echo "<br/>";
i think issue in implementing
– Rakesh Donga
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
yesterday
add a comment |
Create Block file
<?php
namespace VendorModuleBlock;
class ShoppingCart extends MagentoFrameworkViewElementTemplate
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_checkoutSession = $checkoutSession;;
parent::__construct($context, $data);
/**
* Get quote object associated with cart. By default it is current customer session quote
*
* @return MagentoQuoteModelQuote
*/
public function getQuoteData()
$this->_checkoutSession->getQuote();
if (!$this->hasData('quote'))
$this->setData('quote', $this->_checkoutSession->getQuote());
return $this->_getData('quote');
Call in template(.phtml) file,
<?php
// Get all visible items in cart
$quote = $block->getQuoteData();
foreach($quote->getAllVisibleItems() 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 'Product Type: '.$_item->getProductType().'<br/>';
echo 'Discount: '.$_item->getDiscountAmount();echo "<br/>";
echo "<br/>";
i think issue in implementing
– Rakesh Donga
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
yesterday
add a comment |
Create Block file
<?php
namespace VendorModuleBlock;
class ShoppingCart extends MagentoFrameworkViewElementTemplate
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_checkoutSession = $checkoutSession;;
parent::__construct($context, $data);
/**
* Get quote object associated with cart. By default it is current customer session quote
*
* @return MagentoQuoteModelQuote
*/
public function getQuoteData()
$this->_checkoutSession->getQuote();
if (!$this->hasData('quote'))
$this->setData('quote', $this->_checkoutSession->getQuote());
return $this->_getData('quote');
Call in template(.phtml) file,
<?php
// Get all visible items in cart
$quote = $block->getQuoteData();
foreach($quote->getAllVisibleItems() 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 'Product Type: '.$_item->getProductType().'<br/>';
echo 'Discount: '.$_item->getDiscountAmount();echo "<br/>";
echo "<br/>";
Create Block file
<?php
namespace VendorModuleBlock;
class ShoppingCart extends MagentoFrameworkViewElementTemplate
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCheckoutModelSession $checkoutSession,
array $data = []
)
$this->_checkoutSession = $checkoutSession;;
parent::__construct($context, $data);
/**
* Get quote object associated with cart. By default it is current customer session quote
*
* @return MagentoQuoteModelQuote
*/
public function getQuoteData()
$this->_checkoutSession->getQuote();
if (!$this->hasData('quote'))
$this->setData('quote', $this->_checkoutSession->getQuote());
return $this->_getData('quote');
Call in template(.phtml) file,
<?php
// Get all visible items in cart
$quote = $block->getQuoteData();
foreach($quote->getAllVisibleItems() 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 'Product Type: '.$_item->getProductType().'<br/>';
echo 'Discount: '.$_item->getDiscountAmount();echo "<br/>";
echo "<br/>";
edited 2 days ago
answered 2 days ago
Rakesh DongaRakesh Donga
2,258316
2,258316
i think issue in implementing
– Rakesh Donga
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
yesterday
add a comment |
i think issue in implementing
– Rakesh Donga
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
yesterday
i think issue in implementing
– Rakesh Donga
yesterday
i think issue in implementing
– Rakesh Donga
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
Hello.. your code works fine when i disable page cache. But when page cache is enable it doesn't show any item in cart.
– Khooshbu Patel
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
yesterday
You can create extension for that and create block file also phtml file create like above my code
– Rakesh Donga
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%2f267928%2fmagento-2-get-cart-items-in-block-class%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

But i want to add it in block.
– Khooshbu Patel
2 days ago
means i don't understand
– Rakesh Donga
2 days ago
Can we add this code in static block ?
– Khooshbu Patel
2 days ago
Yes, exactly same
– Khooshbu Patel
2 days ago
I added this code in static block and got this output : prntscr.com/n4jw9r
– Khooshbu Patel
2 days ago