How to map a custom field to https://schema.org/QuantitativeValue

Created on 27 May 2024, 6 months ago
Updated 11 August 2024, 3 months ago

I create a https://schema.org/Product content type, add a custom_field to map to https://schema.org/hasMeasurement against https://schema.org/QuantitativeValue.

Following by the instruction, I go to the page /admin/config/schemadotorg/settings/properties#edit-schemadotorg-custom-field, and append the following YAML:

Product--mainEntity:
  type: QuantitativeValue
  properties:
    name: string
    value: string

However, the output JSON+LD still be:

<script type="application/ld+json">
{"@context":"https://schema.org","@type":"Product","@url":"https://mycompany.com/test-product","name":"test product","description":"\u003Cp\u003Etest product\u003C/p\u003E\u003Cp\u003Etest product\u003C/p\u003E","hasMeasurement":{"@type":"QuantitativeValue","value":null}}
</script>

This is the screenshot of my custom_field settings:

πŸ’¬ Support request
Status

Needs work

Version

1.0

Component

Documentation

Created by

πŸ‡¨πŸ‡³China fishfree

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fishfree
  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡Έ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:

    1. Why the value has nested key-values of @type and name? I think it unreasonable, esp. I mapped it to integer type.
    2. 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 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    The double nesting is wrong.

  • πŸ‡¨πŸ‡³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?

Production build 0.71.5 2024