Hi there,
I’m trying to create some PropertyGroup during installation of my plugin. I can create the data I want but I get an exception after and the plugin isn’t installed.
On my bootstrap.php I have
public function install()
{
$this->configurePropertiesGroups();
return array('success' => true, 'invalidateCache' => array('backend'));
}
protected function configurePropertiesGroups()
{
$apiResourcePropertyGroup = new \Shopware\Components\Api\Resource\PropertyGroup();
$apiResourcePropertyGroup->setManager($this->getEntityManager());
// add Material Properties
$this->createPropertyGroup($apiResourcePropertyGroup, 'Material', 1);
}
private function getEntityManager()
{
return Shopware()->Models();
}
protected function createPropertyGroup($apiResourcePropertyGroup, $name, $position)
{
$properties = array(
'name' => $name,
'position' => $position,
'comparable' => 1,
'sortmode' => 2
);
$apiResourcePropertyGroup->create($properties);
}
And the exception I get is
„Unable to install, got exception: Entity has to be managed or scheduled for removal for single computation Shopware\Models\Plugin\Plugin@00000000231afc1800007f28a267451c“
After debug I check that exception happen on execution of Plugin/Namespace->flush($plugin).
As I see this is related to EntityManager, because on \Shopware\Components\Api\Resource\PropertyGroup()->create() method is executed the $em->flush($property).
Anyone can help how to create the PropertyGroup items using API on install method and get the plugin installed without errors?
Thanks