Site icon MageComp Blog

How to Get Active Theme ID of Shopify Store in Shopify-Laravel App

How to Get Active Theme ID of Shopify Store in Shopify-Laravel App

Hello Shopify Friends,

Today I am going to explain How to Get the Active Theme ID of the Shopify Store in the Shopify-Laravel App.

It sometimes happens that we require the currently activated theme ID of your Shopify store to perform some action.

So here is the solution to get active theme data. We have used the osiset/laravel-shopify addon to get theme data. Also checkout the latest Shopify editions with 100+ new products and updates.

Steps to Get Active Theme ID of Shopify Store in Shopify-Laravel App:

Step 1: Integrate osiset/laravel-shopify addon with your Shopify app.

Check – How to Integrate Shopify App with Laravel

Step 2: Visit the below file path.

app\Models\User.php

Use the following code in the User Model file

public function getActiveThemeId()
{
         $active_theme_id = 0;
         $themes=$this->api()->rest('get','/admin/api/2021-07/themes.json');
         $themes=$themes['body']['container']['themes'];

         foreach($themes as $theme)
         {
             if($theme['role']=="main")
             {
                 $active_theme_id=$theme['id'];
             }
         }
         return $active_theme_id;
}

Note: You can use getActiveThemeId() function anywhere using user object

Conclusion:

Accordingly, you can retrieve the ID of the active theme on your Shopify website. If you face any difficulty in getting a theme ID, our Shopify Professional Developers can help you out. Mention the error in the comment box.

Happy Coding!

Exit mobile version