Shopify App PHP framework Online / Offline access mode

When you develop an embedded Shopify App with PHP Laravel framework, you can set up your app with online or offline OAuth mode very easily as below:

you just need to locate the web.php file at {php-project-root}/routes/web.php

Route::get('/login', function (Request $request) {
    $shop = Utils::sanitizeShopDomain($request->query('shop'));

    if (!$request->hasCookie('shopify_top_level_oauth')) {
        return redirect("/login/toplevel?shop=$shop");
    }

    $installUrl = OAuth::begin(
        $shop,
        '/auth/callback',
        true,
        ['App\Lib\CookieHandler', 'saveShopifyCookie'],
    );

    return redirect($installUrl);
});

as above snippet codes line 11, it is bool variable:
true: means is online mode
false: means is offline mode

If you follow the default Shopify guide as your default PHP start project, there is no problem with the default settings (default is online mode).

if you want to test an offline mode, you will find your product page will show an error message:

“There was an issue loading products.”

that is because, in offline mode, your GraphQL call will fail.

Please follow and like us:
Pin Share

You may also like...

Leave a Reply

Your email address will not be published.