-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,465 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Actions; | ||
|
||
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery; | ||
use Osiset\ShopifyApp\Objects\Enums\ThemeSupportLevel; | ||
use Osiset\ShopifyApp\Objects\Values\ShopId; | ||
use Osiset\ShopifyApp\Services\ThemeHelper; | ||
|
||
/** | ||
* Activates a plan for a shop. | ||
*/ | ||
class VerifyThemeSupport | ||
{ | ||
/** | ||
* Querier for shops. | ||
* | ||
* @var IShopQuery | ||
*/ | ||
protected $shopQuery; | ||
|
||
/** | ||
* Theme helper. | ||
* | ||
* @var ThemeHelper | ||
*/ | ||
protected $themeHelper; | ||
|
||
/** | ||
* Setup. | ||
* | ||
* @param IShopQuery $shopQuery The querier for shops. | ||
* @param ThemeHelper $themeHelper Theme helper. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct( | ||
IShopQuery $shopQuery, | ||
ThemeHelper $themeHelper | ||
) { | ||
$this->shopQuery = $shopQuery; | ||
$this->themeHelper = $themeHelper; | ||
} | ||
|
||
/** | ||
* Execution. | ||
* | ||
* @param ShopId $shopId The shop ID. | ||
* | ||
* @return int | ||
*/ | ||
public function __invoke(ShopId $shopId): int | ||
{ | ||
$this->themeHelper->extractStoreMainTheme($shopId); | ||
|
||
if ($this->themeHelper->themeIsReady()) { | ||
$templateJSONFiles = $this->themeHelper->templateJSONFiles(); | ||
$templateMainSections = $this->themeHelper->mainSections($templateJSONFiles); | ||
$sectionsWithAppBlock = $this->themeHelper->sectionsWithAppBlock($templateMainSections); | ||
|
||
$hasTemplates = count($templateJSONFiles) > 0; | ||
$allTemplatesHasRightType = count($templateJSONFiles) === count($sectionsWithAppBlock); | ||
$templatesСountWithRightType = count($sectionsWithAppBlock); | ||
|
||
switch (true) { | ||
case $hasTemplates && $allTemplatesHasRightType: | ||
return ThemeSupportLevel::FULL; | ||
|
||
case $templatesСountWithRightType: | ||
return ThemeSupportLevel::PARTIAL; | ||
|
||
default: | ||
return ThemeSupportLevel::UNSUPPORTED; | ||
} | ||
} | ||
|
||
return ThemeSupportLevel::UNSUPPORTED; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Contracts\Objects\Values; | ||
|
||
use Funeralzone\ValueObjects\ValueObject; | ||
|
||
/** | ||
* Theme's ID value object. | ||
*/ | ||
interface ThemeId extends ValueObject | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Contracts\Objects\Values; | ||
|
||
use Funeralzone\ValueObjects\ValueObject; | ||
|
||
/** | ||
* Theme's name value object. | ||
*/ | ||
interface ThemeName extends ValueObject | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Contracts\Objects\Values; | ||
|
||
use Funeralzone\ValueObjects\ValueObject; | ||
|
||
/** | ||
* Theme's role value object. | ||
*/ | ||
interface ThemeRole extends ValueObject | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Contracts\Objects\Values; | ||
|
||
use Funeralzone\ValueObjects\ValueObject; | ||
|
||
/** | ||
* Access token value object. | ||
*/ | ||
interface ThemeSupportLevel extends ValueObject | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Objects\Enums; | ||
|
||
use Funeralzone\ValueObjects\Enums\EnumTrait; | ||
use Funeralzone\ValueObjects\ValueObject; | ||
|
||
/** | ||
* Online Store 2.0 theme support | ||
*/ | ||
class ThemeSupportLevel implements ValueObject | ||
{ | ||
use EnumTrait; | ||
|
||
/** | ||
* Support level: fully. | ||
* | ||
* @var int | ||
*/ | ||
public const FULL = 0; | ||
|
||
/** | ||
* Support level: partial. | ||
* | ||
* @var int | ||
*/ | ||
public const PARTIAL = 1; | ||
|
||
/** | ||
* Support level: unsupported. | ||
* | ||
* @var int | ||
*/ | ||
public const UNSUPPORTED = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Osiset\ShopifyApp\Objects\Values; | ||
|
||
use Funeralzone\ValueObjects\CompositeTrait; | ||
use Funeralzone\ValueObjects\ValueObject; | ||
use Illuminate\Support\Arr; | ||
use Osiset\ShopifyApp\Contracts\Objects\Values\ThemeId as ThemeIdValue; | ||
use Osiset\ShopifyApp\Contracts\Objects\Values\ThemeName as ThemeNameValue; | ||
use Osiset\ShopifyApp\Contracts\Objects\Values\ThemeRole as ThemeRoleValue; | ||
|
||
/** | ||
* Used to inject current session data into the user's model. | ||
* TODO: Possibly move this to a composite VO? | ||
*/ | ||
final class MainTheme implements ValueObject | ||
{ | ||
use CompositeTrait; | ||
|
||
/** | ||
* Theme id | ||
* | ||
* @var ThemeId | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Theme name | ||
* | ||
* @var ThemeName | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* Theme role | ||
* | ||
* @var ThemeRole | ||
*/ | ||
protected $role; | ||
|
||
/** | ||
* __construct | ||
* | ||
* @param ThemeIdValue $id | ||
* @param ThemeNameValue $name | ||
* @param ThemeRoleValue $role | ||
*/ | ||
public function __construct(ThemeIdValue $id, ThemeNameValue $name, ThemeRoleValue $role) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
$this->role = $role; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function fromNative($native) | ||
{ | ||
return new static( | ||
NullableThemeId::fromNative(Arr::get($native, 'id')), | ||
NullableThemeName::fromNative(Arr::get($native, 'name')), | ||
NullableThemeRole::fromNative(Arr::get($native, 'role')) | ||
); | ||
} | ||
|
||
/** | ||
* Get theme id | ||
* | ||
* @return ThemeId | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Get theme name | ||
* | ||
* @return ThemeName | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Get theme role | ||
* | ||
* @return ThemeRole | ||
*/ | ||
public function getRole() | ||
{ | ||
return $this->role; | ||
} | ||
} |
Oops, something went wrong.