Re: Issue with accessing a JSON type of Metafield in my liquid file | Theme app extension | Shopify

Issue with accessing a JSON type of Metafield in my liquid file | Theme app extension | Shopify app

Bontalexel31
Shopify Partner
28 2 4

Dear community,

My current app needs a theme extension where I would make my app's database (not the database of Shopify) available to my liquid file through a Metafield.

I choose the JSON type meta field, and after writing the schema and validating it in my product edit page. I cannot access the meta field in my liquid file, when logging the result of the variable assigned I get undefined, I tried different methods but still couldn't get it to work.

NB: I've got another metafield of type integer which is working perfectly.

I will leave some screenshots below of my configuration, JSON schema and JSON data in my product but also my liquid code.

Thank you in advance for your time and consideration.

Screenshot from 2024-05-05 19-55-07.pngScreenshot from 2024-05-05 19-54-27.pngScreenshot from 2024-05-05 19-53-55.pngScreenshot from 2024-05-05 19-53-48.pngScreenshot from 2024-05-05 19-53-09.png

 

Show Variant Options as Text or Colored Swatches with Add to cart Button on Home and Collection Page
Install it now for free!
Swatch Display: https://apps.shopify.com/swatch-display
Replies 3 (3)

Atanu_Sarkar
Shopify Partner
10 3 3

Hi @Bontalexel31 ,

Please apply a json filter in the value while printing, here's the code below.

 

console.log('avg_swatch value ', {{ avg_swatch.value | json }})

 

Let me know if it works.

Bontalexel31
Shopify Partner
28 2 4

Hi, @Atanu_Sarkar Thank you for replying,

 

I tried the filter you mentioned, and it doesn't work but now I get a value of "null" instead of "undefined" in the console.

Show Variant Options as Text or Colored Swatches with Add to cart Button on Home and Collection Page
Install it now for free!
Swatch Display: https://apps.shopify.com/swatch-display
Webwizzy
Shopify Partner
18 1 1

Im starting to get seriously annoyed.... this .liquid **bleep**e is pure shte... why built a template engine that don't know anything.

Honestly the whole template stuff is bugged out.... you have to put "parse_json" as the flag... however, this gives CLI errors....

I cant access app owned metafields either... which is stupid... the whole .liquid themeing is stupid.

Basically you have to built a template in .liquid, but also create a JSX element... why not just use .jsx/tsx for templating, then you could reuse components... I'm so frustrated getting into shopify development... there isn't even a add/remove cart items event... everything basically sucks.

Fullstack Developer - Founder of the cryptocurrency market data aggregator, https://www.bitculator.com