Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [addtocart]

Questions related to the functionality of adding product to shopping cart in Magento.

18
votes
0answers
7k views

Magento 2: Uncaught TypeError: Cannot read property '*' of undefined in (section-config.js:33)

It's duplicate question but I am facing the same issue while adding the product & removing items from the cart page. I have spent almost a day to resolve but no luck hope someone could help me ...
15
votes
2answers
3k views

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

Magento has since recent versions a form_key as part of the add to cart action, to protect against I think CSRF attacks. So now I wonder, is it really needed for this place, and why or better said, ...
15
votes
4answers
4k views

Adding multiple items with different attributes to cart programmatically

I'm making a bulk add to cart system. Please note : i want it to works for simple products with with custom options -> Where custom option are like color(red , green , blue) or Size(Xl, M , S) ...
13
votes
2answers
5k views

Copying dynamic custom options to quote item, order item

I have an observer that is adding dynamic custom options to the product detail page, which is called on the catalog_controller_product_view event. This allows the customer to select from a dropdown of ...
12
votes
7answers
8k views

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

I have changed "Add to cart" text to "I want this" by overriding "vendor\magento\module-catalog\view\frontend\templates\product\list.phtml". But, when I click on "I want this" (i.e. "Add to cart" ) ...
10
votes
4answers
16k views

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

In Magento 2 the normal Add to Cart button has a very nice AJAX-based logic to add products to the cart. However, when we use a Catalog Products List widget for example in CMS pages the button in this ...
10
votes
3answers
33k views

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

I'm getting the shopping cart using: $cart = Mage::getSingleton('checkout/session')->getQuote(); And then iterating through it using: foreach ($cart->getAllItems() as $item) { } But it seems ...
9
votes
2answers
11k views

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

What I want to do is if my custom attribute is set in quote then i do not want any product to be added in cart. My custom attribute is being set correctly. To stop product from getting added to cart,...
9
votes
2answers
7k views

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

I had created a custom module in which I am overriding the add to cart form on the product page, and I successfully did it with catalog_product_view.xml file. Now I can see a custom input field on the ...
8
votes
1answer
7k views

Magento2 redirecting to Shopping cart

Is there a way in Magento2 to have the user get redirected to shopping cart page after clicking "add to cart" - instead of the mini cart option at top of page?
8
votes
1answer
12k views

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

Consider there are two product ie: Product A and Product B. Product B is a virual product which i need to add to cart when Product A is added to it. To do so, I am trying to add Product B to cart by ...
8
votes
0answers
261 views

Magento 2: Observer add product to cart?

I've read some other post about adding products to cart, but nothing seems to fit. I've an observer for checkout_cart_update_items_before that adds another product in same qty if specific product is ...
7
votes
2answers
5k views

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

I'm adding a nominal product programically to the shopping cart. But it throws an exception as 'The stock item for Product is not valid.'. How can I resolve this? NOTE : $product is getting passed to ...
7
votes
1answer
8k views

Magento 2: Where is saved about the cart data?

Magento version: 2.0.0 When user add products into cart, where are they saved? $_SESSION or Database? If it is in database, which table?
7
votes
2answers
525 views

Magento 1.9: Save custom image after click on Add to cart

We have custom button in product view page , once user "upload image or Add text" & click on "save design", its saving custom image in server. save design : app/design/frontend/rwd/Theme1/...
7
votes
2answers
1k views

Magento 2 - Generate customization image in product page and add it to product options in cart

I need to let users create a customization image in product page and than attach that image to product when users add product in cart. Create a custom product option type seems to be very tricky. I ...
7
votes
0answers
206 views

Magento2 Add to cart button in row with grouped Products

In Magento2 I want to add "Add to cart" button with qty for every single product of Grouped Product. Is it possible? How? I see that the form is only one. I need also to remove the standard "Add to ...
7
votes
0answers
538 views

Magento 2: How to make custom fee taxable

I want to add a tax on custom fee. tax calculation is perfect and gets tax amount but it's not set in TAX files in quote_address in the database. public function collect( \Magento\Quote\Model\...
7
votes
1answer
2k views

Magento 2 Add to cart frontend event listener

