/** * addCategoryContent. * * @param $id * @param $content */ private function addCategoryContent($id, $content) { $CategoryContent = new CategoryContent(); $CategoryContent->setId($id)->setContent($content); $this->app['orm.em']->persist($CategoryContent); $this->app['orm.em']->flush($CategoryContent); }
/** * プラグイン有効時の処理. * * @param array $config * @param object $app * * @throws \Exception */ public function enable($config, $app) { $this->migrationSchema($app, __DIR__ . '/Resource/doctrine/migration', $config['code']); $em = $app['orm.em']; // serviceで定義している情報が取得できないため、直接呼び出す try { // EC-CUBE3.0.3対応 $CategoryContent = $em->getRepository('Plugin\\CategoryContent\\Entity\\CategoryContent')->find(1); } catch (\Exception $e) { return null; } if (!$CategoryContent) { $CategoryContent = new CategoryContent(); // IDは1固定 $CategoryContent->setId(1); $em->persist($CategoryContent); $em->flush($CategoryContent); } }
/** * 管理画面:カテゴリ登録画面で、登録処理を行う. * * @param EventArgs $event */ public function onAdminProductCategoryEditComplete(EventArgs $event) { /** @var Application $app */ $app = $this->app; /** @var Category $target_category */ $TargetCategory = $event->getArgument('TargetCategory'); /** @var FormInterface $form */ $form = $event->getArgument('form'); // 現在のエンティティを取得 $id = $TargetCategory->getId(); $CategoryContent = $app['category_content.repository.category_content']->find($id); if (is_null($CategoryContent)) { $CategoryContent = new CategoryContent(); } // エンティティを更新 $CategoryContent->setId($id)->setContent($form[self::CATEGORY_CONTENT_TEXTAREA_NAME]->getData()); // DB更新 $app['orm.em']->persist($CategoryContent); $app['orm.em']->flush($CategoryContent); }
/** * 管理画面:カテゴリ登録画面で、登録処理を行う. * * @param EventArgs $event */ public function onAdminProductCategoryEditComplete(EventArgs $event) { log_info('CategoryContent admin.product.category.index.complete start'); /** @var Application $app */ $app = $this->app; /* @var Category $TargetCategory */ $TargetCategory = $event->getArgument('TargetCategory'); /** @var FormInterface $form */ $form = $event->getArgument('form'); // 現在のエンティティを取得 $id = $TargetCategory->getId(); $CategoryContent = $app['eccube.plugin.category_content.repository.category_content']->find($id); if (!$CategoryContent) { $CategoryContent = new CategoryContent(); } // エンティティを更新 $CategoryContent->setId($id)->setContent($form[self::CATEGORY_CONTENT_TEXTAREA_NAME]->getData()); // DB更新 $app['orm.em']->persist($CategoryContent); $app['orm.em']->flush($CategoryContent); log_info('Category Content save successful !', array('category id' => $id)); log_info('CategoryContent admin.product.category.index.complete end'); }
/** * onAdminProductCategoryEditAfter. */ public function onAdminProductCategoryEditAfter() { log_info('CategoryContent eccube.event.controller.admin_product_category_edit.after start'); $app = $this->app; if ('POST' !== $app['request']->getMethod()) { log_info('CategoryContent eccube.event.controller.admin_product_category_edit.after not post end'); return; } $id = $app['request']->attributes->get('id'); $form = $app['form.factory']->createBuilder('admin_category')->getForm(); $CategoryContent = $app['eccube.plugin.category_content.repository.category_content']->find($id); if (!$CategoryContent) { $CategoryContent = new CategoryContent(); } $form->handleRequest($app['request']); if ($form->isValid()) { $CategoryContent->setId($id)->setContent($form['content']->getData()); $app['orm.em']->persist($CategoryContent); $app['orm.em']->flush($CategoryContent); } log_info('CategoryContent eccube.event.controller.admin_product_category_edit.after end'); }