<p>Untested, but something like this should work:</p>

<pre><code>{% set products = craft.commerce.products({
  hasVariant: {sku: 'my-sku-number'}
}).first() %}
</code></pre>

<p>See: <a href="https://craftcommerce.com/docs/craft-commerce-products#hasvariant" rel="nofollow noreferrer">https://craftcommerce.com/docs/craft-commerce-products#hasvariant</a></p>

<p>If you only want to search the default variant of the product:</p>

<pre><code>{% set products = craft.commerce.products({defaultSku : 'my-sku-number'}).first() %}
</code></pre>

<p>See: <a href="https://craftcommerce.com/docs/craft-commerce-products#defaultsku" rel="nofollow noreferrer">https://craftcommerce.com/docs/craft-commerce-products#defaultsku</a></p>

CC BY-SA 3.0
2017-11-17T05:06:23.040Z
Thanks Luke, that works. Turns out the client entered some skus to search with a related product, before adding those specific products and skus. Nothing like deadlines between developers and marketers!
jrothafer
CC BY-SA 3.0
2017-11-17T04:50:37.257Z
2017-11-17T04:50:37.257Z
Luke Holder
<p>I need to get a product variant as an object in Twig, as well as get its parents details (the product fields, not just the variant fields). My first guess starts with this:</p>

<pre><code>{% set variant = craft.commerce.products.sku('my-sku-number') %}
</code></pre>

<p>But that doesn't work. I've also tried adding a the <code>.first()</code> limiter to the end. What am I missing?</p>

<p><strong>Edit</strong></p>

<p>Thoughts... should I be trying a search/find?</p>

<plugin-craftcommerce>
How to get a product variant by SKU and get parent product details as well?
# How to get a product variant by SKU and get parent product details as well?

(Asked by: username_0 on 2017-11-17)

I need to get a product variant as an object in Twig, as well as get its parents details (the product fields, not just the variant fields). My first guess starts with this:
{% set variant = craft.commerce.products.sku('my-sku-number') %}

But that doesn't work. I've also tried adding a the .first() limiter to the end. What am I missing?
Edit
Thoughts... should I be trying a search/find?

**Tags:** plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2017-11-17. Score: 2 | Accepted answer

Untested, but something like this should work:
{% set products = craft.commerce.products({
  hasVariant: {sku: 'my-sku-number'}
}).first() %}

See: https://craftcommerce.com/docs/craft-commerce-products#hasvariant
If you only want to search the default variant of the product:
{% set products = craft.commerce.products({defaultSku : 'my-sku-number'}).first() %}

See: https://craftcommerce.com/docs/craft-commerce-products#defaultsku

> **Comments:**
> **username_0**: Thanks Luke, that works. Turns out the client entered some skus to search with a related product, before adding those specific products and skus. Nothing like deadlines between developers and marketers!  

---

