Excuse my new-ness, but I'm having an issue with product variants.
Scenario
I have a product with multiple variants (up to 30 in fact). Based on the URL, I want to choose a specific variant so that I can display fields from that variant on my product detail page. I also want a 'default variant' if there is no variant specified in the URL.
In my example, the variant should be selected by a custom field in that variant colour
whose value match the 4th URL segment.
Code
{# Grab colour segment #}
{% set colourSlug = craft.request.getSegment(4) %}
{# If there is no colour, we grab the first variant colour #}
{% if not colourSlug %}
{# Grab first product variant #}
{% set dressColour = product.defaultVariant %}
{% else %}
{# Set dress colour #}
??{% set dressColour = product.variants.find(colour.colourSlug) %}??
{% endif %}