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 ...
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(
...
...
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 ...
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->...
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();
$...
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 ...
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 = $...
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(...
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>
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' ...
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-...
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"
...
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-...
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
| ...
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\...
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() ...
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:...
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....
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 ...
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="...
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;
}...
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
<?...
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:...
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 ...
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();
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 ...
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:
....
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 ...
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,
...
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" ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cart × 2231magento2 × 782
magento-1.9 × 432
checkout × 361
addtocart × 199
product × 164
shopping-cart × 148
quote × 142
magento-2.1 × 107
event-observer × 94
mini-cart × 86
shopping-cart-price-rules × 82
shipping × 81
magento-1.7 × 80
price × 77
custom-options × 68
ajax × 65
configurable-product × 64
magento-1.8 × 61
php × 55
magento2.3 × 54
onepage-checkout × 53
session × 52
rest-api × 51
tax × 49