I am building a site that uses Drupal Commerce 2 and I am attempting to build out the product details template. Our product has a variation (field_accessories) which is an entity reference to another product and I am trying to access the title, the images (first one actually), and the link to the product's detail page.
I got the title showing with
{{ product['field_accessories'][0]['#commerce_product_variation'].getTitle() }}
and I can get the sku and price with:
{{ product['field_accessories'][0]['#commerce_product_variation'].getPrice() }}
{{ product['field_accessories'][0]['#commerce_product_variation'].getSku() }}
But I need the images and url link. Based on the available methods from using kint on the product['field_accessories'][0]['#commerce_product_variation'] I tried:
{{ product['field_accessories'][0]['#commerce_product_variation'].get('field_images') }}
and
{{ product['field_accessories'][0]['#commerce_product_variation'].getField('field_images') }}
and
{{ product['field_accessories'][0]['#commerce_product_variation'].getField('images') }}
but nothing is working and all come back with null.
When I do a product['field_accessories'][1]['#commerce_product_variation'].getFields()
I see the following:
Any ideas on how to access the field_images and url to that product's page? Thanks and let me know!