Outputting a metaobject entry in a packing slip via product metafield references

Hey!

I’m writing a packing slip template to output a customs declaration form, and I need to connect a manufacturer address to each line item.

I don’t want to input the address individually for every product, so I have the manufacturers set up in a custom brands metaobject, connected to each product by a metafield:metaobject reference.

  • product metafield: ship.brand [metaobject reference, single entry]
  • connected metaobject: brands
  • metaobject fields: brand_name; address1; city; region; country; a couple more

However, I can’t find any documentation on how to reference a field in a metaobject entry via a “metaobject reference” product metafield.

Current attempt (blank output): {{line_item.product.metafields.ship.brand.brands.brand_name}}

Thoughts?

Hello @pureonline,

I’m not entirely sure if this level of dynamic sources is available for the packing slip templates, but if they are, use the following:

{% liquid
  assign brand = line_item.product.metafields.ship.brand.value
  assign brand_name = brand.brand_name.value
%}
  • First, you access the product associated with the line_item
  • Then, you access the associated metafield reference using metafields.namespace.key
  • This metafield references a metaobject, so you have a MetaobjectDrop at this point, that should return gid://xxx if output directly
  • To access the metaobject, you need to use .value
  • From there, you can access the fields using their property name (i.e. brand_name)
  • Same as earlier, this gives you a reference to the field
  • To access the actual data, you need to use .value

Note: for most basic types, not using .value will yield the correct result. But for reference fields (product, collection …), you will get nothing without, just like accessing the brand metaobject data.

Take the good habit to use .value when dealing with references inside metafields/metaobjects and you should be good ! Still, don’t know if packing slip templates work for this, good luck !