EN IT
Open2b version 7.8

Storage

Apps can persist information, as key-value pairs, in a store database area called storage. Both keys and values are strings. Storage allows apps without a server side to store configuration information related to the store.

  1. Go to the back office in the Apps section
  2. Click Manage Apps.
  3. Click the row for the app.
  4. Select Store information in app storage.
  5. Click Save.

Then add Admin SDK to the app HTML pages:

<script src="https://open2b.dev/admin-sdk/open2b-admin-sdk-v7.8.min.js"></script>

Methods

Admin.Storage.clear(function(error) { … })

Removes all keys and values saved by the app in the store storage.

Example:

Admin.Storage.clear(function(error) {
    if ( error != null ) { alert(error); return; }
    // done
});

Admin.Storage.remove(keys, function(error) { … })

Removes the specified keys from store storage.

Example:

Admin.Storage.remove([ 'color', 'width' ], function(error) {
    if ( error != null ) { alert(error); return; }
    // done
});

Admin.Storage.get(keys, function(items, error) { … })

Returns values associated with the specified keys. If a key does not exist, it returns null as the value for that key. To read all keys, use null instead of the list of keys.

Example:

Admin.Storage.get([ 'color', 'width' ], function(items, error) {
    if ( error != null ) { alert(error); return; }
    alert('color: '+items.color, '; width: '+items.width);
});

Admin.Storage.set(items, function(error) { … })

Adds new keys or updates existing ones. items is a JavaScript object with all keys and values to store. If a key already exists its value is updated, otherwise it is added. Values that are not strings are first serialized to JSON and then saved as strings.

Example:

Admin.Storage.set({ color: 'red', width: 348 }, function(error) {
    if ( error != null ) { alert(error); return; }
    // done
});

Limits

Storage can hold up to 1,000 keys with a maximum length of 32 characters. Values can be up to one million characters long and, in any case, the sum of the lengths of all values cannot exceed one million characters. Keys are case-insensitive and the empty string is a valid key.