Skip to main content
41 votes

Pop up minicart when I add a product to the cart magento 2

This is my first answer on this site. I've been struggling trying to make this work for the past two days and I was finally able to make it work, so I though it would be nice to share it. First of ...
pinicio's user avatar
  • 766
32 votes

Magento 2 - How to get all items in cart?

The use of Magento\Checkout\Model\Cart is deprecated. You should use the session to get the quote and your cart items. use Magento\Checkout\Model\Session; public function __construct( ... ...
Frank's user avatar
  • 1,144
24 votes
Accepted

Magento 2.3.2 Call to undefined function Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\bccomp()

bccomp() function belongs to BCMath package; if it's undefined, then possible this library not installed or it's not enabled for your PHP version. Like for php7.2 need to install for ubuntu ...
Hassan Ali Shahzad's user avatar
20 votes

Magento 2 - How to get all items in cart?

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); // retrieve quote items collection $itemsCollection = $cart->...
Rahul Katoch's user avatar
  • 1,119
19 votes
Accepted

Get Shipping Price From Quote

This will do the trick. From your question, I assume that the customer has already selected their desired shipping method. <?php $quote = Mage::getModel("checkout/session")->getQuote(); $...
Shawn Abramson's user avatar
19 votes

Magento 2 How to remove tax from checkout?

If you want to leave taxes enabled and with a value but just remove them from display remove the item with the name tax at the appropriate place. For example to remove tax from the checkout cart ...
steros's user avatar
  • 1,622
19 votes
Accepted

Magento 2 : Updating quote item

I am not sure about my below solution: May be you need to load Quote item object by item id As you want set price then using setPrice() you cannot set your desire price for that cart item $item = $...
Amit Bera's user avatar
  • 77.6k
19 votes
Accepted

How to update minicart view using AJAX?

