Magento add to cart button direct to magento/index.php/checkout/cart/ page

Magento add to cart button direct to magento/index.php/checkout/cart/ page

October 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento add to cart button direct to magento/index.php/checkout/cart/ page

Troubleshooting Magento Cart Additions: Staying on Page

Hello! I’m glad you’ve reached out about this issue with your Magento e-commerce site. Let’s dive into troubleshooting the problem where clicking the “Add to Cart” button redirects you to the cart page instead of updating the cart on the current page.

Understanding the Issue

When you integrate themes like Shopper, conflicts can sometimes arise between JavaScript files and the core Magento functionality. This often leads to unexpected redirections. Let me walk you through a few steps to resolve this issue.

Checking Your Theme’s Add to Cart Functionality

First, navigate to your theme directory in Xampp:

xampp/xamppfiles/htdocs/magento/app/design/frontend/<theme_vendor>/<theme_name>

Open the template folder and check if the catalog_product_view_type_simple.html file exists. This is where the “Add to Cart” button is typically defined.

Inspecting JavaScript Files

Open your browser’s developer tools (right-click > Inspect or use F12) and navigate to the “Network” tab. Reload the page with the product you’re trying to add to cart, and look for any JavaScript errors that might be preventing the AJAX functionality.

Disabling Compilation

Sometimes, the compilation process in Magento can cause conflicts. To rule this out:

  1. Log in to your admin panel.
  2. Navigate to System > Tools > Compilation.
  3. Click “Disable” under “Status”.

After disabling compilation, clear the cache and test if the issue persists.

Reviewing Config Settings

Check the configuration settings for AJAX add-to-cart functionality:

  • Admin Panel > Stores > Configuration > Sales > Checkout
  • Make sure “Enable Onepage Checkout” is set to ‘Yes’
  • Also confirm that “Show Cart Summary on Product View Page” is enabled

If all these settings are correct, let’s look at a code example.

Manually Fixing the Add to Cart Behavior

Open app/design/frontend/<theme_vendor>/<theme_name>/template/catalog/product/view/type/simple.phtml and find this line:

<button id="product-addtocart-button" type="button">Add to cart</button>

Replace it with:

<script type="text/javascript">
    require(['jquery'], function($){
        $(document).ready(function(){
            $('#product-addtocart-button').click(function(e){
                e.preventDefault();
                var form = $('#product_addtocart_form');
                if (!form.data('validate')) {
                    form.ajaxSubmit({
                        error: function(xhr, textStatus) {
                            alert(textStatus);
                        }
                    });
                } else {
                    setLocation(form.attr('action'));
                }
            });
        });
    });
</script>

This will ensure that when the button is clicked, it triggers an AJAX request to add the product without redirecting to another page.

Conclusion

Remember, resolving conflicts in Magento often requires a systematic approach of checking configuration settings and inspecting code files. If you’re still facing issues after following these steps, consider reaching out to a Magento developer or support for further assistance.

For more in-depth troubleshooting guides like this one, feel free to explore our Magento Development resources at Laravel Company. We provide practical tutorials and tips to help you navigate the complexities of e-commerce development.

Checkout Catalog Cache Themes

Our network