---
title: Data Transformation
description: How to use the script editor to transform imported data rows in Shopware 6 using PHP scripts with whitelisted functions.
---

![](https://firebearstudio.com/blog/wp-content/uploads/2024/10/Data-Trnaformation-via-script-for-Shopware-6-import.jpg)

The script editor lets you transform imported rows before they are processed. You can edit field values directly in the import workflow using the `$row` variable.

## Key Functionalities

- **Script input:** Write transformation logic against the `$row` variable for each imported row.
- **Function whitelisting:** Only approved PHP functions are available, so you can perform common transformations without exposing the system to unsafe code.

## Allowed PHP Functions

| **Function Group** | **Functions** |
| --- | --- |
| String Functions | strlen, strpos, strtolower, strtoupper, trim, substr, str_replace, explode, implode, htmlspecialchars, ucfirst, lcfirst |
| Hashing Functions | md5, sha |
| Array Functions | in_array, count |
| Math Functions | abs, round, ceil, floor, max, min, rand, sqrt, pow |
| Date/Time Functions | time, date, strtotime, mktime |
| Variable Handling Functions | isset, empty |
| JSON Functions | json_encode, json_decode |
| Multibyte String Functions | mb_ereg_replace, mb_ereg_replace_callback, mb_eregi_replace, mb_split, mb_str_pad, mb_str_split, mb_strcut, mb_strimwidth, mb_stripos, mb_stristr, mb_strlen, mb_strpos, mb_strrchr, mb_strrichr, mb_strripos, mb_strrpos, mb_strstr, mb_strtolower, mb_strtoupper, mb_substr, mb_substr_count |

## Example Use Cases

You can use data transformation to:

- remove extra `$` symbols from manufacturer values
- replace spaces or separators in options
- increase stock values by a fixed amount
- calculate prices when imported values are empty
- replace commas with `|` in keyword fields
- concatenate `meta_title` and `name`

## General Format For The `$row` Script

The `$row` variable is an associative array. Each key represents a column from the imported file, and each value contains the row data for that column.

### 1. Access Row Data

```php
$manufacturerName = $row['manufacturer_name'];
```

### 2. Modify Row Data

```php
$row['manufacturer_name'] = str_replace('$', '', $row['manufacturer_name']);
```

### 3. Use Allowed PHP Functions

```php
$row['options'] = strtolower($row['options']);
```

### 4. Apply Conditional Logic

```php
if (isset($row['stock']) && $row['stock'] > 0) {
    $row['stock'] += 10;
}
```

### 5. Perform Calculations

```php
if (isset($row['price_gross']) && $row['price_gross'] == 0) {
    $row['price_gross'] = $row['net'] * 1.19;
}
```

### 6. Save The Modified Row

You do not need to return anything manually. Changes to `$row` are applied during the import process.

## Full Script Example

```php
$row['manufacturer_name'] = str_replace('$', '', $row['manufacturer_name']);
$row['options'] = str_replace(';', '|', trim($row['options']));

if (isset($row['stock'])) {
    $row['stock'] += 10;
}

if (isset($row['price_gross']) && $row['price_gross'] == 0) {
    $row['price_gross'] = $row['net'] * 1.19;
}

$row['keywords'] = str_replace(',', '|', $row['keywords']);
$row['meta_title'] = $row['meta_title'] . ' ' . $row['name'];
```

## Key Points

- `$row` is an associative array of imported column values.
- You can access and modify fields with `$row['column_name']`.
- Only whitelisted PHP functions are allowed.
- All changes are applied directly during the import process.
