Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the ID of the active theme from the Theme API

Tags:

shopify

Using the Shopify Theme API (Link), I'd like to be able to get the theme ID for the currently active (main) theme.

I'm using the api gem as follows:

Shopify::Theme.find(:all, :params => { :role => 'published' })

It returns every installed theme and not just the main, published theme. Can I access a Theme this way?

like image 218
Kelly Heard Avatar asked Oct 25 '25 02:10

Kelly Heard


2 Answers

You can't filter on role the way you're trying to.

However, seeing as each shop can only have a maximum of 8 themes it's not much effort to simply grab all the themes with ShopifyAPI::Theme.all and then search through them for the one being used as the main one.

like image 159
David Underwood Avatar answered Oct 26 '25 17:10

David Underwood


You can also try getting the ID through Assets like this:

@theme_asset = ShopifyAPI::Asset.find('layout/theme.liquid')
@theme_asset.theme_id
like image 27
Alex Kozlov Avatar answered Oct 26 '25 17:10

Alex Kozlov