有一个类产品,它有一层ProductSpecs(分类存储)。如何将我需要的categoryStore组写入对象?
文档未找到关于此主题的任何内容。请帮我
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
}
}
}
答案 0 :(得分:0)
假设您的CS字段称为ProductSpecs,您可以尝试使用此方法为对象设置活动组:
$groupConfig = GroupConfig::getByName($groupName, $storeId);
if ($groupConfig) {
$groupId = $groupConfig->getId();
$foo->getProductSpecs()->setActiveGroups([$groupId => true]);
}