Demac Media Demac Media Brand Demac Media Brand



How to add Shopify Options

Timer Icon 4 Mins


Shopify is a very flexible eCommerce platform that allows its clients to customize their catalogues according to their respective business needs. In previous tutorials I have discussed how to add products and variants to Shopify. In this blog, I will explain to how to vary different products in your store using options, and illustrate how they can be pushed into the store using the API.

Understanding Shopify’s Options

Essentially, Shopify options are values that your products vary by. For example, a shirt can vary by size or colour. Hence, for each size you can have small, medium or large, and for each colour the product can vary by red,green or blue.

These options have to be unique for a product. For instance, a product can’t vary by the same green colour. If the options are not unique the API would throw an error, suggesting that the options are not unique.

Uploading a product with an option is a bit tricky, and it took me a while to understand how to upload a product with options, and assign values to them accordingly.
Before I progress further, it is important to clarify that a Shopify product and a variant are two different things.The options in particular are assigned to a Shopify product, but the value of those options is assigned to a variant product.The following code snippets would help explain my point further.

public class ShopifyProduct
  public string id{ get; set; }
  public string title{ get; set; }
  public string handle{ get; set; }
  public string option1 { get; set; }
  public string option2 { get; set; }
  public string option3 { get; set; }
        More Shopify fields

The above sample class shows some fields, a Shopify product might have. As you can see I have three option fields assigned to this product. These are the options that the product can vary by. The options can have the following assigned values, as shown by the JSON string below

    "product": {
            "option1": “Size”,
            "option2": “Colour”,
            "option3": “Material”

Also, notice that I have used only three options in my example. This is because a product can only have, not more than three, options.

As I mentioned before these options are part of a Shopify product and this dictates the type of values a product can vary by. The values are assigned to a variant product.

Multiple Variants

A Shopify product can have multiple variants and each variant can be assigned a unique set of options. The class below, can help you visualize this.

public class Variant
  public string sku{get;set;}
  public string title { get; set; }
  public string price { get; set; }
  public List<Option> options { get; set; }
/*More fields here*/

public class Option
  public string id { get; set; }
  public string name { get; set; }
  public string position { get; set; }
  public string product_id { get; set; }
  public string value { get; set; }

The Options class above contains all the fields that are required to assign an option to a variant. The product_id is the variant product id in this case, and the value is the value assigned to the option. For example, the option Color might consist of the option value “red” or “green”.These options are assigned to a variant as a list, as described by the variant class above.

When developing for the API, it is important that your code creates a Shopify product with the options and then assign option values when assigning variants of those products. This will insure that your product integration runs smoothly and effectively.

Until next time Happy Coding!

Subscribe to the Blog

Stay updated with 20,000+ eCommerce leaders in our community

Sign Up

Let’s talk about your 10X return

Icon/Social/Phone Contact us for pricing information