Liquid - Checkout Object JSON filter return "nulls"s for line items

amosmos
Shopify Expert
32 1 15

Hi,

 

In our client's checkout.liquid template (Shopify plus account), when writing 

{{ checkout.line_items | json }}

We're getting an array of "null" elements, their count is as the number of line items.

So for example if the user has 4 line items, we're getting: ["null", "null", "null", "null"], instead of the actual json of each line items.

 

This seems like a bug but if we're missing something please let us know.

 

Thanks!!

Amos

 

Visely-Team
Shopify Partner
1837 210 421

Odd, what happens when you try?

{{ checkout | json }}
Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
KarimTarek
Shopify Partner
20 0 3

Hey @amosmos were you able to figure this out?

@Visely-Team FYI `{{ checkout | json }}` -> `{error: "json not allowed for this object"}`

Shopify development consultant @ bespark.ca
0 Likes
amosmos
Shopify Expert
32 1 15

No, I had to access each property directly instead of the whole object :-(

0 Likes
KarimTarek
Shopify Partner
20 0 3

Care to shed some light? Code snippet maybe :)

Shopify development consultant @ bespark.ca
0 Likes
amosmos
Shopify Expert
32 1 15

{{ checkout.order | json }}

{{ checkout.customer | json }}

{{ checkout.line_items | json }}

and so on

0 Likes
KarimTarek
Shopify Partner
20 0 3

Hmmm interesting! 🤔

This isn't working for me, I get an array of nulls:

{{ checkout.line_items | json }}

Anyway thanks so much 🙏

Shopify development consultant @ bespark.ca
0 Likes
amosmos
Shopify Expert
32 1 15

Sorry, you're right.

I meant doing a loop in liquid and then outputting each line by itself.

But I do see in our code that we didn't use that eventually, so I don't know if that works either.

KarimTarek
Shopify Partner
20 0 3

Hey @amosmos 

 

This works:

{% for line_item in checkout.line_items %}
  {% if line_item.product.tags contains 'no-free-shipping'%}
    console.log( "💥💥💥 BINGO 💥💥💥 ", {{ line_item.product | json }} )
  {% endif %}
{% endfor %}

I though line_item is a product object, so we need to access product before we're able to access any product attributes 🎉

Shopify development consultant @ bespark.ca