You can try the below code. require([ 'Magento_Customer/js/customer-data' ], function (customerData) { var sections = ['cart']; customerData.invalidate(...
Suresh Chikani's user avatar
18 votes
Accepted

How do I load JavaScript function inside KnockoutJS html?

If you need to work with DOM elements, rendered by knockout from this template, you can use afterRender binding. <div data-bind="afterRender: function() {alert('yes');}"></div>
Max's user avatar
  • 4,054
18 votes
Accepted

Shopping cart is not clearing on the cart page

I've also encountered this issue and I've found out that in vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml ~line 27, Magento Team seems missed to put a dot for the 'action' ...
phagento's user avatar
  • 539
16 votes
Accepted

Customize sticky behaviour of Cart Summary: Magento 2

I finally found the answer to this. The sticky behavior of the cart summary is due to the code in the file magento_root/vendor/magento/theme-frontend-blank/Magento_Theme/web/js/theme.js. $('.cart-...
V.S's user avatar
  • 914
15 votes
Accepted

Remove apply discount code from Cart

app/design/frontend/{Vendor}/{theme}/Magento_Checkout/layout/checkout_cart_index.xml <?xml version="1.0"?> <page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
PЯINCƎ's user avatar
  • 11.7k
15 votes
Accepted

Adding a modal after adding to cart

You can show ajax popup by extending catalog-add-to-cart.js file of Magento-Catalog module. Steps to do : 1 - Copy catalog-add-to-cart.js from '\module-catalog\view\frontend\web\js/catalog-add-to-...
Naveed Asim's user avatar
  • 3,657
14 votes

How to add "Buy Now" button in Magento 2.1 Product detail page along with add to cart?

Here is a module that adds a 'Buy Now' button that takes customer directly to checkout with the choosen product in cart. Module Directory: | registration.php | +---Controller | \---Cart | ...
Aaron Allen's user avatar
  • 9,009
14 votes
Accepted

remove items from cart in controller - magento2

Your custom controller should be: namespace Gworks\Cart\Controller\Items; use Magento\Framework\App\Action\Context; use Magento\Checkout\Model\Cart as CustomerCart; class Remove extends \Magento\...
Sohel Rana's user avatar
14 votes

Magento 2 : Get Quote Item Selected Options

You can usually call $item->getProductOptions() to get all options and then sort through to get selected options as mentioned by @Rakesh Jesadiya. But, Sometimes $item->getProductOptions() ...
Vivek Kumar's user avatar
  • 5,715
14 votes

Magento 2 how to get custom attribute value in cart page and mini cart

Create File catalog_attributes.xml inside Vendor/Module/etc or any existing module. <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Ansar Husain's user avatar
  • 3,469
13 votes
Accepted

Cart Summary expanded

To make cart summary opened initially on page load do the following : Go to your core files and copy cart-items.html vendor/magento/module-checkout/view/frontend/web/template/summary/cart-items....
Manoj Deswal's user avatar
  • 5,805
12 votes
Accepted

magento 2 order confirmation email sending before payment gatway redirection

I was facing same issue but I found alternative solution like I turned off Magento default Order Confirmation email and Send Order Confirmation Email When Order is being placed Successfully. Here are ...
Ronak Chauhan's user avatar
11 votes

Magento 2 - Set custom attribute value on cart page

No need to create any Observe, you can get it by simple below code. Just need to create {MODULE_NAME}/etc/catalog_attributes.xml with below content: <?xml version="1.0"?> <config xmlns:xsi="...
Suresh Chikani's user avatar
11 votes
Accepted

How to check if cart is empty in observer Magento 2

You can also use the cart helper protected $cartHelper; public function __construct( \Magento\Checkout\Helper\Cart $cartHelper ) { $this->cartHelper = $cartHelper; }...
Nikolas's user avatar
  • 2,291
11 votes
Accepted

Magento 2 : When adding 10 (or any number) products to cart with the same sku is there a way to not increment?

If every time want to add a separate product in cart, then you can pluginize representProduct method located in Magento\Quote\Model\Quote\Item Your [Vendor]/[Module]/etc/di.xml looks like below <?...
Murtuza Zabuawala's user avatar
10 votes
Accepted

Magento 2 : How to Update cart after cart update event (checkout_cart_update_items_after)

I ended up using plugin di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
Vishwas Bhatnagar's user avatar
10 votes

Magento 2 - How to show tax and shipping costs in mini-cart pop up

To show additional stuff or costs in the minicart (like taxes or shipping costs), you need to understand where the data in the minicart comes from. The Customer Data Section Pool If you add a ...
Giel Berkers's user avatar
  • 12.3k
10 votes
Accepted

Magento2: How to get order total price

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); $grandTotal = $cart->getQuote()->getGrandTotal();
Sheshgiri Anvekar's user avatar
10 votes

How quotes and cart work in magento

A quote is cart object, this quote is created when the customer adds the first product to the cart and its not created when the customer is created. A customer can have many quotes. One for each ...
PЯINCƎ's user avatar
  • 11.7k
9 votes

Magento 2 remove "Estimate shipping costs and tax" from cart

I also needed to get rid of the "Estimate Shipping costs and Tax" because of a conflict with a payment module. If your only objective is to not show the block, why not use CSS? This worked for me: ....
storepeinture's user avatar
9 votes

Magento 2 Get Cart Quote Total in minicart.phtml

We had a similar question from a client. where he wanted to show "[quantity] item [subtotal]" in a styled cart block instead of the default cart icon in the minicart. We found this question here but ...
Pascal Wientjes's user avatar
9 votes
Accepted

How to override module-checkout/.../cart/item/default.phtml?

you can do it using override in your module with below way, You must have to change referencename of your xml, First create app/code/Custom/Addprofile/view/frontend/layout/checkout_cart_index.xml, ...
Rakesh Jesadiya's user avatar
9 votes

How to update cart qty using ajax Magento 2

Reload totals cart after ajax change quantity 1. Step In your custom them create ( Magento_Theme/layout/checkout_cart_index.xml ) <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
Surendra Kumar Ahir's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible