<p>Usually when selling goods that come in different size and colors, a different SKU would exist for any size/color combination that you sell, thus a unique variant.</p>

<p>So, when that item becomes low in stock (<code>S</code>tock <code>K</code>eeping <code>U</code>nit), you can order more in.</p>

<p>In Craft Commerce we do not automatically generate every combination of variant based on the custom fields attached to a variant because most stores never sell every combination, and also, not every custom field is a unique aspect of that variant.</p>

<p>If more options are added to a product, there is nothing forcing you to make every combination as a variant, you could just use an option/custom field to mark a single variant as special (i.e Gold Edition).</p>

<p>If you are selling something that has a lot of options that customers are required to choose from each option, there is nothing stopping you from building a UI on the front end that makes selecting a variant possible based on all the options of all the custom fields. In that case your front end UI is building a query for a variant (<code>craft.commerce.variants</code>).</p>

<p>If you're not really selling a unique single SKU, but rather wanting a 'build a product' type product based on smaller SKUs, like building a bike, then you would need to build that yourself on the front end and/or with a plugin. That plugin would track what is in the cart, and which items still need to be added to complete the bike.</p>

<p>An alternative to that is building a <a href="https://craftcommerce.com/docs/purchasables" rel="noreferrer">custom purchasable</a> with a plugin. This would allow you to expose the building of the purchasable element to the customer (with any options or custom logic you wish), and once the purchasable is saved by the customer, they can add it to the cart.</p>

<p>Lastly, if you don't want to go down the custom purchasable route, you can always just use generic <a href="https://craftcommerce.com/docs/add-to-cart#line-item-options-and-notes" rel="noreferrer"><code>options</code> params</a> when adding a product to the cart to allow any extra customer choices for the product. If the price is the same for the product regardless of the option chosen, this might be the easiest path if you have a huge amount of options and don't want to have a variant for each. The only thing you would want to do is validate the options for the current product.</p>

<p>The <a href="https://craftcommerce.com/docs/add-to-cart#line-item-options-and-notes" rel="noreferrer">line item options</a> feature mentioned above can also be combined with a small plugin that modifies the price of the line item based on the options choosen with the <a href="https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem" rel="noreferrer">onPopulateLineItem</a> event. The plugin would use the event something like this:</p>

<pre><code>craft()-&gt;on('commerce_lineItems.onPopulateLineItem', function($event){

$purchasable= $event-&gt;params['purchasable'];
$lineItem = $event-&gt;params['lineItem'];

  if(isset($lineItem-&gt;options['giftWrapped']) &amp;&amp; $lineItem-&gt;options['giftWrapped'] == 1){
    $lineItem-&gt;price = $lineItem-&gt;price + 1;
    $lineItem-&gt;salePrice = $lineItem-&gt;price;
    $lineItem-&gt;saleAmount = 0;
  }
}
</code></pre>

<p>Remembering that using the options method above will not be compatible with any stock tracking or inventory features now or in the future.</p>

<p>Let me know if you have any follow up questions and I can improve the answer above.</p>

CC BY-SA 3.0
2016-11-26T03:18:54.083Z
2016-11-26T03:18:54.083Z
Luke Holder
<p>I'm in the process of setting up a shop with Craft Commerce but I'm having some trouble organising the data structure of the products. The problem is that some products have both sizing and color options but I'm not sure how to enter these in the back-end. The most obvious way of doing this would be to make a product variant for each possible combination, like so:</p>

<p><strong>Variant 1:</strong> color 1 - size 1<br>
<strong>Variant 2:</strong> color 2 - size 1<br>
<strong>Variant 3:</strong> color 1 - size 2<br>
<strong>Variant 4:</strong> color 2 - size 2</p>

<p>I guess this would work but there will be a lot of variants. And if another one or two options are added in the future the amount of variants will grow exponentially.</p>

<p>Any insight on this would be much appreciated, thanks!</p>

<plugin-craftcommerce>
Structuring products variants
# Structuring products variants

(Asked by: username_0 on 2016-11-21)

I'm in the process of setting up a shop with Craft Commerce but I'm having some trouble organising the data structure of the products. The problem is that some products have both sizing and color options but I'm not sure how to enter these in the back-end. The most obvious way of doing this would be to make a product variant for each possible combination, like so:

**Variant 1:** color 1 - size 1  
**Variant 2:** color 2 - size 1  
**Variant 3:** color 1 - size 2  
**Variant 4:** color 2 - size 2

I guess this would work but there will be a lot of variants. And if another one or two options are added in the future the amount of variants will grow exponentially.

Any insight on this would be much appreciated, thanks!

**Tags:** plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2016-11-26. Score: 9 | Accepted answer

Usually when selling goods that come in different size and colors, a different SKU would exist for any size/color combination that you sell, thus a unique variant.
So, when that item becomes low in stock (Stock Keeping Unit), you can order more in.
In Craft Commerce we do not automatically generate every combination of variant based on the custom fields attached to a variant because most stores never sell every combination, and also, not every custom field is a unique aspect of that variant.
If more options are added to a product, there is nothing forcing you to make every combination as a variant, you could just use an option/custom field to mark a single variant as special (i.e Gold Edition).
If you are selling something that has a lot of options that customers are required to choose from each option, there is nothing stopping you from building a UI on the front end that makes selecting a variant possible based on all the options of all the custom fields. In that case your front end UI is building a query for a variant (craft.commerce.variants).
If you're not really selling a unique single SKU, but rather wanting a 'build a product' type product based on smaller SKUs, like building a bike, then you would need to build that yourself on the front end and/or with a plugin. That plugin would track what is in the cart, and which items still need to be added to complete the bike.
An alternative to that is building a custom purchasable with a plugin. This would allow you to expose the building of the purchasable element to the customer (with any options or custom logic you wish), and once the purchasable is saved by the customer, they can add it to the cart.
Lastly, if you don't want to go down the custom purchasable route, you can always just use generic options params when adding a product to the cart to allow any extra customer choices for the product. If the price is the same for the product regardless of the option chosen, this might be the easiest path if you have a huge amount of options and don't want to have a variant for each. The only thing you would want to do is validate the options for the current product.
The line item options feature mentioned above can also be combined with a small plugin that modifies the price of the line item based on the options choosen with the onPopulateLineItem event. The plugin would use the event something like this:
craft()->on('commerce_lineItems.onPopulateLineItem', function($event){

$purchasable= $event->params['purchasable'];
$lineItem = $event->params['lineItem'];

  if(isset($lineItem->options['giftWrapped']) && $lineItem->options['giftWrapped'] == 1){
    $lineItem->price = $lineItem->price + 1;
    $lineItem->salePrice = $lineItem->price;
    $lineItem->saleAmount = 0;
  }
}

Remembering that using the options method above will not be compatible with any stock tracking or inventory features now or in the future.
Let me know if you have any follow up questions and I can improve the answer above.


---

