Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax AddToCart - Help #4

Open
JDavidVR opened this issue Aug 26, 2024 · 0 comments
Open

Ajax AddToCart - Help #4

JDavidVR opened this issue Aug 26, 2024 · 0 comments

Comments

@JDavidVR
Copy link

Hi, first if all thanks for this module:

My question is, what would be the best approach to implement this Ajax AddToCart logic (se below link) into instant search implementation?

https://github.com/monsoonconsulting/magento2-hyva-ajax-add-to-cart/blob/main/view/frontend/templates/hyva/script/addtocart.phtml#L29

const forms = document.querySelectorAll(selectors);
    const delay = parseInt('<?= $escaper->escapeJs($delay) ?>', 10);

    forms.forEach(form => {
        form.addEventListener('submit', async (e) => {
            e.preventDefault();

If you check this file:

https://github.com/blackbird-agency/hyva-algolia-search/blob/main/src/view/frontend/web/js/instantsearch.js#L682

const cartForms = document.querySelectorAll('[data-role="tocart-form"]');
            cartForms.forEach((form, i) => {
                const ts = Date.now();
                form.addEventListener('submit', e => {
                    const url = `${algoliaConfig.request.url}${window.location.search}`;
                    e.target.elements[algoliaConfig.instant.addToCartParams.redirectUrlParam].value = AlgoliaBase64.mageEncode(url);
                })
            });

Both are pretty similar, they're iterating the forms in page.

So is it ok to modify directly this file: src/view/frontend/web/js/instantsearch.js or what would be the best approach thinking on easy module upgrades?

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant