コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @return Enlight_View|Enlight_View_Default
  * @throws Exception
  */
 public function duplicateProfileAction()
 {
     $manager = $this->getModelManager();
     $snippetManager = $this->get('snippets');
     $profileId = (int) $this->Request()->getParam('profileId');
     $loadedProfile = $manager->find(Profile::class, $profileId);
     if (!$loadedProfile) {
         throw new \Exception(sprintf('Profile with id %s does NOT exist', $profileId));
     }
     $profile = new Profile();
     $profile->setBaseProfile($loadedProfile->getId());
     $profile->setName($loadedProfile->getName() . ' (' . $snippetManager->getNamespace('backend/swag_import_export/controller')->get('swag_import_export/profile/copy') . ')');
     $profile->setType($loadedProfile->getType());
     $profile->setTree($loadedProfile->getTree());
     $manager->persist($profile);
     try {
         $manager->flush();
     } catch (DBALException $e) {
         return $this->View()->assign(['success' => false, 'message' => $snippetManager->getNamespace('backend/swag_import_export/controller')->get('swag_import_export/profile/duplicate_unique_error_msg')]);
     } catch (\Exception $e) {
         return $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
     }
     return $this->View()->assign(['success' => true, 'data' => ['id' => $profile->getId(), 'name' => $profile->getName(), 'type' => $profile->getType(), 'baseProfile' => $profile->getBaseProfile(), 'tree' => $profile->getTree(), 'default' => $profile->getDefault()]]);
 }