"shopify.formatmoney is not a function" error

Highlighted
New Member
6 0 0

Hello,

I have been running into a weird problem.

I am using metafields to show related products to the current product. My code works perfectly fine on one product's page but throws the above mentioned error on another product page.

For reference here's my code for this recommendations snippet where I am getting the "Shopify.formatmoney is not a function" error -

<!-- Solution brought to you by Caroline Schnapp -->
<!-- See this: http://wiki.shopify.com/Related_Products -->
<!-- This snippet is named recommendations because there is already a snippet called related-products that sadly uses metafield
`recommendation` so this one uses one called `related`. -->
 
{% assign image_size = 'medium' %}

{% if product.metafields.related.productRecco %}

<ul class="recommendations"></ul>
{% endif %}

<script type="text/javascript" charset="utf-8">
//<![CDATA[
  var related = [];
  {% if product.metafields.related.productRecco %}
  related = jQuery.trim({{ product.metafields.related.productRecco | json }}).split(/[\s,;]+/);
  {% endif %}
  if (related.length && related[0] !== '') {
    var list1 = jQuery('.recommendations');
    for (var i=0; i<related.length; i++) {
      jQuery.getJSON('/products/' + related[i] + '.js', function(product) {
        list1.append('<li class="product"><div class="imgwrap"><a href="' + product.url +'"><img src="' + product.images[0].replace(/(\.jpg|\.png|\.jpeg|\.gif)/, '_{{ image_size }}$1') + '" /></a></div><div class="k"><a href="' + product.url + '">' + product.title + '</a>' + Shopify.formatMoney(product.price, '{{ shop.money_format }}') + '</div></li>');
      });
    }
  }
//]]>
</script>

Thanks in advance!

0 Likes
Highlighted
Shopify Partner
67 0 7

Hi Tejas, can you point us to the product page that shows the error too, pls.

 

0 Likes
Highlighted
New Member
6 0 0

Sure.

Here's where I get the error and the product is not displayed in Worn with - http://aishlife.in/products/mala-robe-black-white

But no error whatsoever on this product page - http://aishlife.in/products/mala-robe-multi

Thanks!

 

0 Likes
Highlighted
Shopify Partner
67 0 7

Hello Tejas,

I dont see a formatMoney is not a function error, but a 404 ( Not Found ) error on my comsole.

The page is looking for a sana-blouse.js

Apparently, there is no product with the handle sana-blouse in your inventory, Fix the typo and you are set.

Good Luck

AM

0 Likes
Highlighted
Shopify Partner
1 0 0

Don't know if this will work for you but somehow I came across this solution while solving the same problem. No idea why but upgrading my jQuery version fixed this and a couple other problems for me. I was on an ancient 1.11.0, tried to go full upgrade to 3.2.1 which broke some more things, and finally settled on 2.2.1. 

Again, no idea why this fixed this problem and a few other errors messages that have been plaguing my console for some time but it did. Presumably it has to do with other apps and plugins downloaded expecting recent versions of jQuery and rightly so. Please respond if this works for you too so others can see

 

0 Likes
Highlighted
Shopify Partner
12 1 5
    {{ 'api.jquery.js' | shopify_asset_url | script_tag }}

Use this piece of code right below where you have jQuery added or after theme.js / app.js / main.js

2 Likes
New Member
1 0 0

Thank you Atiqur Rahman, It is very useful

0 Likes