Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#305 | Try and catch the theme support and any error we keep the theme null #312

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Actions/InstallShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Osiset\ShopifyApp\Contracts\Commands\Shop as IShopCommand;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Objects\Enums\AuthMode;
use Osiset\ShopifyApp\Objects\Enums\ThemeSupportLevel as ThemeSupportLevelEnum;
use Osiset\ShopifyApp\Objects\Values\AccessToken;
use Osiset\ShopifyApp\Objects\Values\NullAccessToken;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
Expand Down Expand Up @@ -41,14 +42,14 @@ class InstallShop
/**
* Setup.
*
* @param IShopQuery $shopQuery The querier for the shop.
* @param VerifyThemeSupport $verifyThemeSupport The action for verify theme support
* @param IShopQuery $shopQuery The querier for the shop.
* @param VerifyThemeSupport $verifyThemeSupport The action for verify theme support
*
* @return void
*/
public function __construct(
IShopQuery $shopQuery,
IShopCommand $shopCommand,
IShopQuery $shopQuery,
IShopCommand $shopCommand,
VerifyThemeSupport $verifyThemeSupport
) {
$this->shopQuery = $shopQuery;
Expand All @@ -59,8 +60,8 @@ public function __construct(
/**
* Execution.
*
* @param ShopDomain $shopDomain The shop ID.
* @param string|null $code The code from Shopify.
* @param ShopDomain $shopDomain The shop ID.
* @param string|null $code The code from Shopify.
*
* @return array
*/
Expand Down Expand Up @@ -100,8 +101,15 @@ public function __invoke(ShopDomain $shopDomain, ?string $code): array
$data = $apiHelper->getAccessData($code);
$this->shopCommand->setAccessToken($shop->getId(), AccessToken::fromNative($data['access_token']));

$themeSupportLevel = call_user_func($this->verifyThemeSupport, $shop->getId());
$this->shopCommand->setThemeSupportLevel($shop->getId(), ThemeSupportLevel::fromNative($themeSupportLevel));
// Try to get the theme support level, if not, return the default setting
try {
$themeSupportLevel = call_user_func($this->verifyThemeSupport, $shop->getId());
$this->shopCommand->setThemeSupportLevel($shop->getId(), ThemeSupportLevel::fromNative($themeSupportLevel));
} catch (Exception $e) {
// Just return the default setting which is null
$themeSupportLevel = ThemeSupportLevelEnum::NONE;
}


return [
'completed' => true,
Expand Down
7 changes: 7 additions & 0 deletions src/Objects/Enums/ThemeSupportLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ class ThemeSupportLevel implements ValueObject
* @var int
*/
public const UNSUPPORTED = 2;

/**
* Support level: None.
*
* @var null
*/
public const NONE = null;
}
Loading