Skip to content

Commit ce16356

Browse files
authored
Merge pull request #1 from landofcoder/update-schema
Update schema
2 parents 9d60dba + 60c43f2 commit ce16356

File tree

5 files changed

+146
-32
lines changed

5 files changed

+146
-32
lines changed

Model/Resolver/DataProvider/Megamenu.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,40 @@
77

88
namespace Lof\MegamenuGraphQl\Model\Resolver\DataProvider;
99

10-
use Ves\Megamenu\Api\MenuRepositoryInterface;
10+
use Ves\Megamenu\Api\GetMenuByAliasInterface;
1111
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1313

1414
class Megamenu
1515
{
16-
16+
/**
17+
* @var GetMenuByAliasInterface
18+
*/
1719
private $repository;
1820

1921
/**
20-
* @param MenuRepositoryInterface $repository
22+
* @param GetMenuByAliasInterface $repository
2123
*/
2224
public function __construct(
23-
MenuRepositoryInterface $repository
25+
GetMenuByAliasInterface $repository
2426
) {
2527
$this->repository = $repository;
2628
}
2729

2830
/**
29-
* get megamenu by id
30-
* @param int $id
31-
* @param int|null $storeId
32-
* @return \Ves\Megamenu\Api\Data\MenuInterface
31+
* get megamenu by alias
32+
* @param string $alias
33+
* @param string|int|null $storeId = null
34+
* @param int $customerGroupId = 0
35+
* @param bool $isMobile = false
36+
* @return \Ves\Megamenu\Api\Data\MenuFrontendInterface
3337
* @throws \Magento\Framework\Exception\LocalizedException
3438
*/
35-
public function getMegamenu($id, $storeId = null)
39+
public function getMegamenu($alias, $storeId = null, $customerGroupId = 0, $isMobile = false)
3640
{
37-
$megamenu = $this->repository->getByAlias($id, $storeId);
41+
$megamenu = $this->repository->execute($alias, $storeId, $customerGroupId, $isMobile);
3842
if (!$megamenu) {
39-
throw new GraphQlInputException(__('Megamenu Id does not match any records.'));
43+
throw new GraphQlInputException(__('Megamenu with alias %! is not exists.', $alias));
4044
}
4145
return $megamenu;
4246
}

Model/Resolver/Megamenu.php

+24-6
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,32 @@
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
17+
use Magento\Customer\Api\Data\CustomerInterface;
1618

1719
class Megamenu implements ResolverInterface
1820
{
1921

22+
/**
23+
* @var DataProvider\Megamenu
24+
*/
2025
private $dataProvider;
2126

27+
/**
28+
* @var GetCustomer
29+
*/
30+
private $getCustomer;
31+
2232
/**
2333
* @param DataProvider\Megamenu $dataProvider
34+
* @param GetCustomer $getCustomer
2435
*/
2536
public function __construct(
26-
DataProvider\Megamenu $dataProvider
37+
DataProvider\Megamenu $dataProvider,
38+
GetCustomer $getCustomer
2739
) {
2840
$this->dataProvider = $dataProvider;
41+
$this->getCustomer = $getCustomer;
2942
}
3043

3144
/**
@@ -39,10 +52,15 @@ public function resolve(
3952
array $args = null
4053
) {
4154
$this->validateArgs($args);
42-
$alias = $args["alias"];
43-
$storeId = isset($args["storeId"])?$args["storeId"]:null;
44-
$megamenuData = $this->dataProvider->getMegamenu($alias, $storeId);
45-
return $megamenuData;
55+
$store = $context->getExtensionAttributes()->getStore();
56+
$customerGroupId = 0;
57+
if ($context->getExtensionAttributes()->getIsCustomer()) {
58+
/** @var CustomerInterface */
59+
$customer = $this->getCustomer->execute($context);
60+
$customerGroupId = $customer->getGroupId();
61+
}
62+
$isMobile = isset($args["isMobile"]) && $args["isMobile"] ? true: false;
63+
return $this->dataProvider->getMegamenu($args["alias"], $store->getCode(), $customerGroupId, $isMobile);
4664
}
4765

