Searching for item SKU in Commerce orders I'm trying to show some Commerce 2 order information on the front-end. I can't work out the correct syntax. I'm trying to list orders that include a specific product.

I have orders for item SKU "abc123" but this is returning no results.

{% set myOrderQuery = craft.orders()
    .relatedTo("abc123")
    .limit(10)
    %}

{% set orders = myOrderQuery.all() %}

{% if orders|length %}
  &lt;ul&gt;
    {% for order in orders %}
      {% for item in order.lineItems %}
        &lt;li&gt;{{ item.sku }}&lt;/li&gt;
      {% endfor %}
    {% endfor %}
  &lt;/ul&gt;
{% else %}
  &lt;p&gt;No results&lt;/p&gt;
{% endif %}


If I remove the .relatedTo parameter I get results including orders for that item. How do I just return orders that include that item?

I've tried various permutations of relatedTo and search but haven't found anything that works yet.
Use the hasPurchasable order query param:

https://docs.craftcms.com/commerce/v2/dev/element-queries/order-queries.html#haspurchasables

{% set myOrderQuery = craft.orders()
    .hasPurchasables(product.defaultVariant)
    .limit(10)
%}