Skip to content

Commit

Permalink
#305 | Try and catch the theme support and any error we keep the them…
Browse files Browse the repository at this point in the history
…e null (#312)

* Try and catch the theme support and any error we keep the theme null

* linting

* linting

* linting
  • Loading branch information
Kyon147 authored May 16, 2024
1 parent b3047a4 commit b3d58ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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;
}

0 comments on commit b3d58ba

Please sign in to comment.