Digital Commerce Blog.

Category: Processes

Lossless Transformation of Data Models Into Pimcore

Perfectly structuring product and customer data for the online shop, marketing channels and sales processes is no easy 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 with high performance.

The digital commerce framework Pimcore offers a wide range of possibilities to adapt a data model ideally to your own business processes. There are various ways to select the data types for the individual fields in classes, object modules and field collections. Since corporate strategy, assortment structure etc. can change quickly, however, even a data model that is perfect for the moment must be regularly adapted. This is the only way to ensure that data maintenance remains meaningful, consistent and efficient.

If data types are changed, however, the data previously entered in the objects is usually lost. Often one has to weigh up between a complex data maintenance or the acceptance of 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 data loss!

How to edit Pimcore data types without data loss

When data is imported into Pimcore with the BB Ultima Import Bundle, the following three steps are performed:

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

The Pimcore objects themselves can also serve as 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. You can then adjust the data type of the object field (or object module or field collection). Of course, the data will be lost for the time being in this case as well. But now you can import into the modified object fields based on the raw data.

Practical example: Conversion of number fields to quantity value fields

For illustration we show here how you can convert a number field in an object module into a quantity value field. In our example, technical data was initially stored without units, as 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).

Initial situation is therefore a product class with an object module field. The corresponding object modules contain different number fields:

Allgemeine Einstellungen

Now create an import that will import data from the Pimcore product objects:

+ Datenport hinzufugen

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

After the raw data import the data looks like this:

verlustfreie-transformation-datenmodelle-pimcore3

Now change the object module definition (from number field to quantity value field):

verlustfreie-transformation-datenmodelle-pimcore4

Then assign the raw data fields to the object fields to enable the object import: Using drag and drop, the raw data field path is assigned to the object fields for the object path and the field key to the object key:

+ Datenport hinzufugen

Both fields are key fields in this case. The system therefore searches for objects for which both the path and the key match the raw data value.

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-datenmodelle-pimcore3

For this purpose, a callback function can be defined in the field assignment. This allows you to 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 chair object module looks like this:

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

In this example the callback function is stored as JavaScript code. It is also possible to store PHP code. All Pimcore data types can be accessed via the callback functions, including relations, relations with metadata, field collections etc.

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

More questions about the BB Ultima Import Bundle for Pimcore?

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

Written by Anett Michael on Aug 29, 2019 3:49:03 PM

 

Kommentare