32 votes
Accepted

Ajax add to cart button in product detail page magento 2

You have to just override addtocart.phtml file app/design/frontend/Packagename/themename/Magento_Catalog/templates/product/view/addtocart.phtml Replace "bindSubmit": false to "bindSubmit": true &...
Rakesh Jesadiya's user avatar
26 votes
Accepted

Magento2 - How to stop a product from getting added to cart programmatically?

you could try to set the product param to false and then set the return_url param: $observer->getRequest()->setParam('product', false); $observer->getRequest()->setParam('return_url', $...
David Verholen's user avatar
25 votes
Accepted

How to enable AJAX for the the 'Add to Cart' button of product widgets in Magento 2?

You have to override addtocart.phtml file app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/view/addtocart.phtml Now Just Replace "bindSubmit": false to "bindSubmit": true &...
Prince Patel's user avatar
  • 22.5k
24 votes
Accepted

Magento 2: Where is cart data saved?

Magento2, save cart details at Quote tables. For Cart general details use quote table . Carts item details at quote_item. Cart items option details at quote_item_option Additional: Checkout ...
Amit Bera's user avatar
  • 77k
23 votes
Accepted

How to "add to cart" a product with custom input field and save it to Database?

To accomplish this you could use Magento built-in "additional_options" functionality so that you don't have to edit email template, admin order view, customer order view (etc) to display ...
MagePal Extensions's user avatar
21 votes

What is step by step process for add products to magento guest cart using Rest apis?

Please follow the below steps as shown in the screenshots so that it will help you Note: 1) Mask Key we can trace out from the table called 'quote_id_mask' 2) quote_id (or) cart id as well you ...
Nagaraju Kasa's user avatar
20 votes
Accepted

Magento2 redirecting to Shopping cart

Like Magento1.x, there is an option in Magento2 admin panel to redirect to shopping cart page after adding product to cart. Change the option as, Stores->Configuration->Sales->Checkout->Shopping ...
saravanavelu's user avatar
  • 3,941
19 votes
Accepted

How to add Qty in add to cart form on Product Listings Page in Magento 2

On this form just add below code <input type="number" name="qty" id="qty" maxlength="12" value="<?php /* @escapeNotVerified */ echo '1' ?>" title="<?php /* @escapeNotVerified */ echo __('...
Amit Bera's user avatar
  • 77k
17 votes
Accepted

Magento 2 Related products add to cart button issue

By default Magento, there is no setting option in Admin for Add to Cart button on the related products block. If we want to custom the related, upsell, crosssel and new product template, we should ...
Khoa TruongDinh's user avatar
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
  • 8,939
14 votes
Accepted

Magento 2 programatically add product to cart?

protected $formKey; protected $cart; protected $product; public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\Data\Form\FormKey $formKey, \Magento\...
Nagaraju Kasa's user avatar
13 votes
Accepted

Magento 2: How to get add to cart url in custom templete file and add product to cart

You can try this, it work for me. <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct'); $...
Nitish Chauhan's user avatar
11 votes
Accepted

Cannot Add Product to cart

If you ran in local and your path is :localhost please replace "localhost" to "127.0.0.1". Following: So you can change root URL by SQL query: UPDATE core_config_data SET value = 'http://127.0.0.1/'...
MrTo-Kane's user avatar
  • 3,636
11 votes
Accepted

Magento 2 Ajax Add to Cart

In product listing page, Magento has a jQuery widget to handle the Ajax Add To Cart. We should take a look: vendor/magento/module-catalog/view/frontend/templates/product/list.phtml <script type=...
Khoa TruongDinh's user avatar
10 votes

Magento 2 Add to cart frontend event listener

When something is added to the cart, the local storage information is updated and you can subscribe to a knockout observable in the cart section of the customer data to be notified when it's content ...
Quinten's user avatar
  • 321
10 votes
Accepted

Magento2 - How to add a product into cart programatically when checkout_cart_product_add_after is fired

