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

Prevent multiple add-to-cart initializations in case of ajax loaded product listing #15409

Conversation

vovayatsyuk
Copy link
Member

Description

catalogAddToCart widget initialize its functions for all suitable elements:

This commit fixes this by additional catalog-addtocart-initialized flag.

Manual testing scenarios

  1. Navigate to the category with products.

  2. Open developer console and execute the following script:

    jQuery('footer').append('<script type="text/x-magento-init">{"[data-role=tocart-form], .form.map.checkout": {"catalogAddToCart": {}}}</script>');
    jQuery('footer').trigger('contentUpdated');

    This scenario is a simplified case that may happen when some third-party widget loads ajax products listing on the page using standard listing template.

  3. Open "Network" tab and press "Add to cart" on some product.

  4. Two requests will be sent instead of one.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@VladimirZaets
Copy link
Contributor

Hi, @vovayatsyuk, I took your PR into processing, thank you for collaboration.

@magento-engcom-team
Copy link
Contributor

Hi @vovayatsyuk. Thank you for your contribution.
Changes from your Pull Request will be available with the upcoming 2.2.5 release.

Please, consider porting this solution across release lines.
You may use Porting tool to port commits automatically.

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

Successfully merging this pull request may close these issues.

3 participants