Skip to content

Commit 211e8ab

Browse files
authored
Merge pull request #451 from magento-honey-badgers/dynamic-blocks
GraphQL schema for dynamic blocks
2 parents 20f51ca + b3e9d8e commit 211e8ab

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
type DynamicBlock {
2+
uid: ID!
3+
content: ComplexTextValue!
4+
}
5+
6+
# We don't need name, is_enabled, locations, ga_creative, catalog_price_rule_ids, cart_price_rules_ids, locations on storefront
7+
8+
type DynamicBlocks {
9+
items: [DynamicBlock]!
10+
page_info: SearchResultPageInfo
11+
total_count: Int!
12+
}
13+
14+
type DynamicBlocksFilterInput {
15+
type: DynamicBlockTypeEnum!
16+
locations: [DynamicBlockLocationEnum!] # Blocks for all locations will be displayed if not supplied
17+
rotation_mode: DynamicBlockRotationModeEnum!
18+
dynamic_block_uids: [ID!] # Only makes sense when DynamicBlockTypeEnum is set to SPECIFIED
19+
}
20+
21+
type DynamicBlocksOutput {
22+
dynamic_blocks: DynamicBlocks!
23+
}
24+
25+
enum DynamicBlockTypeEnum {
26+
SPECIFIED
27+
CART_PRICE_RULE_RELATED
28+
CATALOG_PRICE_RULE_RELATED
29+
}
30+
31+
enum DynamicBlockLocationEnum {
32+
CONTENT
33+
HEADER
34+
FOOTER
35+
LEFT
36+
RIGHT
37+
}
38+
39+
enum DynamicBlockRotationModeEnum {
40+
NO_ROTATION @doc(description: "Display all.")
41+
RANDOM
42+
SERIES
43+
SHUFFLE
44+
}
45+
46+
type Query {
47+
dynamic_blocks(input: DynamicBlocksFilterInput): DynamicBlocksOutput
48+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Dynamic Blocks
2+
3+
Dynamic blocks can be inserted in CMS pages and blocks using widgets. Below is the sample markup of the widget inserted on the page.
4+
5+
```
6+
{{widget type="Magento\Banner\Block\Widget\Banner" display_mode="fixed" types="content" rotate="random" banner_ids="1" template="widget/block.phtml" unique_id="34f6520f51ca9b79c91d1f56b5b453adc4d9ff235a7c9f5b04d1b0557584c5bc"}}
7+
```
8+
9+
In Luma dynamic blocks rendered to a JavaScript component definition that does request to a backend to load content of the dynamic block. Here is an example of a JavaScript component definition.
10+
11+
```
12+
<div class="widget block block-banners" data-bind="scope: 'banner'" data-banner-id="34f6520f51ca9b79c91d1f56b5b453adc4d9ff235a7c9f5b04d1b0557584c5bc" data-types="content" data-display-mode="fixed" data-ids="1" data-rotate="random" data-store-id="1">
13+
<ul class="banner-items" data-bind="afterRender: registerBanner">
14+
<!-- ko foreach: getItems34f6520f51ca9b79c91d1f56b5b453adc4d9ff235a7c9f5b04d1b0557584c5bc() -->
15+
<li class="banner-item" data-bind="attr: {'data-banner-id': $data.bannerId}">
16+
<div class="banner-item-content" data-bind="bindHtml: $data.html"></div>
17+
</li>
18+
<!-- /ko -->
19+
</ul>
20+
</div>
21+
```
22+
23+
PWA will receive similar JavaScript component definition that can be parsed to extract parameters and make a [GraphQL query](./dynamic-blocks.graphqls) to load dynamic blocks.
24+
25+
```graphql
26+
{
27+
dynamic_blocks(input: {type: SPECIFIED, locations: [CONTENT], rotation_mode: RANDOM, dynamic_block_uids: [1, 2]}) {
28+
items {
29+
uid
30+
content {
31+
html
32+
}
33+
}
34+
page_info {
35+
current_page
36+
page_size
37+
total_pages
38+
}
39+
total_count
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)