1. Go to this page and download the library: Download cashdash-pro/zaar 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/ */
use CashDash\Zaar\Facades\Zaar;
Zaar::setShopifyDomain(function (Request $request, User $user, ?string $current_domain) {
// For external apps (outside Shopify Admin), you MUST return the shop domain
if (!Zaar::isEmbedded()) {
return $request->header('X-Shopify-Shop-Domain');
// or from query params: return $request->get('shop');
// or from route parameters: return $request->route('shop');
}
// For embedded apps, you can override the domain to switch stores
// The $user parameter lets you check permissions
if ($user->can('access', $otherStore)) {
return 'other-store.myshopify.com';
}
// Return null to use the domain from the session token
return null;
});
Route::middleware('shopify.web')->group(function () {
Route::get('/app', function () {
// Your embedded app's main entry point
});
});
Route::middleware('shopify.public')->group(function () {
Route::get('/public/products', function () {
// Public endpoint logic
});
});
// Get current session
$session = Zaar::session();
$accessToken = $session->accessToken;
$shop = $session->shop;
// Check session type
if (Zaar::sessionType() === SessionType::ONLINE) {
// Online session logic
}
// Start session for different store
Zaar::startSessionManually($newShop, $user);
// Handle expired sessions
if (!Zaar::sessionStarted()) {
Zaar::clearExpiredSessionsAndReauthenticate($domain);
}