Category Archives: Shopify

I recently worked on a reasonably large shopify project where the potential categories (collections) counted approximately 190. We built the menu based on those collections, but the problem was that until we had products imported for those collections we didnt want to show the menu item.

Using the supply menu I edited the site-nav.liquid file in the snippets directory and added a line under each of the for loops that build the menu items and added a test to see if a. the time was based on a collection and if the number of products in that collection where over 0. This was done using an <%unless %> tag – look at the bolded lines below.

Yep.. I’ve joined the dark side.. from .net to python.. What is more I’m moving away from Ecommerce Sites that i have built from scratch to the more universal Shopify Platform (at least for evaluation reasons)

On first blush this may be better as an ecommerce site than i expected. It has some shocking limitations like only supporting a VERY limited number of payment gateways and having little to no concept of an ACH transaction (ones that take money directly from a persons bank account.. WAY cheeper than running credit card transactions..

One of my tasks was to see if we could write code to generate a menu based on our products taxonomy. Out of the box our company sells around 130 different categorys and if we didn’t script this creation it would be really easy to have unreachable products after the import. The fact that Shopify doesn’t really even understand categories isn’t that much of a problem.. What it does have is “collections”, “collections” come in 2 flavors, dynamic and static.

Because we want automatic incorporation of products as they are uploaded into Shopify the correct choice is dynamic.

So.. how did we manage to script the creation.. Most of the documentation is in PHP.. but our current flavor of language is python and as much as it is probably possible to just convert the code over, shopify was nice enough to create a PYTHON based api that allows you to work with both the ADMIN api and STOREFRONT api. The ADMIN api actually providing all the ability required to work with products or collections

You also need to generate API keys for shopify. To do this login to your store and create a new “app key”

Log into your store and in theme actions click “Edit Code”

On the next screen select “Apps” in the left hand menu.

On the Apps Screen select (at the bottom of the page) “Manage Private Apps”

If you don’t already have one click the button labeled “Create a new private app” (top right)

On the next screen review all the permissions available and what they pertain to (select the ones you need)

You will need the followitn values after going to your app (copy them somewhere)
API key
Password
Shared secret
and example u8rl (as a sanity check)

From the python side you need to install the Shopify Python API (docs:http://shopify.github.io/shopify_python_api/)

open a bash prompt

use pip to install the api pip install –upgrade ShopifyAPI

In this example I’m just going to create a simple python file that can be executed from a command prompt of some type. (bash or dos)

x = shopify.SmartCollection().find()print('-------------------------------------------------------------')
# print x
for y in x:
# if y.attributes["title"] == "rob test":
# print y.__dict__# prints all the properties of the collection
# print y.attributes['title']
print y.__dict__
# the properties are all stored in a dictionary.. you can loop through

# them if needed.
print('-------------------------------------------------------------')