Skip to content

Commit b3d58ba

Browse files
authored
#305 | Try and catch the theme support and any error we keep the theme null (#312)
* Try and catch the theme support and any error we keep the theme null * linting * linting * linting
1 parent b3047a4 commit b3d58ba

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/Actions/InstallShop.php

+16-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Osiset\ShopifyApp\Contracts\Commands\Shop as IShopCommand;
77
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
88
use Osiset\ShopifyApp\Objects\Enums\AuthMode;
9+
use Osiset\ShopifyApp\Objects\Enums\ThemeSupportLevel as ThemeSupportLevelEnum;
910
use Osiset\ShopifyApp\Objects\Values\AccessToken;
1011
use Osiset\ShopifyApp\Objects\Values\NullAccessToken;
1112
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
@@ -41,14 +42,14 @@ class InstallShop
4142
/**
4243
* Setup.
4344
*
44-
* @param IShopQuery $shopQuery The querier for the shop.
45-
* @param VerifyThemeSupport $verifyThemeSupport The action for verify theme support
45+
* @param IShopQuery $shopQuery The querier for the shop.
46+
* @param VerifyThemeSupport $verifyThemeSupport The action for verify theme support
4647
*
4748
* @return void
4849
*/
4950
public function __construct(
50-
IShopQuery $shopQuery,
51-
IShopCommand $shopCommand,
51+
IShopQuery $shopQuery,
52+
IShopCommand $shopCommand,
5253
VerifyThemeSupport $verifyThemeSupport
5354
) {
5455
$this->shopQuery = $shopQuery;
@@ -59,8 +60,8 @@ public function __construct(
5960
/**
6061
* Execution.
6162
*
62-
* @param ShopDomain $shopDomain The shop ID.
63-
* @param string|null $code The code from Shopify.
63+
* @param ShopDomain $shopDomain The shop ID.
64+
* @param string|null $code The code from Shopify.
6465
*
6566
* @return array
6667
*/
@@ -100,8 +101,15 @@ public function __invoke(ShopDomain $shopDomain, ?string $code): array
100101
$data = $apiHelper->getAccessData($code);
101102
$this->shopCommand->setAccessToken($shop->getId(), AccessToken::fromNative($data['access_token']));
102103

103-
$themeSupportLevel = call_user_func($this->verifyThemeSupport, $shop->getId());
104-
$this->shopCommand->setThemeSupportLevel($shop->getId(), ThemeSupportLevel::fromNative($themeSupportLevel));
104+
// Try to get the theme support level, if not, return the default setting
105+
try {
106+
$themeSupportLevel = call_user_func($this->verifyThemeSupport, $shop->getId());
107+
$this->shopCommand->setThemeSupportLevel($shop->getId(), ThemeSupportLevel::fromNative($themeSupportLevel));
108+
} catch (Exception $e) {
109+
// Just return the default setting which is null
110+
$themeSupportLevel = ThemeSupportLevelEnum::NONE;
111+
}
112+
105113

106114
return [
107115
'completed' => true,

src/Objects/Enums/ThemeSupportLevel.php

+7
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ class ThemeSupportLevel implements ValueObject
3232
* @var int
3333
*/
3434
public const UNSUPPORTED = 2;
35+
36+
/**
37+
* Support level: None.
38+
*
39+
* @var null
40+
*/
41+
public const NONE = null;
3542
}

0 commit comments

Comments
 (0)