Data manipulation in OXID eShop

The OXID eShop Makaira Connect module 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. So Makaira offers all basic data types (int, float, time, as well as several str types which are more suitable depending on the type of text. More details can be found under Typing in the Makaira Index .

Adjustment of the imported data

Task

You want to change or add the data of the OXID eShop for the import.

Solution

With the help of an OXID eShop module you can extend the data:

First create a module directory as usual (here specified with <module_root>) and a metadata.php that looks like this:

<?php
/* <module_root>/metadata.php */

$sMetadataVersion = '1.1';

$aModule = array(
    'id'          => 'makaira/demo',
    'title'       => 'Makaira :: Demo Extension',
    'files'       => array(
        'makaira_demo_modifier' => '<module_root>/makaira_demo_modifier.php',
    ),
    'extend'      => array(),
    'blocks'      => array(),
    'settings'    => array(),
);

Next comes the modifier itself. By using Pimple as a dependency injection container you can add dependencies even in older versions of OXID eShop.

The method apply() gets the object to be modified as argument.

Attention: The field names are case sensitive.

Attention: In order to be able to use newly added fields, for example, as search fields, they must be available at the product objects. It is not enough to extend only the variant objects.

<?php
/* <module_root>/makaira_demo_modifier.php */

use Makaira\Connect\Modifier;
use Makaira\Connect\Type;
use Makaira\Connect\DatabaseInterface;

class makaira_demo_modifier extends Modifier
{
    /**
     * @var DatabaseInterface
     */
    private $database;

    public function __construct(DatabaseInterface $database)
    {
        $this->database = $database;
    }

    /**
     * Modify product and return modified product
     *
     * @param Type $type
     *
     * @return Type
     */
    public function apply(Type $type)
    {
        // Apply custom handling here
        /*
            $type->active = false;                              // Deaktiviert das Objekt.
            $type->newProperty = ["some_int", "Data"];              // Fügt ein Feld des Datentypes ``int`` hinzu.
            $type->OXTITLE = $type->OXTITLE . ' some content';  // Ändert den Inhalt eines Feldes.
            $type->attribute = [];                              // Enfernt alle Attribute.
        */

        return $type;
    }
}

With the help of the file dic.php, which we read automatically by means of the yamm module, you can determine for which object types your modifier should be used.

Additionally, as an optional third parameter, you can specify the priority of the modifier. This influences the loading order of the modifiers, where a modifier with a high value is loaded before a modifier with a lower value.

<?php
/* <module_root>/dic.php */

/* Custom autoloading if needed */
//require_once __DIR__ . '/vendor/autoload.php';

$dic['makaira.connect.modifiers.custom.demo'] = function (\Marm\Yamm\DIC $dic) {
    return new makaira_demo_modifier($dic['oxid.database']);
};

$oxModule = oxNew('oxModule');
$oxModule->load('makaira/demo');
if ($oxModule->isActive()) {
    //Modifier für Produkte anwenden
    $dic->tag('makaira.connect.modifiers.custom.demo', 'makaira.importer.modifier.product', 100);
    // Modifier für Kategorien
    //$dic->tag('makaira.connect.modifiers.custom.demo', 'makaira.importer.modifier.category', 100);
    // Modifier für Hersteller
    //$dic->tag('makaira.connect.modifiers.custom.demo', 'makaira.importer.modifier.manufacturer', 100);
}
Information

The Yamm module, which comes with Makaira-Connect in the release package, provides a Pimple DIC (Dependency Injection Container).

The dic.php file in the module directory is automatically processed and the makaira_demo_modifier class is added as an import modifier for product data by the $dic->tag() method.

In this way, the data for imported manufacturers and categories can also be customized.

The function of the modifier can be checked using HTTP requests to the store. See Signed requests with Postman.