Contact us

Applies to: Customer's Canvas On-Premises; Customer's Canvas Hub cloud; UI Framework 4.0 - 4.47

Skip to main content

Restore the editor

Restore the widget values, the current step, and the design from a stored snapshot when a customer returns from the shopping cart. Use the restoration section when the config logic is complex or relies on data from the ajax widget.

  1. Pass the stored snapshot to the editor.

    Initialize the e-commerce driver with the snapshot in the restore data:

    let ecommerce = await driver.init(product, editor, config,
    { editorUrl: "https://{your-site-url}/design-editor/" },
    /* restore data */ { snapshot: "N4I...." },
    /* quantity */ 1,
    /* user info*/ { id: "JohnWood" });

    Alternatively, call auWizard.restoreEditor():

    await auWizard.restoreEditor(snapshot);
  2. Add the restoration section to the workflow file.

    {
    "restoration": {
    "widgets": [...],
    "steps": [...],
    "vars": {...}
    }
    }

    When this section is present, UI Framework uses widgets, steps, and vars from it instead of the original values. If you omit any of them, the values come from the original config.

  3. Refer to snapshot data with widgetData.

    Inside the restoration section, dynamic expressions can use the widgetData object. It refers to widget data stored in a snapshot instead of the widget itself.

    For example, a workflow that fills vehicle dropdowns from the server cannot repeat these requests during restoration. Remove the ajax widgets from restoration.widgets and read their values from widgetData:

    {
    "widgets": [ ... ],
    "restoration": {
    "widgets": [
    {
    "name": "order",
    "type": "order",
    "params": {
    "data": {
    "Year": "{{ widgetData.vehicleYear.selected.optionValue.title }}",
    "Make": "{{ widgetData.vehicleMake.selected.optionValue.title }}",
    "Model": "{{ widgetData.vehicleModel.selected.optionValue.title }}"
    },
    "images": "{{ $['editor'].proofImageUrls.map(x=> x[0]) }}",
    "downloadUrls": "{{ $['editor'].hiResUrls }}"
    }
    }
    ]
    }
    }
  4. Map widget properties to widgetData.

    Widget values in widgetData may use different property names than in the config:

    WidgetProperty in configProperty in widgetData
    ajaxresponseresponse
    ajaxresponsesresponses
    ajaxstatusCodestatus
    asset-storage-ajaxapiResponseapiResponse
    asset-storage-ajaxresponseresponse
    canvasstateIdstateId
    checkbox._value
    color-pickercolorcolor
    color-selectorcolorcolor
    data-driven-editorstateIddesign.designId
    data-driven-editoruserIdaccess.userId
    datasheettableService.getData()tableData
    datasheetcolumnSchemescolumnSchemes
    design-editorstateIdstateId
    gallery._value
    html$.container.innerHTMLhtml
    input-text._text
    option._selected.optionValue
    preflightstateIdstateId
    preflightpagepage
    static-texttexttext
  5. Configure Design Editor for restoration.

    Set productDefinition to any valid value, for example, a blank 1×1 design: Design Editor replaces it with the saved design. Replace the bulky editorConfig with {"loadConfigFromState": true} to load the config from the saved state file:

    {
    "name": "editor",
    "type": "design-editor",
    "params": {
    "initial": {
    "productDefinition": {
    "surfaces": [
    {
    "width": 1,
    "height": 1
    }
    ]
    },
    "editorConfig": {
    "loadConfigFromState": true
    }
    }
    }
    }

After these steps, the restored workflow reuses the snapshot data and does not repeat server requests.

Was this page helpful?