Reputation: 459
When I'm creating a Shopify "Buy Button" of any type, the generated HTML code does not work. The Chrome Developer Tools Console tells me: buy-button-storefront.js:2999
: cannot read property '1' of null
.
In the Chrome debugger, I see that the function formatMoney(amount, format)
is called with a format
parameter which does not work with the placeholderRegex
:
Any help would be much appreciated.
Upvotes: 1
Views: 2403
Reputation: 893
When money_format
isn't set correctly, Shopify's formatMoney() regex fails.
Check your money format:
console.log(Shopify.api.getMoneyFormat())
For me, this was returning $
instead of ${{amount}}
- It looks like yours is returning €
instead of €{{amount}}
After checking my script, I was setting the format correctly to begin with - but my JS file had a .liquid extension - so Shopify was seeing {{amount}} as a variable, which rendered blank on the client side. You can avoid this behaviour by using the %raw%
tags in your liquid file.
{% raw %}
var money_format = '${{amount}}';
{% endraw %}
Upvotes: 4
Reputation: 136
I seen this problem a handful of times, its odd it just seems to pop up and I've never actually got to the bottom of it.
Sometimes resetting the money format does the trick
<script>Shopify.money_format = "{{ shop.money_format }}";</script>
I can't take credit for that,I found it on github a while back
Upvotes: 0
Reputation: 46
You have to use JavaScript SDk to avoid this problem . Generate a new snippet from Buy Button > JavaScript SDk > Generate code .
I think then it will be solve.
Upvotes: 0