Editor snapshots
A snapshot is basically a state of all widgets in the editor represented by a base64-encoded string. UI Framework allows for applying this string later to restore the state of widgets. When it happens, it temporarily turns off the dynamic expression auto update to prevent any side effects and inconsistencies.
UI Framework allows for reading this string at any time. As usual, you want to do it when a user finishes personalization and leaves the editor. It is supposed that you store this string somewhere, for example, in local storage or a database that temporarily stores unfinished shopping carts. When a user decides to return to the editor, you need to pass a snapshot to the editor page and initialize the editor using this string.
All standard e-commerce plugins implement this idea. As long as a config file sets up a snapshot and a restoration section (see Restore the editor), the "return to edit" functionality works out of the box. However, you can implement it in any custom integration as well.
Creating a snapshot
The simplest way to read a snapshot and pass it outside of the editor is to define the snapshot property in the data object of the order or cart widget as follows:
{
"name": "order",
"type": "order",
"params": {
"images": "{{ $['design-editor'].proofImageUrls.map(item=>item[0]) }}",
"downloadUrls": "{{$['design-editor'].hiResUrls}}",
"data": {
"stateId": "{{ $['design-editor'].stateId}}",
"snapshot": "{{ main.editorState }}"
}
}
}
All our standard e-commerce plugins read the snapshot from this snapshot property. In custom integrations, you must store this value, as explained below.
As you may notice, we're just reading the editorState property of the editor component (au-wizard HTML element), which is accessed through the main object of a scope.
You can also create a snapshot outside of the config in your JavaScript code. To make a snapshot, you can call the auWizard.createEditorSnapshot() method in your script.
const snapshot = await auWizard.createEditorSnapshot(true);
If you pass true as the parameter, then this method will also have all Design Editors used in the config to save the design by using the saveProduct method of the Customer's Canvas IFrame API.
Storing a snapshot
It is up to you where and how you store a snapshot. For example, you may use:
- Local storage
- Database
- For the online store platforms like Shopify, cart item meta fields
- ... and any other way to store temporary data
A user may order more than one line item, or the same item may be ordered several times with different personalization. It may be important to take this into consideration, for example, if you are using local storage and select a key name for a snapshot entry.
It is not recommended to store this data too long. If you change the config after the snapshot is created, UI Framework may fail to restore the updated config with a snapshot.