如何在产品中编写对象分类库?

How to write object classificationstore in a product?

有一个 class 产品,它有一层 ProductSpecs (classificationstore)。如何将我需要的 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
        }
    }
}

假设您的 CS 字段称为 ProductSpecs,您可以尝试为对象设置活动组:

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

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