# Shopify

## Introduction

Shopify is one of the big players in the e-commerce scene. If you are ready to create an amazing showcase for your products and as well as create a great shopping experience for your clients, use this step by step guide to learn how to add an interactive and customizable 3D models from Verctary.

For this guide we will use a `free` template that Shopify provides when creating a new shop called `Dawn`.

This integration **does require minor changes to the templates**, but do not worry, the process is fast and easy.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FUcMNFZfN1eFVNgSEbnKX%2Fimage.png?alt=media&#x26;token=f83f204d-3c14-4aa1-84cf-a347c46f14ac" alt=""><figcaption></figcaption></figure>

## Requirements

For integrating with `Shopify` you will need the following:

* A Shopify account with an active `free trial` or `paid subscription`

## Vectary setup

### 1.1. Create a folder for the product models

This is an important part of any integration. **Use the id of the folder to fetch and map your models to the products** you have/will setup in the e-shop.

You can see the id when it is selected inside the [Dashboard](https://vectary.com/dashboard), directly in the URL after the string `&folderId=`.

### 1.2. Create the model of your product/s

In this case, we created an abstract design called `Awesomeness`. **The name of your project needs to match the name of your product**.

Here is the model you can clone directly into a new project in your workspace: <https://www.vectary.com/p/5s8oStuOPjH9E2xrRVje3q>\
\
It features a `Variant` with 3 different objects, and each of the variants contains the same 3 materials. **Make sure to link the materials if they are the same between each variant**.

We can expose these through the `Floating UI` by adding a `Materials` and a `Variants` sub-objects.

Please note that the `source` of the MSController is the Object Switcher containing the variants.

&#x20;![](https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FVH6XHcXPUSEIHKQxGz6z%2Fimage.png?alt=media\&token=c9f72a5d-3b26-448c-a6a1-7f4c1eccd006)         ![](https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FrEMsBf5SCYBm4j8CfHLc%2Fimage.png?alt=media\&token=5eca8124-1b27-486b-a779-baf690b4ab6c)

### 1.3. Share your model

Go ahead and [share](https://help.vectary.com/documentation/sharing-exporting-embedding/sharing)

Please remember that:

* The name of the project matches the name of the product.
* The names of the objects and their materials match the options/variants that are setup for the product in the e-shop.

## Shopify’s setup

### 2.1. Add products

First of all we need to make sure we have at least one product. Remember that **the names of the products need to match the names of the models** we are creating in Vectary.

For the purposes of covering all the options that are possible in this guide, we are going to use a product with `options` (that will generate `variants`).

To add options to a product simply edit the chosen product, scroll down to the `Options` section and start adding.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FuwWYnDPRwZTRZuiKPQBS%2Fimage.png?alt=media&#x26;token=9a3d9890-6641-4758-b725-ab7bd379b678" alt=""><figcaption></figcaption></figure>

If the default Option names do not match with what you would need, please look for a plugin/app instead of using the defaults from Shopify.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FGyn768nBBPCXVWjePMeR%2Fimage.png?alt=media&#x26;token=0852a276-fb89-4881-aa5b-c26e5bf7a408" alt=""><figcaption></figcaption></figure>

In this case, here are the options that we’ll be working with, and that mimic what we have setup in Vectary.

From these options the `variants` are then generated. It is possible to manage price and inventory individually for each one.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FqckuJgjp8OBj4s5QaQjE%2Fimage.png?alt=media&#x26;token=2b439c42-ed9d-4025-bdbb-0f65afe18cf9" alt="" width="302"><figcaption></figcaption></figure>

### 2.2. Add the iframe and api script

Now, edit the theme. To do that, we will select the Themes page under our Online Store.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FIJbIXgFNiYKJ4RtdISTv%2Fimage.png?alt=media&#x26;token=27bf05bb-d6e0-4322-ad43-7519acb62b43" alt=""><figcaption></figcaption></figure>

In our case we are working with Shopify’s default Dawn theme (v12.0.0).

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2F3c5UtavmSIDnWAHfXw93%2Fimage.png?alt=media&#x26;token=cd81d9b5-ed45-4616-8471-7e3a77a62433" alt=""><figcaption></figcaption></figure>

What we want to do is to click on the Edit code button.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FpjYYlwaDUvYpZYUtmwGw%2Fimage.png?alt=media&#x26;token=90f968f8-68ce-4f75-8873-9f9386dd7aa5" alt=""><figcaption></figcaption></figure>

A new view will open. Search for a specific file called product-media-gallery.liquid, which should be under the Snippets folder.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FPGnyNMCYMA2uzMwMe7ij%2Fimage.png?alt=media&#x26;token=bd274aac-bd10-42fb-85ec-7d1c838e9bb6" alt=""><figcaption></figcaption></figure>

Look for the container that holds the [`Media`](https://help.shopify.com/en/manual/products/product-media). Add it to the products, and then add our custom code.

Here’s how to find it:

* Click anywhere in the code
* Press `ctrl+f`(Windows) or `cmd+f`(Mac)
* Paste the text `id="Slider-Gallery-{{ section.id }}`
* Hit intro

You should be able to see (or similar) as selected:

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2F7twhTUC4QmKcBndHOUYS%2Fimage.png?alt=media&#x26;token=5ddc9171-3d01-4cbf-b3b2-c1ade037907a" alt=""><figcaption></figcaption></figure>

If you don’t find it, that probably means your theme is set differently.

{% hint style="danger" %}
In older theme versions this code we located in the main-product.liquid file, under the Sections folder. Check it out in case you don’t find it there.
{% endhint %}

Please [get in touch with us](https://www.vectary.com/contact-us/) or contact your sales representative, and we will assist you in figuring out a solution.

Paste the following code under the last line in the previous screenshot:

```javascript
<!-- My Vectary integration start -->
<li class="product__media-item grid__item slider__slide is-active">
  <iframe id="vectary_embed" 
		src="https://app.vectary.com/p/{shared_model_id}" 
		frameborder="0" 
		width="100%" 
		height="480">
	</iframe>
</li>
<script type="module">
  // Init Model API
	import { VctrModelApi } from "https://app.vectary.com/studio-lite/scripts/api.js";
  var modelApi = new VctrModelApi("vectary_embed");
  await modelApi.setShopify("{folder_id}", "{{ product.title | escape }}");
</script>
<!-- My Vectary integration end -->
```

Let’s analyze exactly what we are adding to make sure everything is how it is supposed to be:

1. `li` element that contains the iframe of our embed.
   1. We added the same `class` names that are used for any other media that is used in our current theme.
2. `iframe` element that contains **any of your shared projects in the folder** we created.
   1. You need to change the `{shared_model_id}` in the `src` attribute for a valid id.

{% hint style="info" %}
Do not worry about which of the product ids you add here. The script will take care of selecting the right product id from your folder based on the `product.title`, but Shopify needs to have a valid `src` input, otherwise it will not allow to load the `iframe`.&#x20;
{% endhint %}

&#x20;        b. Replace the iframe code directly from the Copy embed button in Vectary share popup - [sharing](https://help.vectary.com/documentation/sharing-exporting-embedding/sharing "mention")

3. `script` tag which in turn:
   1. Imports our `VctrModelApi`.
   2. Creates a new instance of the API, linking to the `iframe` embed we just added using its DOM `id` (e.g. `vectary_emebed`).
   3. Sets the integration with `{folder_id}` from step **#1.1**

Don’t forget to Save!

One more thing to consider, in case you just want to use the Vectary embed to showcase your product and/or **you will not add any other pictures**. Please note that some themes can change the layout of the product page when they detect that there is no media attached.

To avoid that do the following:

* Search for & open the `main-product.liquid` file
* Press `ctrl+f`(Windows) or `cmd+f`(Mac)
* Paste `if product.media.size > 0` in the `Find` field
* Paste `if product.media.size >= 0` in the `Replace` field\
  ![](https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2F348YYC5d3irXJBUKcMZi%2Fimage.png?alt=media\&token=cefec742-ccfb-4758-bb97-872b3f39a255)
* Click on the `replace all` button and `Save`

If your product names match the model names, and if the product options also match the names of the materials and objects used, you should be able to see how they influence each other in the product page:

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FnMFXHnohA49ziOUKsSKE%2Ftest.gif?alt=media&#x26;token=d5778b48-95f1-4c17-bf7f-ae92d94158af" alt=""><figcaption></figcaption></figure>

It also works by default with a different `Variant picker` type.

You can select another type when you `Customize` your theme in the `Default product` page.\
\
![](https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2F6DOCsikvsea4QtzAry9M%2Fimage.png?alt=media\&token=f4b10e70-8d3c-4f19-a208-b86d22ec7d45)

![](https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FRucIoDc8tbhn16K6t5RH%2Fimage.png?alt=media\&token=037cda5f-ff88-42dd-9433-28fe625ad6e4)

![](https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2Fo6QC5QiW0o0YhtqUCQFo%2Fimage.png?alt=media\&token=c3c85d70-8d79-46b9-aee7-d1e55e038105)<br>
