<?php
namespace App\EventListener\Importer\Ecomerce;
use Pimcore\Bundle\DataImporterBundle\Event\DataObject\PreSaveEvent;
use Pimcore\Model\DataObject\Data\ElementMetadata;
class EcomCatSecListener
{
public function onPreSave(PreSaveEvent $event)
{
if ($event->getConfigName() !== 'ecomCatSecundarias') {
return;
}
$data = $event->getRawData();
$product = $event->getDataObject();
$productKey = $data[0];
$category = $data[1];
$orden = $data[2];
if (empty($category)) {
return;
}
$categoriasSecundarias = $product->getCategoriasSecundarias();
/** @var ElementMetadata $categoriasSecundaria */
foreach ($categoriasSecundarias as $categoriasSecundaria) {
if ($categoriasSecundaria->getElement()->getFullPath() === $category) {
$categoriasSecundaria->setData(['Orden_1' => $orden]);
$categoriasSecundaria->setColumns(['Orden_1']);
}
}
}
}