PHP code example of culturekings / shopify-app-auth-laravel

1. Go to this page and download the library: Download culturekings/shopify-app-auth-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

culturekings / shopify-app-auth-laravel example snippets


Route::group(
    [
        'prefix' => 'shopify-apps',
        'namespace' => 'ShopifyApps',
        'middleware' => 'CultureKings\ShopifyAuth\Http\Middleware\ShopifyAuthCheck'
    ],
    function () {
        Route::get('appname', 'AppnameController@getDashboard');
    }
);

'appname' => [
    'name' => 'app_name', // checked in db, so shouldn't change after launch
    'price' => 0.00,
    'redirect_url' => '/shopify-auth/app_name/auth/callback', // relative uri
    'success_url' => '/shopify-auth/app_name/install/success',
    'dashboard_url' => '/apps/app_name/dashboard',
    'scope' => [
        "write_products",
        "write_script_tags"
    ],
    'view_folder_path' => 'shopify-apps.app_name',
    'view_install_success_path' => 'shopify-apps.app_name.install-success',
    'key' => env("SHOPIFY_APPNAME_APIKEY"),
    'secret' => env("SHOPIFY_APPNAME_SECRET"),
],

// $appName comes from url passed into method as param (look at middleware)
$shopifyAppConfig = config('shopify-auth.'.$appName);

/ call shopify api
$this->shopify
    ->setKey($shopifyAppConfig['key'])
    ->setSecret($shopifyAppConfig['secret'])
    ->setShopUrl($shopUrl)
    ->setAccessToken($accessToken)
    ->post('admin/script_tags.json', $scriptTags);

public function __construct(ShopifyApi $shopify, Request $request, ShopifyAuthService $shopifyAuthService)
{
     $this->shopify = $shopify;
     $this->shopifySession = $request->session()->get('shopifyapp');
     $this->shopifyAuthService = $shopifyAuthService;
 }

public function getDashboard()
{
    $shopUrl = $this->shopifySession['shop_url'];
    $appName = $this->shopifySession['app_name'];

    // find user, then get countdowns based on that
    $user = ShopifyUser::where([
        'shop_url' => $shopUrl,
        'app_name' => $appName,
    ])->first();

    $appConfig = config('shopify-auth.' . $appName);

    $this->checkExistsAndCreateScriptTag($shopUrl, $user->access_token, $user, $appName);

    return view('app_name.dashboard')->with([
        'app_key' => config($appConfig['key']),
    ]);
}