Shopify section schema: different content for each present block - shopify

I'm just starting out with Shopify development, and I'm creating a custom section called USP Banner which has a single block type called column that can be added up to 4 times; and that column just has one text and one richtext field within it. The content of each column is identical on every page, but the section can appear in different places depending on the page itself.
I've given the column default values for the text & richtext and added the 4 columns that will be used into the presets definition of the schema; however because it's just the same column x 4, each column has the same content 4 times. What I'm aiming for is that when you add the section to any page, it prefills each column with different content.
I read through the Shopify docs and all I found was some vague allusion to having a settings object within the block presets, but I can't find any examples of that anywhere. I also found an old SO answer stating that presets can't contain default content.
Is there an easy way to add default content to repeating blocks within a section?

Although it's not made clear in the official docs, you can set default values for repeated blocks in the presets; but whereas the settings when defining the blocks are arrays of objects, the settings within the preset blocks are objects where each pre-determined field value uses the field's unique ID as its key. For example, a typical section schema might look like:
{% schema %}
{
"name": "USP Banner",
"blocks": [
{
"type": "column",
"name": "Column",
"limit": 4,
"settings": [
{
"type": "text",
"id": "heading",
"label": "Heading",
},
{
"type": "richtext",
"id": "text",
"label": "Text",
}
]
}
],
"presets": [
{
"name": "USP Banner",
"blocks": [
{
"type": "column"
},
{
"type": "column"
}
]
}
]
}
{% endschema %}
...so to create preset values for each block, we simply add settings to the preset definition like so:
"presets": [
{
"name": "USP Banner",
"blocks": [
{
"type": "column",
"settings": {
"heading": "Remarkable Value",
"text": "<p>Never knowingly undersold</p>"
}
},
{
"type": "column",
"settings": {
"heading": "5-Year Warranty",
"text": "<p>We're that confident in our products</p>"
}
}
]
}
]
...where the key for each field (heading & text in this case) is the ID of the defined fields in the blocks section at the top of the schema.

Related

Remove user selected item from the list in SAP conversational AI Chatbot

