質問 > その他 > Customizeフォルダーでのカスタマイズ方法 |
その他
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | 下へ |
投稿者 | スレッド |
---|---|
jacker |
投稿日時: 2019/12/10 13:35
対応状況: −−−
|
新米 登録日: 2019/7/10 居住地: 投稿: 10 |
Customizeフォルダーでのカスタマイズ方法 [EC-CUBE] 4.03
こんにちは EC-CUBE4でCustomizeの存在を知って、ただいまSymfony勉強中です。 まずは、会員管理をコピーしてお問合せ管理を作成しようとsrcで追加していき、正常動作が確認できたので Customizeフォルダーへ移行し始めました。getContactQueryBuilderのところでエラーになってしまい 困っています。このエラーの箇所だけ、既存のEccube\Service\CsvExportService.phpを直接修正していて。 \Customize\Service\CsvExportService.phpでextendsで拡張したつもりですが下記のエラーとなってしまいました。 いまいち、基本のソースから拡張する方法がうまくできません。ネットで調べてもextendsをするぐらいの情報しかなく。 どこか参考になるサイトなどないでしょうか? app\Customize\Controller\Admin\Contact\ContactController.php(line 307) use Eccube\Service\CsvExportService; $this->csvExportService->exportHeader(); // お問合せデータ検索用のクエリビルダを取得. $qb = $this->csvExportService ->getContactQueryBuilder($request); UndefinedMethodException Attempted to call an undefined method named "getContactQueryBuilder" of class "Eccube\Service\CsvExportService". Did you mean to call e.g. "getCustomerQueryBuilder", "getOrderQueryBuilder", "getProductQueryBuilder" or "setExportQueryBuilder"? ■app\Customize\Service\CsvExportService.phpの内容 <?php namespace Customize\Service; use Customize\Form\Type\Admin\SearchContactType; use Customize\Repository\ContactRepository; use Eccube\Service as Service; class CsvExportService extends Service\CsvExportService { /** * @var ContactRepository */ protected $contactRepository; /** * CsvExportService constructor. * * @param ContactRepository $contactRepository */ public function __construct( ContactRepository $contactRepository ) { $this->contactRepository = $contactRepository; } /** * @param ContactRepository $contactRepository */ public function setContactRepository(ContactRepository $contactRepository) { $this->contactRepository = $contactRepository; } /** * お問合せ用のクエリビルダを返す. * * @param Request $request * * @return \Doctrine\ORM\QueryBuilder */ public function getContactQueryBuilder(Request $request) { $session = $request->getSession(); $builder = $this->formFactory ->createBuilder(SearchContactType::class); $searchForm = $builder->getForm(); $viewData = $session->get('eccube.admin.contact.search', []); $searchData = FormUtil::submitAndGetData($searchForm, $viewData); // お問合せデータのクエリビルダを構築. $qb = $this->contactRepository ->getQueryBuilderBySearchData($searchData); return $qb; } } |
umebius |
投稿日時: 2019/12/10 17:04
対応状況: −−−
|
神 登録日: 2016/7/22 居住地: 投稿: 2085 |
Re: Customizeフォルダーでのカスタマイズ方法 エラーになる原因は、$qb = $this->csvExportService->getContactQueryBuilder($request);の箇所で、$this->csvExportServiceに入っているのが
Customize\Service\ CsvExportServiceクラスのオブジェクトではなく、Eccube\Service\CsvExportServiceクラスだからです。 コンストラクタでCustomize\Service\ CsvExportServiceクラスをインジェクションしてやってください
|
jacker |
投稿日時: 2019/12/11 11:31
対応状況: −−−
|
新米 登録日: 2019/7/10 居住地: 投稿: 10 |
Re: Customizeフォルダーでのカスタマイズ方法 umebiusさん
ご返信ありがとうございます。 初歩的な質問かと思いますが useと\Customize\Service\CsvExportServiceを直接指定する場合 違いはあるのでしょうか? いろいろやってみたのですが、うまくいきません。 $this->csvExportService->initCsvType(6)が存在しないとなってしまって ●useの方法 use Customize\Service\CsvExportService; private $csvExportService; public function __construct( CsvExportService $csvExportService ) { $this->csvExportService = $csvExportService; } ●回答いただいた方法 private $csvExportService; public function __construct( \Customize\Service\CsvExportService $csvExportService ) { $this->csvExportService = $csvExportService; } ●現在のコード ■app\Customize\Service\CsvExportService.php内容 namespace Customize\Service; use Customize\Form\Type\Admin\SearchContactType; use Customize\Repository\ContactRepository; use Symfony\Component\HttpFoundation\Request; use Eccube\Service as Service; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormFactoryInterface; class CsvExportService extends Service\CsvExportService { /** * @var CsvExportService */ protected $csvExportService; /** * @var ContactRepository */ protected $contactRepository; /** * CsvExportService constructor. * * @param ContactRepository $contactRepository */ public function __construct( ContactRepository $contactRepository ) { $this->contactRepository = $contactRepository; } ■app\Customize\Controller\Admin\Contact\ContactController.php内容 namespace Customize\Controller\Admin\Contact; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\ORM\QueryBuilder; use Eccube\Common\Constant; use Eccube\Controller\AbstractController; use Eccube\Entity\Master\CsvType; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Customize\Form\Type\Admin\SearchContactType; use Customize\Repository\ContactRepository; use Eccube\Repository\Master\PageMaxRepository; use Eccube\Repository\Master\PrefRepository; use Eccube\Repository\Master\SexRepository; #use Eccube\Service\CsvExportService; use Customize\Service\CsvExportService; use Eccube\Service\MailService; use Eccube\Util\FormUtil; use Knp\Component\Pager\Paginator; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Translation\TranslatorInterface; class ContactController extends AbstractController { /** * @var CsvExportService */ protected $csvExportService; /** * @var MailService */ protected $mailService; /** * @var PrefRepository */ protected $prefRepository; /** * @var SexRepository */ protected $sexRepository; /** * @var PageMaxRepository */ protected $pageMaxRepository; /** * @var ContactRepository */ protected $contactRepository; public function __construct( PageMaxRepository $pageMaxRepository, ContactRepository $contactRepository, SexRepository $sexRepository, PrefRepository $prefRepository, MailService $mailService, CsvExportService $csvExportService ) { $this->pageMaxRepository = $pageMaxRepository; $this->contactRepository = $contactRepository; $this->sexRepository = $sexRepository; $this->prefRepository = $prefRepository; $this->mailService = $mailService; $this->csvExportService = $csvExportService; } その他コード /** * お問合せCSVの出力. * * @Route("/%eccube_admin_route%/contact/export", name="admin_contact_export") * * @param Request $request * * @return StreamedResponse */ public function export(Request $request) { // タイムアウトを無効にする. set_time_limit(0); // sql loggerを無効にする. $em = $this->entityManager; $em->getConfiguration()->setSQLLogger(null); $response = new StreamedResponse(); $response->setCallback(function () use ($request) { // CSV種別を元に初期化. $this->csvExportService->initCsvType(6); // ヘッダ行の出力. $this->csvExportService->exportHeader(); // お問合せデータ検索用のクエリビルダを取得. $qb = $this->csvExportService ->getContactQueryBuilder($request); その他コード |
umebius |
投稿日時: 2019/12/11 18:32
対応状況: −−−
|
神 登録日: 2016/7/22 居住地: 投稿: 2085 |
Re: Customizeフォルダーでのカスタマイズ方法 引用:
useと\Customize\Service\CsvExportServiceを直接指定する場合 いえ書き方の違いだけで同じとなります。 引用: $this->csvExportService->initCsvType(6)が存在しないとなってしまって エラーなどが出ていますか? mtb_csv_typeにはCSVの種別「6」を登録されていますでしょうか? 登録がないと、次のexportHeaderでエラーになるかと思います。
|
jacker |
投稿日時: 2019/12/12 9:25
対応状況: −−−
|
新米 登録日: 2019/7/10 居住地: 投稿: 10 |
Re: Customizeフォルダーでのカスタマイズ方法 umebiusさん、こんにちは すみません。エラー記載していませんでした。 use Customize\Service\CsvExportService;と use Eccube\Service\CsvExportService; の呼び出しを変えた場合です。 あとsrcフォルダー一度直にソースをさわって動作させているのでdtb_csv、mtb_csv_typeは登録済みです。 use Customize\Service\CsvExportService;を有効にすると Call to a member function find() on null FatalThrowableError in Eccube\Service\CsvExportService.php(line 230) 225. public function initCsvType($CsvType) 226. { 227. if ($CsvType instanceof CsvType) { 228. $this->CsvType = $CsvType; 229. } else { 230. $this->CsvType = $this->csvTypeRepository->find($CsvType); 231. } 232. use Eccube\Service\CsvExportService;を有効にすると Symfony\Component\Debug\Exception\ UndefinedMethodException app\Customize\Controller\Admin\Contact\ContactController.php(line 303) 302. $qb = $this->csvExportService 303. ->getContactQueryBuilder($request); |
jacker |
投稿日時: 2019/12/12 10:16
対応状況: −−−
|
新米 登録日: 2019/7/10 居住地: 投稿: 10 |
Re: Customizeフォルダーでのカスタマイズ方法 自己レスです。
とりあず、extendsで追加するのをあきらめて、下記で対応させてました。 もう少し、クラスを理解してから考えます。 app\Customize\Controller\Admin\Contact\ContactController.php内に下記関数を入れて public function getContactQueryBuilder(Request $request) { $session = $request->getSession(); $builder = $this->formFactory ->createBuilder(SearchContactType::class); $searchForm = $builder->getForm(); $viewData = $session->get('eccube.admin.contact.search', []); $searchData = FormUtil::submitAndGetData($searchForm, $viewData); // お問合せデータのクエリビルダを構築. $qb = $this->contactRepository ->getQueryBuilderBySearchData($searchData); return $qb; } 下記で呼び出すことにしました。 # $qb = $this->csvExportService # ->getContactQueryBuilder($request); $qb = $this->getContactQueryBuilder($request); |
umebius |
投稿日時: 2019/12/12 10:27
対応状況: −−−
|
神 登録日: 2016/7/22 居住地: 投稿: 2085 |
Re: Customizeフォルダーでのカスタマイズ方法 Call to a member function find() on null
FatalThrowableError 継承元(parent)のコンストラクタを呼ぶか、Customize\Service\CsvExportService;のコンストラクタにも下記のプロパティ代入を追記してもらえれば、そのエラーは出なくなると思います。 継承元のコンストラクタ
|
jacker |
投稿日時: 2019/12/12 14:16
対応状況: −−−
|
新米 登録日: 2019/7/10 居住地: 投稿: 10 |
Re: Customizeフォルダーでのカスタマイズ方法 umebiusさん。こんにちは。
ありがとうございます。できました。! なんとなく、理解できてきました。追加したほうにも親側の引数でセットされる 内容を新しく作った方にもつけないといけないということですね。 自分が追加した機能だけで追加すれば、他は引き継がれるかと思っておりました。 __construct自体はnewで宣言されたときにセットされるので追加した方にも 同様のものがないと引き継いでくれないという認識でよいのでしょうか? |
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | トップ |