SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
738 stars 383 forks source link

Improvement for SmartEdit contract for components #296

Closed Xymmer closed 5 years ago

Xymmer commented 5 years ago

Current contract was added in dynamic-slot.component.html. We want to generate component contract in component-wrapper.directive.ts. Also check, if no cmsTicketId (SPA not started from smart edit), do not add contract.

WeizhengSap commented 5 years ago

This is from Riry:

If you are using wcms-module-19.05.0-M3, the uuids is provided part of the cmsoccaddon response in a new smartedit property. However, the property is only provided if the GET request contains a cmsTicketId For example, to get a component using a cmsTicketId, you will get the following response: GET https://localhost:9002/rest/v2/electronics/cms/components/CameraFlashesFeatureComponent?fields=FULL&cmsTicketId=64772131984640484d7c20a0-c03f-49a9-944a-0ec6abe17f08

{
    "uid": "CameraFlashesFeatureComponent",
    "uuid": "eyJpdGVtSWQiOiJDYW1lcmFGbGFzaGVzRmVhdHVyZUNvbXBvbmVudCIsImNhdGFsb2dJZCI6ImVsZWN0cm9uaWNzQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6IlN0YWdlZCJ9",
    "typeCode": "CategoryFeatureComponent",
    "modifiedTime": "2018-11-30T14:44:49+0000",
    "name": "CameraFlashesFeatureComponent",
    "container": "false",
    "description": "Schießen Sie noch hochwertigere Bilder mit Blitz...",
    "media": {
        "code": "Elec_96x96_CatFlash_DE_01.jpg",
        "mime": "image/jpeg",
        "url": "/medias/?context=bWFzdGVyfGltYWdlc3wyNjI2fGltYWdlL2pwZWd8aW1hZ2VzL2g3YS9oYWIvODc5Njg3NjY2ODk1OC5qcGd8ZjYzM2JjNmFmYWU4MGE5ZGU2OTE4ZTRhZjRmNWRmYmNiMTc2MzExZmQ1ZTZiZGFmMDYwM2QzYWVmY2I4M2RhYg",
        "downloadUrl": "/medias/?context=bWFzdGVyfGltYWdlc3wyNjI2fGltYWdlL2pwZWd8aW1hZ2VzL2g3YS9oYWIvODc5Njg3NjY2ODk1OC5qcGd8ZjYzM2JjNmFmYWU4MGE5ZGU2OTE4ZTRhZjRmNWRmYmNiMTc2MzExZmQ1ZTZiZGFmMDYwM2QzYWVmY2I4M2RhYg&attachment=true"
    },
    "title": "Kamerablitze u. -beleuchtung",
    "category": "586",
    "properties": {
        "smartedit": {
            "catalogVersionUuid": "electronicsContentCatalog/Staged",
            "componentType": "CategoryFeatureComponent",
            "componentId": "CameraFlashesFeatureComponent",
            "classes": "smartEditComponent",
            "componentUuid": "eyJpdGVtSWQiOiJDYW1lcmFGbGFzaGVzRmVhdHVyZUNvbXBvbmVudCIsImNhdGFsb2dJZCI6ImVsZWN0cm9uaWNzQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6IlN0YWdlZCJ9"
        }
    }
}

Notice the “properties > smartedit” section in the payload all the values that you need to add to the component, content slot or page will be provided and ready to be consumed. you won’t have to do any extra work.

This is a sample request to create a preview ticket POST https://127.0.0.1:9002/previewwebservices/v1/preview

{
  "catalogVersions": [
    {
      "catalog": "electronicsProductCatalog",
      "catalogVersion": "Online"
    },
    {
      "catalog": "electronicsContentCatalog",
      "catalogVersion": "Staged"
    }
  ],
  "evaluateRestrictions": true,
  "language": "de",
  "pageId": "homepage",
  "resourcePath": "https://127.0.0.1:9002/yacceleratorstorefront/?site=electronics",
  "siteId": "electronics",
  "time": null
}
WeizhengSap commented 5 years ago

Tested on my local. I can see the properties > smartedit for each component.

screen shot 2018-12-07 at 5 46 40 pm
WeizhengSap commented 5 years ago

PR: https://github.com/SAP/cloud-commerce-spartacus-storefront/pull/712