I am working on a chatbot project where I have to create a dynamic list option. There is a list of 15 Items (first step). When user selects one, selected item should be removed from the list. After that It will return to first step (list) and will display only 14 items. Where is the issue in step 3?
Step 1: I have created a "item_list" in the memory field of one skill.
[{"item": "product_1", "value": 5},{"item": "product_2", "value": 6},{"item": "product_3", "value": 4}]
Step 2: Choose custom list and enter the following script in the same skill.
{
"type": "list",
"delay": "",
"content": {
"elements": [
{{#eachJoin memory.item_list}}
{
"title": "{{this.item_list.item}}",
"subtitle": "{{this.item_list.value}}",
"imageUrl": "",
"status": "",
"statusState": "<''/none/information/error/success/warning>",
"description": "",
"buttons": [
{
"title": "{{this.item_list.item}}",
"value": "{{this.item_list.item}}",
"type": "postback"
}
]
}{{/eachJoin}}
]
}
}
Step 3: In another skill, set memory field where the user input is stored and set another memory "item_list" to match the user input within the array value to remove it from the item_list. For this, I have entered the following script. But there is some problem with that script. How can I remove the item from the array?
{{#inArray memory.item_list.title memory.user_input.raw}} "{{remove memory.item_list memory.user_input.raw}}" {{else}} "{{memory.lists}}"{{/inArray}}

Structures DB Schema Design

I am working on db schema for the below json. product has different parameterCategories and categories has different parameters. same parameter may belong to different categories. product can have 1 or more categories. product may have same categories with different parameters. let me know if my approach is correct. should I keep productCategory-section and section-parameters linking or simple table would work as I created below. all products of the same category will have same section and parameters so I am linking productCategory with parameters.
table Parameters
parameterid
parameterName
standard
value
parametersection
productCategory
{
"productCategory": "electronic",
"products": {
"productId": "productId",
"productName": "productName",
"productParameterSections": [
{
"productParameterSectionId": "appearance",
"parameters": [
{
"parameterId": "color",
"unit": "",
"standard": "red",
"val": "light red"
},
{
"parameterId": "brightness",
"unit": "",
"standard": "high",
"val": "medium"
}
]
},
{
"productParameterSectionId": "quantitative",
"parameters": [
{
"parameterId": "length",
"unit": "cm",
"standard": "440",
"val": "400"
},
{
"parameterId": "height",
"unit": "cm",
"standard": "red",
"val": "400"
}
]
}
]
}
}
Recently we work on the same schema design. What we did is as below:
Made a list of all the parameters possible and all the different fields in the parameters possible.
Then we created templates like here it is a category which is a combination of some of the parameters.
Then that template is assigned to any entity like product in this case.
Pros of this approach
- You can add as many parameters as you want in the list
- you can customize the template as you want and attach it to the entity
How to use it
Use parameters as a contact like an array of objects.
Create a template with an array of the selected parameters so that it is creating a copy of the selected parameter for every category to keep the constant array safe from updates.
The template is the second table which can have other fields like template name ( category name ) who created it when it is last updated even from which category it is created like a reference to own.
The final entity table ( product ) will have reference to that template table and also an array from that template. So reference provides information about parameters and you can update the copy with the values to use.
I hope it explains well, let me know if you still have any doubts.

radio with custom input in alpacajs with jsonschema?

I'm trying to create a field with several radio input options and an optional fill in the blank. The following schema doesn't seem to work in displaying output:
{
"oneOf": [
{
"enum": [
"Option 1",
"Option 2",
"Option 3"
]
}, {
"type":"string"
}
]
}
What should I be doing? Thanks!
Clarification: I'd like to output:
( ) option 1
( ) option 2
( ) option 3
(X) custom [__fill in the blank here__]
I'm sorry it was my mistake I accidently overrided that fiddle. Thank you for your clarification. If you want to have that layout in your page you must use two different components, a radio group buttons and a simple text field that automatically will be appended after the radio group (but you could do better using jquery and append it in a different place in the postRender function of Alpaca. So your schema must be like this :
"schema": {
"type": "object",
"properties": {
"oneOf": {
"required": true,
"enum": ['a', 'b', 'c', 'd']
},
"customResponse": {
"type": "string"
}
}
}
I added more options for the fields like disabling default sorting, disabling the input text for custom response because it must be enabled only when the user choose the 4th option.
Here's a more complete fiddle.
your schema properties should be enclosed into a properties object and if the "oneOf" refers to the group of radio buttons it should be an object not an array.
"properties": {
"oneOf": {
"required": true,
"enum": ["option1", "option2", "option3"]
}, ////
Here's a complete fiddle, hope it helps.
Tell me if you want something else.

What properties of an item should be included in the json schema?

I am confused about for which situation I am defining the properties in my json schemas.
Assume I have an item product for which I am trying to define a schema. In my database the products table has id, brand_id, name, item_number and description. All except description are required fields. The id is autogenerated by the database and the brand_id is set upon creation automatically by the api based on the user creating.
This means I can POST /api/products using only the following data:
{
"product": {
"name": "Product Name",
"item_number": "item001"
}
}
However, how should I now define the product schema? Should I include the properties id and brand_id? If so, should I label them as required, even though they are set automatically?
This is what I came up with:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://jsonschema.net/products",
"type": "object",
"properties": {
"item_number": {
"id": "http://jsonschema.net/products/item_number",
"type": "string"
},
"name": {
"id": "http://jsonschema.net/products/name",
"type": "string"
},
"description": {
"id": "http://jsonschema.net/products/description",
"type": "string",
"default": "null"
}
},
"required": [
"item_number",
"name"
]
}
You should only define in your JSON schema properties that are dealt with by the user of the API.
In your case, it makes no sense to have id and brand_id in the schema that defines the POST body entity for the creation of a new product because these values are not provided by the API user.
This said, you may have another schema for existing product entities where these two fields are present, if it's OK to expose them publicly.
If that's the case, for this you can use schema union mechanism and have the "existing product" schema use allOf new_product.json and add id and brand_id to it.

Turned off the dynamic mapping in Elasticsearch, but the custom mapping still not work?

my problem is: I have a JsonObject like this:
{
"success": true,
"type": "message",
"body": {
"_id": "5215bdd32de81e0c0f000005",
"id": "411c79eb-a725-4ad9-9d82-2db54dfc80ee",
"type": "metaModel",
"title": "testchang",
"authorId": "5215bd552de81e0c0f000001",
"drawElems": [
{
"type": "App.draw.metaElem.ModelStartPhase",
"id": "27re7e35-550j",
"x": 60,
"y": 50,
"width": 50,
"height": 50,
"title": "problem engagement",
"isGhost": true,
"pointTo": "e88e2845-37a4-4c45-a030-d02a3c3e03f9",
"bindingId": "90f79d70-0afc-11e3-98d2-83967d2ad9a6",
"model": "meta",
"entityType": "phase",
"domainId": "411c79eb-a725-4ad9-9d82-2db54dfc80ee",
"authorId": "5215bd552de81e0c0f000001",
"userData": {},
"_id": "5215f4c5d89f629c1700000d"
},
{...}
]
}
}
And I tried to define a mapping as follows to index only parts of this object.
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("domaindata").field("dynamic","false")
.startObject("properties")
.startObject("id").field("type","string").field("store","yes").endObject()
.startObject("type").field("type","string").field("store","yes").endObject()
.startObject("title").field("type","integer").field("store","yes").endObject()
.startObject("drawElems")
.startObject("properties")
.startObject("type").field("store","yes").field("type","string").endObject()
.startObject("title").field("store","yes").field("type","string").endObject()
.endObject().endObject().endObject().endObject().endObject().string();
after adding this mapping into my type with:
node.client().admin()
.indices().prepareCreate("test")
.addMapping("domaindata", mapping)
.execute().actionGet();
I still got all of the jsonobject in my indexresponse, it seems that my mapping does not work.
Could anybody help me? Thanks a lot!
The problem here is that using static mapping only means that fields that are not already present in the mapping won't be added to it, thus won't be indexed either. But as they are part of the source document that you sent, they are returned as part of the _source field.
Same goes if you disable a specific object in the mapping ("enable":false) as mentioned here. That object won't be parsed nor indexed, but will still be part of the stored _source field.
If you want to avoid storing part of the _source you can use the source includes/excludes feature as described here.