2

I'm trying to display the value/price of the default variant for a product.

This is what I currently have:

{% for variant in product.variants %}
  From {{ variant.price|currency(cart.currency) }}
{% endfor %}

This displays the price of every variant that a product has. How can I just display the default variant price? Or better still, the product variant with the lowest price.

3

You can access the default variant using {{ product.defaultVariant }}.

Because product.variants isn't an ElementCriteriaModel you can't sort it like one. You'd have to retrieve the products variants as an ElementCriteriaModel first like so:

{% set lowestPriceVariant = craft.commerce.variants({
  productId: product.id,
  order: 'variants.price'
}).first() %}

{{ lowestPriceVariant.title }}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.