Re: Allowing add-ons

Disclaimer: there is still a glitch, see below for a possible solution.

Am 22.02.2015 um 14:19 schrieb Dietrich Schulten:
> Hi,
> 
> Am 21.02.2015 um 16:18 schrieb Dietrich Schulten:
> 
> {
>   "@context": {
>     "@vocab": "http://schema.org/",
>     "hydra": "http://www.w3.org/ns/hydra/core#",
>     "hydra:property": {"@type": "@vocab"}
>   },
>   "@type": "Order",
>   "@id": "http://example.com/orders/1234",
>   "orderedItem": [
>     {
>       "@type": "Product",
>       "name": "Latte Macchiato",
>       "@id": "http://example.com/orders/1234/items/1",
>       "offers": {
>         "@type": "Offer",
>         "addOn": [
>           {
>             "@type": "Offer",
>             "itemOffered": {
>               "@type": "Product",
>               "@id": "http://example.com/orders/1234/items/1/addOns",
>               "name": "shot",
>               "hydra:operation": {
>                 "hydra:httpMethod": "POST",
>                 "@type": "OrderAction",
>                 "hydra:expects": {
>                   "@type": "Product",
>                   "hydra:supportedProperty": [
>                     {
>                       "hydra:property": "name",
>                       "hydra:required": true,
>                       "defaultValue": "shot",
>                       "readOnlyValue": true
>                     }
>                   ]
>                 }
>               }
>             },
>             "price": 0.2,
>             "priceCurrency": "EUR"
>           },
>           {
>             "@type": "Offer",
>             "itemOffered": {
>               "@type": "Product",
>               "@id": "http://example.com/orders/1234/items/1/addOns",
>               "name": "Brioche con crema",
>               "description": "Breakfast special",
>               "hydra:operation": [
>                 {
>                   "hydra:httpMethod": "POST",
>                   "@type": "OrderAction",
>                   "hydra:expects": {
>                     "@type": "Product",
>                     "hydra:supportedProperty": [
>                       {
>                         "hydra:property": "name",
>                         "hydra:required": true,
>                         "defaultValue": "Brioche con crema",
>                         "readOnlyValue": true
>                       }
>                     ]
>                   }
>                 }
>               ]
>             },
>             "price": 1.00,
>             "priceCurrency": "EUR"
>           }
>         ]
>       }
>     }
>   ]
> }
> 

Both products at the itemOffered properties share the same @id, namely
/orders/1234/items/1/addOns.

GET /orders/1234/items/1/addOns would have to return a collection of
extras which have been added to the Latte Macchiato.

So the URI /orders/1234/items/1/addOns cannot be the @id of an itemOffered.

This shows a general design constraint: hydra:operation can only target
a http method on the @id of the surrounding subject.

A possible solution is to use hydra:collection as indirection. Now the
URI to POST to is the collection URI and the product on offer could have
its own URI.

{
  "@context": {
    "@vocab": "http://schema.org/",
    "hydra": "http://www.w3.org/ns/hydra/core#",
    "hydra:property": {"@type": "@vocab"}
  },
  "@type": "Order",
  "@id": "http://example.com/orders/1234",
  "orderedItem": [
    {
      "@type": "Product",
      "name": "Latte Macchiato",
      "@id": "http://example.com/orders/1234/items/1",
      "offers": {
        "@type": "Offer",
        "addOn": [
          {
            "@type": "Offer",
            "itemOffered": {
              "@type": "Product",
              "name": "shot",
              "hydra:collection" : {
                "@id": "http://example.com/orders/1234/items/1/addOns",
                "hydra:operation": {
                  "hydra:httpMethod": "POST",
                  "@type": "OrderAction",
                  "hydra:expects": {
                    "@type": "Product",
                    "hydra:supportedProperty": [
                      {
                        "hydra:property": "name",
                        "hydra:required": true,
                        "defaultValue": "shot",
                        "readOnlyValue": true
                      }
                    ]
                  }
                }
              }
            },
            "price": 0.2,
            "priceCurrency": "EUR"
          },
          {
            "@type": "Offer",
            "itemOffered": {
              "@type": "Product",
              "name": "Brioche con crema",
              "description": "Breakfast special",
              "hydra:collection" : {
                "@id": "http://example.com/orders/1234/items/1/addOns",
                "hydra:operation": {
                    "hydra:httpMethod": "POST",
                    "@type": "OrderAction",
                    "hydra:expects": {
                      "@type": "Product",
                      "hydra:supportedProperty": [
                        {
                          "hydra:property": "name",
                          "hydra:required": true,
                          "defaultValue": "Brioche con crema",
                          "readOnlyValue": true
                        }
                      ]
                    }
                  }
              }
            },
            "price": 1.00,
            "priceCurrency": "EUR"
          }
        ]
      }
    }
  ]
}

Comments? Does anyone see more issues?

Best regards,
Dietrich

Received on Sunday, 22 February 2015 16:16:29 UTC