Skip to content

Lossless transformation of data models in Pimcore

Structuring product and customer data perfectly for the online store, marketing channels and sales processes is no simple task. When creating a data model, numerous factors must be taken into account so that the data can be efficiently maintained and stored and processed in the end.

The digital commerce framework Pimcore offers a wide range of options for ideally adapting a data model to your own company processes. When selecting the data types for the individual fields in classes, object modules and field collections, various paths lead to the goal. Since corporate strategy, product range structure, etc. can change quickly, even a data model that is perfect for the moment must be adapted regularly. This is the only way to ensure that data maintenance continues to be meaningful, consistent and efficient.

When data types are changed, however, the data previously entered in the objects is usually lost. So you often have to weigh up between costly data maintenance or accepting a data model that is suboptimal for the new requirements.

With the BB Ultima Import Bundle, this choice between two evils no longer exists: It is now possible to change data types without losing data!

How to edit Pimcore data types without data loss

When importing data into Pimcore using the BB Ultima Import Bundle, the following three steps occur:

  1. Importing the raw data from a data source
  2. Editing the raw data
  3. Importing the data into the Pimcore data objects

The Pimcore objects themselves can also serve as the data source for the first step. To convert the data type of an object field, the first step is to read the data from the Pimcore objects. Then you can adjust the data type of the object field (or the object module or the field collection). Of course, even in this case, the data will be lost for the time being. But now you can import based on the raw data into the changed object fields.

Practical example: Converting number fields to quantity value fields

To illustrate this, we show here how you can convert a number field into a quantity value field in an object module. In our example, technical data was initially stored without units, since all data was available in cm when the data model was introduced. In the future, however, the system should allow the units to be individually adapted during product data maintenance (e.g. length in mm, cm, m).

The initial situation is therefore a product class with an object module field. The associated object modules contain various number fields:

Pimcore Objektbausteine

Now you create an import that is to import data from the Pimcore product objects:

Pimcore Datenimport einrichten

For the raw data fields, you can access all getter methods of the product class. In this case, you need the object path and object key for later identification of the objects and, of course, the object modules that contain the data fields to be changed.

After the raw data import, the data looks like this:

Rohdaten-Import für verlustfreie Transformation des Datenmodells in Pimcore

Now change the object module definition (from Number field to Quantity Value field):

Objektbaustein-Definition in Pimcore ändern

Then map the raw data fields to the object fields to enable object import: drag and drop the raw data field path to the object fields for the object path and the field key to the object key:

Änderung Datenmodell in Pimcore: Rohdatenfeldern den Objektfeldern zuordnen

Both fields are key fields in this case. So objects are searched for where both the path and the key match the raw data value.

In order to enter the raw data into the new object module fields, the raw data must now be prepared in such a way that the import bundle understands it and can call the respective setter methods correctly.

Verlustfreie Transformation von Datenmodellen in Pimcore

For this purpose, a callback function can be stored in the field assignment. In it you can access the raw data and the existing object data. In the case of object modules with Quantity Value fields, such a callback function for the width field in the object module chair looks like this:

// parse the JSON string containing the object Brick data - converting the Brick getter method return value to JSON is handled by the import bundle params.value = JSON.parse(params.value); // If object has no technical data, null returned if(typeof params.value.primarytechnicaldata === "undefined") return null; // if it has object component "chair" if(typeof params.value.primarytechnicaldata.Chair !== "undefined") { // read the value from the old number field and return it as an array to populate the Quantity Value field [value, unit] return [params.value.primarytechnicaldata.Chair.width, 'cm']; }

In this example, the callback function is JavaScript code. However, it is also possible to use PHP code. All Pimcore data types can be accessed via the callback functions, i.e. also relations, relations with metadata, field collections, etc.

The BB Ultima Import Bundle thus allows you to adapt your data model to changed requirements and Pimcore developments without data loss.

Still questions about the BB Ultima Import Bundle for Pimcore?

Do you need help with data model changes or imports from external sources? We will be happy to answer your questions and support you during the implementation.

Pimcore-Experten von Blackbit kontaktieren

Comments: