public function mailAll(Application $app, Request $request) { $builder = $app['form.factory']->createBuilder('mail'); $form = $builder->getForm(); $ids = ''; if ('POST' === $request->getMethod()) { $form->handleRequest($request); $mode = $request->get('mode'); $ids = $request->get('ids'); // テンプレート変更の場合は. バリデーション前に内容差し替え. if ($mode == 'change') { if ($form->get('template')->isValid()) { /** @var $data \Eccube\Entity\MailTemplate */ $MailTemplate = $form->get('template')->getData(); $form = $builder->getForm(); $form->get('template')->setData($MailTemplate); $form->get('subject')->setData($MailTemplate->getSubject()); $form->get('header')->setData($MailTemplate->getHeader()); $form->get('footer')->setData($MailTemplate->getFooter()); } } else { if ($form->isValid()) { switch ($mode) { case 'confirm': // フォームをFreezeして再生成. $builder->setAttribute('freeze', true); $builder->setAttribute('freeze_display_text', true); $data = $form->getData(); $tmp = explode(',', $ids); $Order = $app['eccube.repository.order']->find($tmp[0]); if (is_null($Order)) { throw new NotFoundHttpException('order not found.'); } $body = $this->createBody($app, $data['header'], $data['footer'], $Order); $MailTemplate = $form->get('template')->getData(); $form = $builder->getForm(); $form->setData($data); $form->get('template')->setData($MailTemplate); return $app->renderView('Order/mail_all_confirm.twig', array('form' => $form->createView(), 'body' => $body, 'ids' => $ids)); break; case 'complete': $data = $form->getData(); $ids = explode(',', $ids); foreach ($ids as $value) { $Order = $app['eccube.repository.order']->find($value); $body = $this->createBody($app, $data['header'], $data['footer'], $Order); // メール送信 $app['eccube.service.mail']->sendAdminOrderMail($Order, $data); // 送信履歴を保存. $MailTemplate = $form->get('template')->getData(); $MailHistory = new MailHistory(); $MailHistory->setSubject($data['subject'])->setMailBody($body)->setMailTemplate($MailTemplate)->setSendDate(new \DateTime())->setOrder($Order); $app['orm.em']->persist($MailHistory); } $app['orm.em']->flush($MailHistory); return $app->redirect($app->url('admin_order_mail_complete')); break; default: break; } } } } else { foreach ($_GET as $key => $value) { $ids = str_replace('ids', '', $key) . ',' . $ids; } $ids = substr($ids, 0, -1); } return $app->renderView('Order/mail_all.twig', array('form' => $form->createView(), 'ids' => $ids)); }
/** * 受注メール送信を行う * * @param Order $Order * @return MailHistory */ public function sendOrderMail(Order $Order) { // メール送信 $message = $this->app['eccube.service.mail']->sendOrderMail($Order); // 送信履歴を保存. $MailTemplate = $this->app['eccube.repository.mail_template']->find(1); $MailHistory = new MailHistory(); $MailHistory->setSubject($message->getSubject())->setMailBody($message->getBody())->setMailTemplate($MailTemplate)->setSendDate(new \DateTime())->setOrder($Order); $this->app['orm.em']->persist($MailHistory); $this->app['orm.em']->flush($MailHistory); return $MailHistory; }
/** * 購入処理 */ public function confirm(Application $app, Request $request) { $cartService = $app['eccube.service.cart']; // カートチェック if (!$cartService->isLocked()) { // カートが存在しない、カートがロックされていない時はエラー return $app->redirect($app->url('cart')); } $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); if (!$Order) { $app->addError('front.shopping.order.error'); return $app->redirect($app->url('shopping_error')); } if ('POST' !== $request->getMethod()) { return $app->redirect($app->url('cart')); } // form作成 $form = $app['eccube.service.shopping']->getShippingForm($Order); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); // トランザクション制御 $em = $app['orm.em']; $em->getConnection()->beginTransaction(); try { // 商品公開ステータスチェック、商品制限数チェック、在庫チェック $check = $app['eccube.service.shopping']->isOrderProduct($em, $Order); if (!$check) { $em->getConnection()->rollback(); $app->addError('front.shopping.stock.error'); return $app->redirect($app->url('shopping_error')); } // 受注情報、配送情報を更新 $app['eccube.service.shopping']->setOrderUpdate($Order, $data); // 在庫情報を更新 $app['eccube.service.shopping']->setStockUpdate($em, $Order); if ($app->isGranted('ROLE_USER')) { // 会員の場合、購入金額を更新 $app['eccube.service.shopping']->setCustomerUpdate($Order, $app->user()); } $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { $em->getConnection()->rollback(); $app->log($e); $app->addError('front.shopping.system.error'); return $app->redirect($app->url('shopping_error')); } // カート削除 $app['eccube.service.cart']->clear()->save(); // メール送信 $app['eccube.service.mail']->sendOrderMail($Order); // 受注IDをセッションにセット $app['session']->set($this->sessionOrderKey, $Order->getId()); // 送信履歴を保存. $MailTemplate = $app['eccube.repository.mail_template']->find(1); $body = $app->renderView($MailTemplate->getFileName(), array('header' => $MailTemplate->getHeader(), 'footer' => $MailTemplate->getFooter(), 'Order' => $Order)); $MailHistory = new MailHistory(); $MailHistory->setSubject('[' . $app['eccube.repository.base_info']->get()->getShopName() . '] ' . $MailTemplate->getSubject())->setMailBody($body)->setMailTemplate($MailTemplate)->setSendDate(new \DateTime())->setOrder($Order); $app['orm.em']->persist($MailHistory); $app['orm.em']->flush($MailHistory); // 完了画面表示 return $app->redirect($app->url('shopping_complete')); } return $app->render('Shopping/index.twig', array('form' => $form->createView(), 'Order' => $Order)); }
public function mailAll(Application $app, Request $request) { $builder = $app['form.factory']->createBuilder('mail'); $event = new EventArgs(array('builder' => $builder), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_INITIALIZE, $event); $form = $builder->getForm(); $ids = ''; if ('POST' === $request->getMethod()) { $form->handleRequest($request); $mode = $request->get('mode'); $ids = $request->get('ids'); // テンプレート変更の場合は. バリデーション前に内容差し替え. if ($mode == 'change') { if ($form->get('template')->isValid()) { /** @var $data \Eccube\Entity\MailTemplate */ $MailTemplate = $form->get('template')->getData(); $form = $builder->getForm(); $event = new EventArgs(array('form' => $form, 'MailTemplate' => $MailTemplate), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_CHANGE, $event); $form->get('template')->setData($MailTemplate); $form->get('subject')->setData($MailTemplate->getSubject()); $form->get('header')->setData($MailTemplate->getHeader()); $form->get('footer')->setData($MailTemplate->getFooter()); } } else { if ($form->isValid()) { switch ($mode) { case 'confirm': // フォームをFreezeして再生成. $builder->setAttribute('freeze', true); $builder->setAttribute('freeze_display_text', true); $data = $form->getData(); $tmp = explode(',', $ids); $Order = $app['eccube.repository.order']->find($tmp[0]); if (is_null($Order)) { throw new NotFoundHttpException('order not found.'); } $body = $this->createBody($app, $data['header'], $data['footer'], $Order); $MailTemplate = $form->get('template')->getData(); $form = $builder->getForm(); $event = new EventArgs(array('form' => $form, 'MailTemplate' => $MailTemplate, 'Order' => $Order), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_CONFIRM, $event); $form->setData($data); $form->get('template')->setData($MailTemplate); return $app->render('Order/mail_all_confirm.twig', array('form' => $form->createView(), 'body' => $body, 'ids' => $ids)); break; case 'complete': $data = $form->getData(); $ids = explode(',', $ids); foreach ($ids as $value) { $Order = $app['eccube.repository.order']->find($value); $body = $this->createBody($app, $data['header'], $data['footer'], $Order); // メール送信 $app['eccube.service.mail']->sendAdminOrderMail($Order, $data); // 送信履歴を保存. $MailTemplate = $form->get('template')->getData(); $MailHistory = new MailHistory(); $MailHistory->setSubject($data['subject'])->setMailBody($body)->setMailTemplate($MailTemplate)->setSendDate(new \DateTime())->setOrder($Order); $app['orm.em']->persist($MailHistory); } $app['orm.em']->flush($MailHistory); $event = new EventArgs(array('form' => $form, 'MailHistory' => $MailHistory), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_COMPLETE, $event); return $app->redirect($app->url('admin_order_mail_complete')); break; default: break; } } } } else { $filter = function ($v) { return preg_match('/^ids\\d+$/', $v); }; $map = function ($v) { return preg_replace('/[^\\d+]/', '', $v); }; $keys = array_keys($request->query->all()); $idArray = array_map($map, array_filter($keys, $filter)); $ids = implode(',', $idArray); } return $app->render('Order/mail_all.twig', array('form' => $form->createView(), 'ids' => $ids)); }