amzn / amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
https://amzn.github.io/amazon-payments-magento-2-plugin/
Apache License 2.0
109 stars 77 forks source link

Amazon Buttons not loading - Uncaught AmazonPay: Can not find element #ui-id-4 for amazon.Pay.renderButton. #1141

Closed HenKun closed 1 year ago

HenKun commented 2 years ago

This issue is related to @1096 but only solved for payment button, not for login button.

What I expected

Amazon Buttons (Login and Pay) render successfully

What happened instead

Js error Uncaught AmazonPay: Can not find element #ui-id-4 for amazon.Pay.renderButton.

Steps to reproduce the issue

In our theme the Amazon login button is rendered via knockout JS.

Solution

Identically to the solution for issue @1096 it helps to wrap

amazon.Pay.renderButton('#' + $buttonRoot.empty().uniqueId().attr('id'), buttonConfig);

in view/frontend/web/js/amazon-login-button.js on line 75 in a try-catch clause.

Your setup

HenKun commented 2 years ago

I made a patch for version 5.14.1 in case anyone else encounters the issue amzn-button-login-render-gh-issue-1141.txt

sgabhart22 commented 2 years ago

Hello @HenKun ,

Thanks for sharing that find, and posting a fix as well! Theoretically this issue could happen on any page where multiple Amazon Pay (or Sign In) buttons are rendered. By default, the module never renders more than one Amazon Sign In button anywhere, but I could definitely see an issue if a theme adds another one. Seems reasonable to include this for safety, also keeps consistency with the way the other button(s) are rendered.

If you'd like, you can fork this repo and create a PR with the fix from the patch you attached. We wouldn't directly merge the PR if we include the fix, but we would cherry pick your commit into a release so you'd receive credit for the contribution.

Thanks again! Spencer

HenKun commented 2 years ago

@sgabhart22 Great, I openend the PR

sgabhart22 commented 1 year ago

Hello again @HenKun ,

Your fix has (finally) been included in version 5.15.0 of the module which is now available on the Magento Marketplace. We will be closing this issue and the related PR shortly. Thank you again for your contribution!

Spencer