I am trying to find good solution to execute custom javascript when product is successfully added to cart. Also this custom javascript need information about product that was added to cart (sku, qty, ...
6
votes
1answer
7k views

Ajax add to cart button in product detail page magento 2

I have check online demo of Magento 2 http://magento2-demo.nexcess.net/fusion-backpack.htmlwhen we click on add to cart it add product via AJAX but i have Set up demo on localhost it don't to add ...
6
votes
2answers
5k views

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

How can you add a Qty filed to the the add to cart form on the category listings page. With the Luma theme the user only has the option to add one product to cart at a time from the product listings ...
6
votes
1answer
4k views

Remove success message after show

I custom add to cart module on Magento 2 and keep message like Magento core. if (!$this->_checkoutSession->getNoCartRedirect(true)) { if (!$this->cart->getQuote()->getHasError()) { ...
6
votes
1answer
1k views

Get add to cart URL and image without loading product object

Kind of a spinoff of this question. I'm trying to extend Mage_Catalog_Block_Product_Widget_Link to make a widget template that displays the product image and an add to cart button along with the ...
6
votes
1answer
408 views

Different quantity for different size add to cart product

i've created configurable product which has different sizes and different colors, In my product details page currently there's only one quantity input field and i need to select the size before add to ...
6
votes
4answers
855 views

How to disabled ADD TO CART button when user had not checked the zipcode

I am building an e-commerce website named "bookslab.in". My old exceptions are working fine for my "Add to cart" button. I want to add one new exception to my "Add to cart" button. I found this ...
6
votes
2answers
973 views

Product created programmatically unable to add to cart in magento 1.9.2?? It gives error “The product could not be found.”

public function createcustomerproduct($data) { Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $product = Mage::getModel('catalog/product'); try { $...
5
votes
2answers
4k views

How to add “Buy Now” button in Magento 2.1? [closed]

I need help to add "Buy Now" button on the product detail page. Thanks.
5
votes
4answers
8k views

Cannot Add Product to cart

Whenever I tried to add product to cart from list page or product page in fresh setup Magento Ce 2.1 release it redirects to checkout page and no product gets added. I tried disabling cache also.
5
votes
2answers
15k views

Check Some Condition Before Product added to cart

I want to add product to cart. So when i click on the add to cart button i will be checking some condition like some variable is set or not. If it is set, product will be added to cart. If not set, ...
5
votes
2answers
906 views

How to exclude products being added to cart based on products attributes?

How can i set a condition, if pre-ordered products are purchased, no other products can be added to cart? How can I set a condition like, if some of the "non-pre-order" products is in the cart, ...
5
votes
2answers
2k views

Add to cart Ajax response 302 in magento 2?

I am facing some problem regarding product add to cart. Whenever i am trying to add any configurable of simple product to my cart. It is not getting added to cart. Also When i checked in console, I ...
5
votes
2answers
592 views

Magento 2 Add to cart one product with different size at once but seems as one product

I have created one module in which we can directly add products to cart using SKUs with different configuration options but when i added it shows one product in cart with last option i selected and 2 ...
5
votes
5answers
3k views

I am trying to add link to the success message in Magento 2

I am trying to add a product details link in the success message after a user clicks the add to cart button. So I create a variable in my controller but and want to send cart link. Here is file ...
5
votes
1answer
551 views

I want to add discount to existing quote using controller file Magento 2

I have my custom code , which generates the new customer and add products to that customer's cart.This code is working fine for me.I want to add some discount to that customer programmatically. So how ...
5
votes
2answers
250 views

How to set custom tax price during add to cart in Magento 2

I am adding product to cart using ajax call. Here is my controller code. use Magento\Framework\Controller\ResultFactory; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\...
5
votes
1answer
1k views

Adding products to cart programmatically with custom price in controller: Magento 2

I am having a module that is creating quotes using the Magento quote module. It is using the \Magento\Quote\Model\QuoteFactory for creating the quotes. Now I have added a button "Proceed to ...
5
votes
2answers
276 views

How to override class which extends Abstract Class

I want to override a class Magento\Catalog\Model\Product\Type\Simple di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
5
votes
4answers
3k views

When Adding a product to cart programatically ,the price of the product becomes zero ($0.00) [duplicate]

When Adding a product to cart programatically ,the price of the product becomes zero ($0.00) on the fist time , but on adding the same item to the cart, it shows the price . The product adding is ...
5
votes
1answer
1k views

Magento 1.9 :- Add to Cart Helper - not working

I've been trying to fix a problem on an inherited Magento 1.9.1 site - the problem is coming from a custom category page I think. The template is using the Add to Cart Helper - in what appears to be ...
4
votes
4answers
20k views

Add to cart for out of stock products

I'm trying to get the Add to cart button to appear on products that are Out of stock. I've already set the System->Configuration->Catalog->Inventory->Backorders=Allow Qty Below 0 My store previously ...
4
votes
3answers
4k views

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

I am trying like this, Step 1: Post(empty) baseurl/rest/V1/guest-carts get: guest customerid =02ccea0d67a4be667fa6ebf7905tia21 Step 2: I want add items to cart,so am using this api, POST /V1/guest-...
4
votes
2answers
8k views

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

I just upgraded a site from 1.6.2 to 1.9.1 I have a big issue with configurable products. Impossible to add them to the cart. I always get "Please specify the product's option(s)." There is no error ...
4
votes
3answers
3k views

Limiting “Add to cart” to just 1 click / item

I've noticed that some visitors will click the "Add to cart" button multiple times. This results in the product being added multiple times. I thought it was my theme, but I've reproduced this on the ...
4
votes
4answers
9k views

Add product to cart programmatically invalid request for adding product to quote

I'm trying to create a controller to add to cart a product programmatically in magento 1.9, like this: <?php class Namespace_Module_IndexController extends Mage_Core_Controller_Front_Action{ ...
4
votes
2answers
1k views

Remove “Add to Cart” via Layout Update XML Magento 2.1

I'm trying to figure out how to remove the add to cart from specific items only in Magento 2.1 via "Layout Update XML on the product backend. In magento 1.x it was simple <reference name="content"...
4
votes
4answers
2k views

Magento 2: Add to Cart JS Override works on product page but not on category page

I override magento\vendor\magento\module-catalog\view\frontend\web\js\catalog-add-to-cart.js as I need to change the text from "Add to Cart" to "Buy Now" magento\app\code\Custom\Module\view\frontend\...
4
votes
4answers
6k views

Magento 2 Programatically add product to cart with additional options

I want to add product to cart with some additional data. My code adds the product to cart,but the additional info is not saved properly. I want to display the additional content in cart like custom ...
4
votes
2answers
2k views

Shopping Cart Rule Causing Internal Sever Error 500

I am trying to configure a shopping cart price rule where if you add 2 or more bundled products from one category you get the discount off the subtotal of the cart. This is the only cart rule on the ...
4
votes
1answer
1k views

Promotion: Automatically add certain product to cart for free

Is it (and if so, how is it) possible to create the following promotion in Magento? If a certain product item is added to the cart, another certain product shall be added to cart automatically and ...
4
votes
1answer
1k views

add to cart button in CMS page

In Magento2.1, I'm able to load a product in CMS page using: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Catalog\Model\Product')-&...