Как написать классификацию объектов в продукте? - PullRequest
0 голосов
/ 03 июня 2019

Существует класс product, в нем есть слой ProductSpecs (classificationstore). Как записать нужную мне группу классификации в объект?

В документации ничего не найдено по этой теме. Пожалуйста, помогите мне


namespace AppBundle\EventListener;

use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Event\Model\DataObjectEvent; 
use Pimcore\Event\Model\AssetEvent;
use Pimcore\Event\Model\DocumentEvent; 

class ProductPropertyListener
{
    public function onPreUpdate (ElementEventInterface $e) {

        if($e instanceof AssetEvent) {
            // do something with the asset
            $foo = $e->getAsset(); 
        } else if ($e instanceof DocumentEvent) {
            // do something with the document
            $foo = $e->getDocument(); 
        } else if ($e instanceof DataObjectEvent) {
            // do something with the object
            $foo = $e->getObject();

            // getting an object here is not clear what to do with it
        }
    }
}

1 Ответ

0 голосов
/ 04 июня 2019

Предполагая, что ваше поле CS называется ProductSpecs, вы можете попытаться установить активную группу для объекта:

$groupConfig = GroupConfig::getByName($groupName, $storeId);

if ($groupConfig) {
    $groupId = $groupConfig->getId();
    $foo->getProductSpecs()->setActiveGroups([$groupId => true]);
}
...