- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
i have a condition. if that condition success then only the product should added to the cart.I have a condition but i want to know where exactly i should place that condition. I need files to add that condition .
can any one help me ?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For add custom conditions before the add To cart in Magento 2, You need to find the line with $block->getAddToCartUrl from Catalog module templates.
getAddToCartUrl() function is responsible for fetch add action of cart.
Many files contain the line as above defined, which is responsible for add to cart in the store. So you need to override specific file and before above action, you need to set your custom conditions.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: I want to check with one condition before adding product to the cart magento 2 ?
By default all the products in Magento 2 before add, They perform action Add Controller in Checkout module.
You can check file, vendor/magento/module-checkout/Controller/Cart/Add.php
You need to Override controller file in your custom module or you can create plugin for execute() method of Add.php file for setting your custom conditions.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: I want to check with one condition before adding product to the cart magento 2 ?
But i want to put that condition in .phtml file. Can you guide me ?
how can i acheive it ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For add custom conditions before the add To cart in Magento 2, You need to find the line with $block->getAddToCartUrl from Catalog module templates.
getAddToCartUrl() function is responsible for fetch add action of cart.
Many files contain the line as above defined, which is responsible for add to cart in the store. So you need to override specific file and before above action, you need to set your custom conditions.
Magento 2 Blogs/Tutorial