Modifier

Sometimes it is necessary to enrich the data in the Makaira. This is realized by modifiers.

They reside in separate Shopware plugins written by you and are PHP classes that implement one of the following interfaces:

Interface

Used for

MakairaConnect\Modifier\ProductModifierInterface

Articles with their main article details and article variants

MakairaConnect\Modifier\CategoryModifierInterface

Categories

MakairaConnect\Modifier\ManufacturerModifierInterface

Manufacturers

The Makaira Connect plugin provides very easy-to-use events to modify and enrich the data during import.

This allows, for example, to create values for filters, to add content extensions to the fields, or to concatenate several fields - all data is taken into account here. Makaira provides a naming of the new fields, which ensures the correct typing of the field. The correct typing is necessary so that the field can be used with the desired effect. Thus Makaira offers all basic data types int, float, time as well as several str types which are more suitable depending upon the kind of the text. More details can be found under Types in Makaira.

The removal of whitespaces in the article title will serve as an example here. The parameter $mappedData will contain the data for Makaira.

<?php

namespace MyAwesomePlugin\Makaira\Modifier\Product;

use MakairaConnect\Modifier\ProductModifierInterface;
use Shopware\Bundle\StoreFrontBundle\Struct\Product;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContext;

class TrimTitleModifier implements ProductModifierInterface
{
    public function modifyProduct(array &$mappedData, Product $item, ShopContext $context): void
    {
        // To overwrite the title, regardless of any previous title modification
        $mappedData['title'] = trim($item->getName());
        // Or if you want to modify the mapped title
        // E.g. if another modifier changed the title already
        $mappedData['title'] = trim($mappedData['title']);
    }
}

Once the class has been created and can be loaded by the autoloader, it still needs to be registered as a modifier. This is done in the services.xml in your plugin.

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="MyAwesomePlugin\Makaira\Modifier\Product\TrimTitleModifier">
            <tag name="makaira_connect.mapper.modifier.product" priority="999" />
        </service>
    </services>

</container>

The tag name makaira_connect.mapper.modifier.product marks the modifier as product modifier (with the main details).

The plugin supports multiple tags to modify different document types.

Tag-Name

Modifier for

makaira_connect.mapper.modifier.product

Article with its main article details

makaira_connect.mapper.modifier.variant

Article with article details

makaira_connect.mapper.modifier.category

Categories

makaira_connect.mapper.modifier.manufacturer

Manufacturer

📘

The loading of multiple modifiers can be specified via priority whereby the higher priority is loaded first.

The function of the modifier can be checked by calling the plugin endpoint with the corresponding action.