0

Folks:

I figured this would be simple but apparently not (for me, anyway).

  • I have a product with two variants (orange and yellow).
  • I have a page that lists all the available products.
  • On that page, both variants appear. I really just need one and users can select their variant from a drop-down on the checkout page.

What I've got:

{# get the products from the categories #}
{% set products = craft.commerce.products.type('shirts,shorts') %}

{# show the product main image and link to the product page #}
<a href="{{ product.url }}">
    {% if product|length %}
        {% set asset = product.productHeroImage.first() %}
    <img src="{{ asset.url }}">{% endif %}
</a>

I did try {% set products = craft.commerce.products.defaultVariant.type('shirts,shorts') %} but get the same results.

0

OK, so this did have a really simple solution. Just use isDefault.

{% if variant.isDefault %}Show the product{% endif %}

Works like a charm.

| improve this answer | |

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.