Unlocking Your Data with Flows
Flows is essentially an EAV system and nearly everything on Moltin runs on top of this. This means you have more flexibility and control over your data out of the box than you get with other eCommerce platforms. You can add flows, fields, and entries to anything you can imagine. For example you could create a Flow for your site or app content that you could then distribute from anywhere. Or you could even add additional data to core components of the Moltin platform.
So What is an EAV system?
Wikipedia defines EAV as: “Entity–attribute–value model (EAV) is a data model to describe entities where the number of attributes (properties, parameters) that can be used to describe them is potentially vast, but the number that will actually apply to a given entity is relatively modest. In mathematics, this model is known as a sparse matrix.”
For Moltin, this means that any Flow can have any number of fields attached, from a range of available field types and can store a huge number of entries whilst remaining lightning fast to query. You can think of a Flow as a container and is in some ways similar to a database table.
Flows in Practice
Flows might seem like something quite complicated but once you’ve tried it out for yourself you’ll see just how easy it is to use. If you’d rather just create the flows, fields, and entries without touching any code however you can do so via the store management dashboard through simple forms. If interacting with Flows directly gets you excited then you’ll be interested in some simple examples below to help you get started. The code examples assume you are using PHP, other language examples will be available in our documentation.
Creating a Flow
The first thing you need to do when defining your own custom data is to define the container to store it in - a Flow. This is relatively simple, it’s just the title, a slug, and a description. Adding a Flow looks like this:
$flow = $moltin->createFlow(array( 'name' => 'My Awesome Flow', 'slug' => 'my-awesome-flow', 'info' => 'This flow stores my awesome custom data' ));
Adding Fields to a Flow
So we’ve created a Flow, now we need to define our fields. A simple string field can easily be added like this:
$field = $moltin->post('flow/my-awesome-flow/field', array( 'slug' => "title", 'name' => "Title", 'type' => "string", 'options' => , // optional 'required' => false, // optional 'unique' => false, // optional 'title' => true // optional ));
Other field types can be added including; choice, country, date, decimal, email, integer, relationship, slug, string, text, multiple, tax band, gateway, and currency. Whilst some of these are self explanatory, there are a couple of interesting ones here. The multiple and relationship field types allow you to bind the field to a particular flow, meaning the field will return the available entries from that flow. You can see an example below of creating a relationship field between “my-awesome-flow” and the categories flow.
$field = $moltin->post('flow/my-awesome-flow/field', array( 'slug' => "category", 'name' => "Category", 'type' => "relationship", 'options' => ['relates_to' => 'categories'], 'required' => false, // optional 'unique' => false, // optional 'title' => false // optional ));
You can also edit most of the core Moltin system by adding your own fields, allowing you to adapt the platform to your needs with ease. You would just replace “my-awesome-flow” with the core flow slug e.g. “categories” or “products”.
Adding Entries to a Flow
The Flow and fields are set, now it’s just a case of adding your entries so that you can retrieve and perform further operations later.
$entry = $moltin->post('flow/my-awesome-flow/entry', array( 'title' => "Entry Title", 'category' => 1 ));
Getting Entries from a Flow
Retrieving entries that you have added to a Flow is relatively straightforward, an example is shown below to retrieve the first 15 entries.
$entries = $moltin->get('flow/my-awesome-flow/entries', ['limit' => 15, 'offset' => 0]);
So now what?
Flows is an incredibly powerful tool, but when combined with the Moltin API, it enables you to create and store any data you can think of and distribute it to where ever you need it. Flows and the API remove the barriers and hurdles that developers face when extending a platform with custom data.
Manage your data structure through the store management dashboard
So now you know what Flows is and how it works your only limitation is your imagination. You can read more in-depth and detailed instructions and examples over on the docs, create and edit your own Flows via the store management dashboard or dive straight in and start implementing Flows programmatically into your own projects.
Over the coming weeks, we’ll be giving a sneak preview of some of the tech we’ve been working on, including a preview of the next version of our store management dashboard (powered by AngularJS), an awesome new template system and some great example uses of Flows. If you have any uses for Flows drop us a message or leave a comment below, we’d love to hear your ideas!
The Moltin team