For all those who might waste their day in future, please note below answer which will be helpful to you. The above code to add product into cart works fine. However the problem is with the logic. I ...
Dexter's user avatar
  • 3,593
10 votes
Accepted

Changing "Add to cart" button text in Magento 2.1.0 ( Overriding js file )

You have to override js file from path vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js To app/design/frontend/YourTheme/Packadge/Magento_Catalog/web/js/catalog-add-to-...
Suresh Chikani's user avatar
9 votes

Magento 1.9 How to add buy now button in product page?

First, change Add to Cart Button to Buy Now. Then add a hidden input field to the #product_addtocart_form form. Name should be return_url and its value should be <?php echo Mage::getUrl('checkout/...
Amit Bera's user avatar
  • 77k
8 votes
Accepted

Related Products template customize

By default, Magento uses the same template for product related, upsell, crosssel and new products content widget. This template comes from vendor/magento/module-catalog/view/frontend/templates/product/...
Khoa TruongDinh's user avatar
8 votes

Magento2 how to add configurable product to cart programmatically

Process of adding configurable product to cart //Get cart object $cart = $this->_objectManager->get('Magento\Checkout\Model\Cart'); // Load Configurable Product $productId = 10;//configurable ...
satya prakash patel's user avatar
7 votes

Making non-customisable bundles in Magento 2

When I saw this page come up in Google I was cautiously optimistic. Several hours of bashing my keyboard into the wall later, here is what worked for me: Magento_Bundle/layout/...
Dominic Ferrantelli's user avatar
7 votes

What is step by step process for add products to magento guest cart using Rest apis?

The API is very tricky here. You need to create a cart first: [POST] /V1/carts/ This will return an ID. Now add the item to your cart: [POST] /V1/guest-carts/{cartId}/items Body: { "cart_item"...
awavi's user avatar
  • 989
7 votes

What is step by step process for add products to magento guest cart using Rest apis?

For guest you need to follow these steps: Step-1: Create empty guest-cart POST http://yourhost.com/rest/V1/guest-carts The response of above request will give you "cartKey" [Note: remove double ...
Kamal Singh's user avatar
7 votes
Accepted

Magento2 Change bundle item price in cart

So finally I was able to achieve this, first we need a events.xml For my requirement I needed this event observer for both frontend and adminhtml so the events.xml was create at app/code/Foo/...
Atish Goswami's user avatar
7 votes

How to enable AJAX for the the 'Add to Cart' button of product widgets in Magento 2?

You can extend the Catalog Products List to use the ajax cart by creating a module with the following files: /Your/Module/Block/Product/ListBlock.php with content: <?php namespace Your\Module\...
Aaron Allen's user avatar
  • 8,939
7 votes

Changing "Add to cart" button text in Magento 2.1.0 ( Overriding js file )

you need to override, catalog-add-to-cart.js from path, vendor/magento/module-catalog/view/frontend/web/js Text is changing from here after ajax call. you can change text here.
Rushvi's user avatar
  • 2,825
7 votes

Changing "Add to cart" button text in Magento 2.1.0 ( Overriding js file )

The text changed by Javascript after Ajax call. We can take a look: vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js For the best practice, should use mixins for "overriding"...
Khoa TruongDinh's user avatar
7 votes
Accepted

Remove success message after show

[Update] After all, I found a solution for this problem. It's made me sweat too much. Message was inited at messages.phtml on Magento_Theme package(module-theme\view\frontend\templates\messages....
Henry Bui's user avatar
  • 471
7 votes
Accepted

Magento2 - Ajax Add to Cart - Out of stock situation - Stop redirect and show message dynamically

In order to achieve this, you need to follow these steps: 1) Override Magento2 default theme js file by copying it from this path: vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-...
Toms Bugna's user avatar
7 votes

Error when adding to cart 'No such entity with id = 0'

Please check customer_group table for "NOT LOGGED IN" group. If its customer_group_id is not zero, truncate table catalog_product_index_price and catalog_product_index_tier_price. Then run ...
sheetal's user avatar
  • 79

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