/** * @param $data * @return mixed|ProfileEntity * @throws \Enlight_Exception * @throws \Exception */ public function createProfileModel($data) { $event = Shopware()->Events()->notifyUntil('Shopware_Components_SwagImportExport_Factories_CreateProfileModel', ['subject' => $this, 'data' => $data]); if ($event && $event instanceof \Enlight_Event_EventArgs && $event->getReturn() instanceof ProfileEntity) { return $event->getReturn(); } if (!isset($data['name'])) { throw new \Exception('Profile name is required'); } if (!isset($data['type'])) { throw new \Exception('Profile type is required'); } if (isset($data['hidden']) && $data['hidden']) { $tree = TreeHelper::getTreeByHiddenProfileType($data['type']); } else { if (isset($data['baseProfile'])) { $tree = TreeHelper::getDefaultTreeByBaseProfile($data['baseProfile']); } else { $tree = TreeHelper::getDefaultTreeByProfileType($data['type']); } } $profileEntity = new ProfileEntity(); $profileEntity->setName($data['name']); $profileEntity->setBaseProfile($data['baseProfile']); $profileEntity->setType($data['type']); $profileEntity->setTree($tree); if (isset($data['hidden'])) { $profileEntity->setHidden($data['hidden']); } $this->modelManager->persist($profileEntity); $this->modelManager->flush(); return $profileEntity; }
/** * @param string $profileType * @param string $profileName */ private function createProfile($profileType, $profileName) { $defaultTree = TreeHelper::getDefaultTreeByProfileType($profileType); $profile = new Profile(); $profile->setHidden(0); $profile->setName($profileName); $profile->setType($profileType); $profile->setTree($defaultTree); $this->modelManager->persist($profile); $this->modelManager->flush(); $this->profileIds[$profileType] = $profile->getId(); }