skip to Main Content

I am trying to reduce unnecessary calls to the Shopify API from a controller that inherits from ShopifyApp::AuthenticatedController, for example to get the myshopify_domain:

myshopify_domain = ShopifyAPI::Shop.current.myshopify_domain

Is there some method in ShopifyApp::SessionRepository or somewhere else in the ShopifyApp that I can call to retrieve Shop.current.myshopify_domain without making an actual call to the Shopify API webservice? If not, can I store the myshopify_domain, once retrieved, in the ShopifyApp::SessionRepository?

3

Answers


  1. Chosen as BEST ANSWER

    The myshopify_domain is usually available in the session parameters:

    if !session[:myshopify_domain].nil? && !session[:myshopify_domain].empty? session[:myshopify_domain] else session[:myshopify_domain] = ShopifyAPI::Shop.current.myshopify_domain end


  2. Your question is confusing. At the point where you are doing calls to the API, you clearly already know the myshopify_domain, as you cannot do API calls with that the shops name and token.

    So now we’re past that point, and you are asking how you can somehow have the myshopify_domain be more convenient for you to use? Just make yourself a little helper so that when you open a session, you have access to shop_name or whatever you want.

    Shopify always sends you shop name in their requests, so you’re covered there as it’s a param, and your own interface code and calls will also be setting up the shop name too, so you’re really now into some pretty esoteric territory to need anything else.

    Seem like you’re caught in a classic “the dog chasing its own tail”, but why?

    Login or Signup to reply.
  3. If you are in the AuthenticatedController, dump the following to the console:

    session.to_json
    

    You will see that you can access all sorts of stuff about the current session, such as:

    session["shopify_domain"]
    session["shop_id"]
    

    I had the same problem with a muli-store app, where I needed to pull data tied to a specific store. ShopifyAPI::Shop.current.myshopify_domain is redundant in that you are slowing down the controller waiting for Shopify’s response, and you are tinking down the api bucket limit. The session object is the superior method to avoid all of that, and should be accessible from any controller which inherits the ShopifyApp::Authenticated controller.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search