- Issue created by @fishfree
- Status changed to Needs review
7 months ago 6:45pm 28 May 2024 - πΊπΈUnited States jrockowitz Brooklyn, NY
If you are targeting the https://schema.org/hasMeasurement the custom field settings has to be
# SchemaType--schemaProperty Product--hasMeasurement: type: QuantitativeValue properties: name: string value: string
- π¨π³China fishfree
@jrockowitz Thank you very much! Now the generated JSON+LD has but only has the last value of "weight", no "length", as below:
{ "@context": "https://schema.org", "@type": "Product", "@url": "https://mycompany.com/test-product-0", "name": "test product", "hasMeasurement": { "@type": "QuantitativeValue", "weight": "23423" } }
Is it a little buggy?
- πΊπΈUnited States jrockowitz Brooklyn, NY
It is a little incomplete. We will need to think about adding default values and more configuration options for custom fields.
- πΊπΈUnited States jrockowitz Brooklyn, NY
The latest dev release includes a bunch of improvements.
Please look at the the MR to see how to start improving https://schema.org/Product support.
Below is example of how I would set hasMeasurement using a custom field.
Note: for weight, I would use https://schema.org/weight
hasMeasurement: schema_type: QuantitativeValue schema_properties: value: data_type: integer minValue: data_type: integer maxValue: data_type: integer unitCode: data_type: string unitText: data_type: text
- π¨π³China fishfree
@jrockowitz Thank you very much! Now I upgraded to the latest dev version and updated the database, deleted the old config on page /admin/config/schemadotorg/settings/properties#edit-schemadotorg-custom-field and appended you-provided new yaml strings, created a new Product node, now the output JSON+LD still has only the last value "weight" as below:
{ "@context": "https://schema.org", "@type": "Product", "@url": "https://mycompany.com/test-3", "name": "test 3", "hasMeasurement": { "@type": "QuantitativeValue", "weight": { "@type": "QuantitativeValue", "value": "234" } } }
- πΊπΈUnited States jrockowitz Brooklyn, NY
You would need to checkout the MR, copy all config, and delete and recreate the field to see the updates.
- π¨π³China fishfree
@jrokowitz Thank you! I did as your tip. Add in the custom field hasMeasurement I add a new sub-field "name" of type text, which is also correspondent to the schema.org QuatitativeValue text.
Add also add the YAML on page /admin/config/schemadotorg/settings/properties#edit-schemadotorg-custom-field as below:hasMeasurement: schema_type: QuantitativeValue schema_properties: name: data_type: string value: data_type: integer minValue: data_type: integer maxValue: data_type: integer unitCode: data_type: string unitText: data_type: string
Now the output JSON+LD is as below:
{ "@context": "https://schema.org", "@type": "Product", "@url": "https://mycompany.com/test-product-3", "name": "test product 3", "hasMeasurement": [ { "@type": "QuantitativeValue", "value": { "@type": "Text", "name": "20" }, "unitCode": "CM", "unitText": "centimeters", "name": "Length" }, { "@type": "QuantitativeValue", "value": { "@type": "Text", "name": "28" }, "unitCode": "KG", "unitText": "kilograms", "name": "Weight" } ] }
The questions are:
- Why the value has nested key-values of @type and name? I think it unreasonable, esp. I mapped it to integer type.
- Shouldn't the name, value, unitCode and unitText are all properties of QuantitativeValue? I doubt the nesting hierarchy of the JSON is wrong.
- Status changed to Needs work
7 months ago 1:15am 4 June 2024 - π¨π³China fishfree
@jrockowitz Sorry to interrupt you. Did this issue fixed?
BTW: I post an issue here. If the official Schema.org would not adopt this suggestion, how can I make it in https://www.drupal.org/project/schemadotorg β , pls?