I created my website using a custom theme, how to implement ajax to my add-to-cart and wishlist button?

I tried the following step, it not working,

vendor\magento\module-catalog\view\frontend\templates\product\view\addtocart.phtml (For testing purpose added in core files)

<script type="text/x-magento-init">
        "#product_addtocart_form": {
            "Magento_Catalog/js/validate-product": {},
            "catalogAddToCart": {
                "bindSubmit": true
  • Any error in console? Mar 15, 2021 at 4:27
  • My console snipboard.io/MBWrqc.jpg, i can't find a relevant error, some of the error i am facing before itself.
    – zus
    Mar 15, 2021 at 5:00

1 Answer 1


@zus I would suggest to review the below post where you can get your question answer easily. Here you will find an extension option as well as a customization option. But I would suggest to go with the extension option.

Magento 2 : Add to compare and add to wishlist with ajax


Please let me know if this will not help.

  • When i intall fist time why i am getting this error : PHP Fatal error: Cannot declare class Tigren\Core\API\License\LicenseAPI, because the name is already in use in C:\xampp\htdocs\m3\app\code\Tigren\Ajaxcompare\view\frontend\web\css\source\LicenseAPI\LicenseApi.php on line 14
    – zus
    Mar 15, 2021 at 6:26
  • It means that the extension is already installed. Can you please check in the backend and see, if it is already installed, then you just need to configure it.
    – Nits
    Mar 15, 2021 at 7:05
  • This is my first install.
    – zus
    Mar 15, 2021 at 12:47
  • Then you need to debug and fix the issue because in the free module it may have an issue. In this case what you can do, go to that file lone number and find that class name in whole module, if you find the same class name in another file then change class name and see it is working or not. Please let me know if you need any other help.
    – Nits
    Mar 16, 2021 at 4:33
  • 1
    Yes correct Please remove from all the registration.php file
    – Nits
    Mar 16, 2021 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.