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 &...
user avatar
25 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', $...
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 &...
user avatar
  • 21.7k
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 ...
user avatar
22 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 ...
user avatar
  • 75.7k
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 ...
user avatar
  • 3,921
20 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 ...
user avatar
17 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 __('...
user avatar
  • 75.7k
15 votes
Accepted

Adding product to cart cause error 'The stock item for Product is not valid.'?

solved!, Instead of the product object pass product ID to addProduct() method worked. See the corrected code below. /** * Add air product to the cart. */ public function ...
user avatar
  • 9,837
15 votes

Why is CSRF protection needed for add-to-cart?

I believe it will be difficult to source a definitive answer to this question of why a CSRF token is "needed" in Magento's add to cart GET action. I'll make an attempt to interpret its purpose. I'm by ...
user avatar
  • 1,952
15 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 ...
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 | ...
user avatar
  • 8,774
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\...
user avatar
12 votes

Add to cart for out of stock products

Unfortunately, you are not missing a step here. Normally, people would think that the following two configuration options are enough to make it happen: Set System - Configuration - Catalog - ...
user avatar
  • 5,570
12 votes
Accepted

Getting quote (cart) items programatically shows duplicate SKUs for both the configurable and simple product

According to Magento, when a configurable product added at cart then two rows are inserted at the database. one configurable product cart another is a simple product One row has configurable id and ...
user avatar
  • 75.7k
12 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'); $...
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/'...
user avatar
  • 3,526
10 votes
Accepted

I want to use ADD TO CART via URL in Magento 1.8 but don't know which files to change

Starting Magento 1.8 it's not possible anymore to add a product to the cart via an external referrer. All the add to cart actions depend on the user form key that is different from session to session. ...
user avatar
  • 195k
10 votes

Getting quote (cart) items programatically shows duplicate SKUs for both the configurable and simple product

Use $cart->getAllVisibleItems() instead of $cart->getAllItems(). You get duplicates because when adding a configurable product to the cart, magento actually adds 2 products, the simple product ...
user avatar
  • 195k
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-...
user avatar
10 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=...
user avatar
9 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 ...
user avatar
  • 251
9 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 ...
user avatar
  • 3,554
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/...
user avatar
  • 75.7k
8 votes
Accepted

Replacement of an abstract class in custom module

You cannot rewrite abstract classes What you need to do is rewrite the class that extends, and inherits the abstract class methods. As an example: Mage_Catalog_Block_Product_View extends ...
user avatar
  • 9,796
8 votes

"Please specify the product's option(s)." after magento upgrade 1.6.2 to 1.9.1

Finally found the cause of the above issue: shopping cart rules with a category condition First I installed xdebug to try to find out what was going on. I found out that the the Subselect.php and ...
user avatar
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/...
user avatar
7 votes
Accepted

Add to cart for out of stock products

Solution After much, much testing here is how you can have the Add to cart button appear on products that are Out of stock. Set System->Configuration->Catalog->Inventory->Backorders=Allow Qty Below ...
user avatar
  • 5,169
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"...
user avatar
  • 959
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 ...
user avatar

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