4866
/**
@@ -52,7 +70,7 @@ public function resolve(
5270
*/
5371
public function validateArgs($args)
5472
{
55-
if (!isset($args['alias']) || (isset($args['alias']) && !$args['alias'])) {
73+
if (!isset($args['alias']) || (isset($args['alias']) && empty($args['alias']))) {
5674
throw new GraphQlInputException(__('Required parameter "alias" is missing'));
5775
}
5876
}

README.md

+92
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,95 @@ magento 2 megamenu graphql extension
3535
- enable the module by running `php bin/magento module:enable Lof_MegamenuGraphQl`
3636
- apply database updates by running `php bin/magento setup:upgrade`\*
3737
- Flush the cache by running `php bin/magento cache:flush`
38+
39+
### Query
40+
41+
1. Get menu profile with menu alias
42+
43+
Flagment:
44+
45+
```
46+
fragment MenuNode on MegamenuItemNode {
47+
name
48+
show_name
49+
classes
50+
child_col
51+
sub_width
52+
align
53+
icon_position
54+
icon_classes
55+
is_group
56+
status
57+
disable_bellow
58+
show_icon
59+
icon
60+
show_header
61+
header_html
62+
show_left_sidebar
63+
left_sidebar_width
64+
menu_id
65+
left_sidebar_html
66+
show_content
67+
content_width
68+
content_type
69+
link_type
70+
link
71+
category
72+
target
73+
cotnent_html
74+
show_right_sidebar
75+
right_sidebar_width
76+
right_sidebar_html
77+
show_footer
78+
footer_html
79+
color
80+
hover_color
81+
bg_color
82+
bg_hover_color
83+
inline_css
84+
tab_position
85+
before_html
86+
after_html
87+
caret
88+
hover_caret
89+
sub_height
90+
hover_icon
91+
dropdown_bgcolor
92+
dropdown_bgimage
93+
dropdown_bgimagerepeat
94+
dropdown_bgpositionx
95+
dropdown_bgpositiony
96+
dropdown_inlinecss
97+
parentcat
98+
animation_in
99+
animation_time
100+
child_col_type
101+
submenu_sorttype
102+
isgroup_level
103+
}
104+
```
105+
106+
Query (get 3 levels of menu item node) for menu profile alias ``top-menu``:
107+
108+
```
109+
{
110+
megamenu (alias: "top-menu") {
111+
name
112+
alias
113+
disable_bellow
114+
event
115+
classes
116+
width
117+
disable_iblocks
118+
nodes {
119+
...MenuNode
120+
child_nodes {
121+
...MenuNode
122+
child_nodes {
123+
...MenuNode
124+
}
125+
}
126+
}
127+
}
128+
}
129+
```

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"minimum-stability": "dev",
14-
"version": "1.0.0",
14+
"version": "1.0.1",
1515
"require": {
1616
},
1717
"autoload": {

etc/schema.graphqls

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type Query {
22
megamenu (
3-
alias: String! @doc(description: "Query by menu alias."),
4-
storeId: String @doc(description: "Query by storeId.")
3+
alias: String! = "top-menu" @doc(description: "Query by menu alias. Default menu profile alias = top-menu")
4+
isMobile: Int = 0 @doc(description: "Query mobile menu profile if exists. Default value = 0")
55
) : Megamenu @resolver( class: "Lof\\MegamenuGraphQl\\Model\\Resolver\\Megamenu") @doc(description: "Query by Get megamenu by ID.") @cache( cacheIdentity: "Lof\\MegamenuGraphQl\\Model\\Resolver\\Megamenu\\Identity")
66
megamenus (
77
filters: MegamenuFilterInput @doc(description: "Identifies which brand filter inputs to search for and return.")
@@ -31,14 +31,14 @@ input MegamenuSortInput @doc(description: "MegamenuSortInput specifies the attri
3131
}
3232

3333
type Megamenu {
34-
menu_id : String @doc(description: "Query by menu_id.")
35-
name : String @doc(description: "Query by name.")
36-
alias : String @doc(description: "Query by alias.")
37-
disable_bellow : Int @doc(description: "Query by disable_bellow.")
38-
status : Int @doc(description: "Query by status.")
39-
design : String @doc(description: "Query by design.")
40-
event : String @doc(description: "Query by event.")
41-
classes : String @doc(description: "Query by classes.")
34+
menu_id : String @doc(description: "Query by menu_id.")
35+
name : String @doc(description: "Query by name.")
36+
alias : String @doc(description: "Query by alias.")
37+
disable_bellow : Int @doc(description: "Query by disable_bellow.")
38+
status : Int @doc(description: "Query by status.")
39+
design : String @doc(description: "Query by design.")
40+
event : String @doc(description: "Query by event.")
41+
classes : String @doc(description: "Query by classes.")
4242
width : String @doc(description: "Query by width.")
4343
html : String @doc(description: "Query by html.")
4444
params : String @doc(description: "Query by params.")
@@ -50,10 +50,10 @@ type Megamenu {
5050
disable_iblocks : Int @doc(description: "Query by disable_iblocks.")
5151
customer_groups: [Int] @doc(description: "Query by customer groups.")
5252
stores: [Int] @doc(description: "Query by stores.")
53-
menu_items: [MegamenuItem] @doc(description: "Query by MegamenuItem.")
53+
nodes: [MegamenuItemNode] @doc(description: "Query by MegamenuItemNode.")
5454
}
5555

56-
type MegamenuItem {
56+
type MegamenuItemNode {
5757
id: Int
5858
item_id: String
5959
name: String
@@ -112,7 +112,7 @@ type MegamenuItem {
112112
child_col_type: String
113113
submenu_sorttype: String
114114
isgroup_level: String
115-
menu_items: [MegamenuItem] @doc(description: "Query by MegamenuItem.")
115+
child_nodes: [MegamenuItemNode] @doc(description: "Query by MegamenuItemNode.")
116116
}
117117

118118
type Megamenus @doc(description: "The megamenus object is the top-level object returned in a slider search.") {
@@ -129,4 +129,4 @@ type SortField {
129129
type SortFields @doc(description: "SortFields contains a default value for sort fields and all available sort fields.") {
130130
default: String @doc(description: "Default value of sort fields.")
131131
options: [SortField] @doc(description: "Available sort fields.")
132-
}
132+
}

0 commit comments

Comments
 (0)