Skip to content

Commit 806a60b

Browse files
authored
Merge pull request #18 from magefan/6821-pwa-blog-integration
Add PWA studio 12 compatibility
2 parents 5bb754e + 3d2630a commit 806a60b

File tree

14 files changed

+286
-13
lines changed

14 files changed

+286
-13
lines changed

Model/BlogArchiveTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare (strict_types = 1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogArchiveTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_ARCHIVE = 'MF_BLOG_ARCHIVE';
19+
const TYPE_RESOLVER = 'blogPostsOutput';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_ARCHIVE) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/BlogAuthorTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare (strict_types = 1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogAuthorTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_AUTHOR = 'MF_BLOG_AUTHOR';
19+
const TYPE_RESOLVER = 'BlogAuthor';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_AUTHOR) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/BlogCategoryTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogCategoryTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_CATEGORY = 'MF_BLOG_CATEGORY';
19+
const TYPE_RESOLVER = 'BlogCategory';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_CATEGORY) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/BlogIndexTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogIndexTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_INDEX = 'MF_BLOG_INDEX';
19+
const TYPE_RESOLVER = 'blogPostsOutput';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_INDEX) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/BlogPostTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogPostTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_POST = 'MF_BLOG_POST';
19+
const TYPE_RESOLVER = 'BlogPost';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_POST) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/BlogSearchTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare (strict_types = 1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogSearchTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_SEARCH = 'MF_BLOG_SEARCH';
19+
const TYPE_RESOLVER = 'blogPostsOutput';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_SEARCH) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/BlogTagTypeResolver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare (strict_types = 1);
8+
9+
namespace Magefan\BlogGraphQl\Model;
10+
11+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class BlogTagTypeResolver implements TypeResolverInterface
17+
{
18+
const MF_BLOG_TAG = 'MF_BLOG_TAG';
19+
const TYPE_RESOLVER = 'BlogTag';
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function resolveType(array $data) : string
25+
{
26+
if (isset($data['type_id']) && $data['type_id'] == self::MF_BLOG_TAG) {
27+
return self::TYPE_RESOLVER;
28+
}
29+
return '';
30+
}
31+
}

Model/Resolver/DataProvider/Category.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public function getDynamicData($category, $fields = null)
152152

153153
$breadcrumbs[] = [
154154
'category_id' => $categoryData->getId(),
155+
'category_uid' => $categoryData->getId(),
155156
'category_name' => $categoryData->getTitle(),
156157
'category_level' => $categoryData->getLevel(),
157158
'category_url_key' => $categoryData->getIdentifier(),
@@ -162,6 +163,7 @@ public function getDynamicData($category, $fields = null)
162163
$categoryData = $category;
163164
$breadcrumbs[] = [
164165
'category_id' => $categoryData->getId(),
166+
'category_uid' => $categoryData->getId(),
165167
'category_name' => $categoryData->getTitle(),
166168
'category_level' => $categoryData->getLevel(),
167169
'category_url_key' => $categoryData->getIdentifier(),

Model/Resolver/DataProvider/Post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function __construct(
109109
* @return array
110110
* @throws NoSuchEntityException
111111
*/
112-
public function getData(string $postId, $fields = null): array
112+
public function getData(string $postId, $fields = null, $storeId = null): array
113113
{
114114
$post = $this->postRepository->getFactory()->create();
115115
$post->getResource()->load($post, $postId);
@@ -121,14 +121,14 @@ public function getData(string $postId, $fields = null): array
121121
$data = [];
122122
$this->state->emulateAreaCode(
123123
Area::AREA_FRONTEND,
124-
function () use ($post, $fields, &$data) {
124+
function () use ($post, $fields, &$data, $storeId) {
125125
$themeId = $this->scopeConfig->getValue(
126126
'design/theme/theme_id',
127127
ScopeInterface::SCOPE_STORE
128128
);
129129
$theme = $this->themeProvider->getThemeById($themeId);
130130
$this->design->setDesignTheme($theme, Area::AREA_FRONTEND);
131-
131+
$post->setStoreId($storeId);
132132
$data = $this->getDynamicData($post, $fields);
133133

134134
return $data;

Model/Resolver/Post.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public function resolve(
4444
array $value = null,
4545
array $args = null
4646
) {
47+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
4748
$postId = $this->getPostId($args);
4849
$fields = $info ? $info->getFieldSelection(10) : null;
4950

5051
try {
51-
$postData = $this->postDataProvider->getData($postId, $fields);
52+
$postData = $this->postDataProvider->getData($postId, $fields, $storeId);
5253
} catch (NoSuchEntityException $e) {
5354
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
5455
}

0 commit comments

Comments
 (0)