/** * @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(); }
public function deleteNodeAction() { $manager = $this->getModelManager(); $profileId = $this->Request()->getParam('profileId', 1); $data = $this->Request()->getParam('data', 1); $profileRepository = $manager->getRepository(Profile::class); $profileEntity = $profileRepository->findOneBy(['id' => $profileId]); $tree = json_decode($profileEntity->getTree(), 1); if (isset($data['parentId'])) { $data = [$data]; } $errors = false; foreach ($data as &$node) { if (!TreeHelper::deleteNode($node, $tree)) { $errors = true; } } $profileEntity->setTree(json_encode($tree)); $manager->persist($profileEntity); $manager->flush(); if ($errors) { $this->View()->assign(['success' => false, 'message' => 'Some of the nodes could not be saved', 'children' => $data]); } else { $this->View()->assign(['success' => true, 'children' => $data]); } }