<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller\Mypage;
use Eccube\Controller\AbstractController;
use Eccube\Controller\Mypage\MypageController as BaseMypageController;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Customer;
use Eccube\Entity\Product;
use Eccube\Entity\Order;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Exception\CartException;
use Eccube\Entity\ExportCsvRow;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Master\CsvType;
use Eccube\Form\Type\Front\CustomerLoginType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerFavoriteProductRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\Master\OrderStatusRepository;
use Customize\Repository\CashbackSummaryRepository;
use Customize\Repository\OrderCashbackRepository;
use Customize\Repository\NotificationRepository;
use Customize\Repository\FCMHistoryRepository;
use Eccube\Repository\ProductRepository;
use Eccube\Service\CartService;
use Customize\Service\CsvExportService;
use Customize\Service\DzxPdfService;
use Customize\Service\CashbackService;
use Customize\Service\ProductService;
use Customize\Service\OrderStateMachine;
use Customize\Service\NotificationService;
use Customize\Service\MailService;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
// ▼ファイルアップロード
use Customize\Entity\Myimage;
use Customize\Repository\MyimageRepository;
class CustomMypageController extends BaseMypageController
{
/**
* @var CsvExportService
*/
protected $csvExportService;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var ProductService
*/
protected $productService;
/**
* @var CashbackService
*/
protected $cashbackService;
/** @var DzxPdfService */
protected $dzxPdfService;
/**
* @var CustomerFavoriteProductRepository
*/
protected $customerFavoriteProductRepository;
/**
* @var BaseInfo
*/
protected $BaseInfo;
/**
* @var CartService
*/
protected $cartService;
/**
* @var OrderRepository
*/
protected $orderRepository;
/**
* @var NotificationRepository
*/
protected $notificationRepository;
/**
* @var NotificationService
*/
protected $notificationService;
/**
* @var FCMHistoryRepository
*/
protected $fCMHistoryRepository;
/**
* @var OrderStatusRepository
*/
protected $orderStatusRepository;
/**
* @var OrderStateMachine
*/
protected $orderStateMachine;
/**
* @var OrderCashbackRepository
*/
protected $orderCashbackRepository;
/**
* @var CashbackSummaryRepository
*/
protected $cashbackSummaryRepository;
/**
* @var PurchaseFlow
*/
protected $purchaseFlow;
/** ▼ファイルアップロード
* @var MyimageRepository
*/
protected $myimageRepository;
/**
* @var MailService
*/
protected $mailService;
/**
* MypageController constructor.
*
* @param CsvExportService $csvExportService
* @param MyimageRepository $myimageRepository ▼ファイルアップロード
* @param OrderRepository $orderRepository
* @param OrderStatusRepository $orderStatusRepository
* @param OrderCashbackRepository $orderCashbackRepository
* @param OrderStateMachine $orderStateMachine
* @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
* @param CartService $cartService
* @param BaseInfoRepository $baseInfoRepository
* @param PurchaseFlow $purchaseFlow
*/
public function __construct(
CsvExportService $csvExportService,
ProductService $productService,
CashbackService $cashbackService,
MyimageRepository $myimageRepository, // ▼ファイルアップロード
OrderRepository $orderRepository,
OrderStatusRepository $orderStatusRepository,
OrderCashbackRepository $orderCashbackRepository,
NotificationRepository $notificationRepository,
NotificationService $notificationService,
FCMHistoryRepository $fCMHistoryRepository,
OrderStateMachine $orderStateMachine,
CashbackSummaryRepository $cashbackSummaryRepository,
DzxPdfService $dzxPdfService,
CustomerFavoriteProductRepository $customerFavoriteProductRepository,
CartService $cartService,
BaseInfoRepository $baseInfoRepository,
PurchaseFlow $purchaseFlow,
MailService $mailService
) {
$this->csvExportService = $csvExportService;
$this->productService = $productService;
$this->cashbackService = $cashbackService;
$this->myimageRepository = $myimageRepository; // ▼ファイルアップロード
$this->orderRepository = $orderRepository;
$this->orderStatusRepository = $orderStatusRepository;
$this->orderCashbackRepository = $orderCashbackRepository;
$this->notificationRepository = $notificationRepository;
$this->notificationService = $notificationService;
$this->orderStateMachine = $orderStateMachine;
$this->cashbackSummaryRepository = $cashbackSummaryRepository;
$this->customerFavoriteProductRepository = $customerFavoriteProductRepository;
$this->dzxPdfService = $dzxPdfService;
$this->BaseInfo = $baseInfoRepository->get();
$this->fCMHistoryRepository = $fCMHistoryRepository;
$this->cartService = $cartService;
$this->purchaseFlow = $purchaseFlow;
$this->mailService = $mailService;
}
/**
* ログイン画面.
*
* @Route("/mypage/login", name="mypage_login")
* @Template("Mypage/login.twig")
*/
public function login(Request $request, AuthenticationUtils $utils)
{
return $this->loginapp($request, $utils, false);
}
/**
* ログイン画面.
*
* @Route("/mypage/login/{isApp}", name="mypage_login_isapp")
* @Template("Mypage/login.twig")
*/
public function loginapp(Request $request, AuthenticationUtils $utils, $isApp)
{
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
log_info('認証済のためログイン処理をスキップ');
return $this->redirectToRoute('mypage');
/*
if($request->get("isApp")=="1"){
$appVer = $request->get("appVer");
$os = $request->get("os");
$params = array('isApp' => '1','os' => $os,'appVer' => $appVer);
return $this->redirectToRoute('mypage', $params);
}else{
return $this->redirectToRoute('mypage');
}
*/
}
/* @var $form \Symfony\Component\Form\FormInterface */
$builder = $this->formFactory
->createNamedBuilder('', CustomerLoginType::class);
$builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$Customer = $this->getUser();
if ($Customer instanceof Customer) {
$builder->get('login_email')
->setData($Customer->getEmail());
}
$this->refreshNotificationCount();
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE);
$form = $builder->getForm();
return [
'error' => $utils->getLastAuthenticationError(),
'form' => $form->createView(),
'isApp' => $isApp
];
}
/**
* マイページ.
*
* @Route("/mypage/", name="mypage")
* @Template("Mypage/index.twig")
*/
public function index(Request $request, PaginatorInterface $paginator)
{
$Customer = $this->getUser();
$shareKey = $this->productService->getEncodeByShareID($Customer->getId());
$showIntro = $this->BaseInfo->getOptionOrderShowIntro();
// 購入処理中/決済処理中ステータスの受注を非表示にする.
$this->entityManager
->getFilters()
->enable('incomplete_order_status_hidden');
// paginator
$qb = $this->orderRepository->getQueryBuilderByCustomer($Customer);
$event = new EventArgs(
[
'qb' => $qb,
'Customer' => $Customer,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH);
$pagination = $paginator->paginate(
$qb,
$request->get('pageno', 1),
$this->eccubeConfig['eccube_search_pmax']
);
$this->refreshNotificationCount();
return [
'showIntro' => $showIntro,
'shareKey' => $shareKey,
'pagination' => $pagination,
];
}
/**
* ランキング情報.
*
* @Route("/mypage/ranking/", name="mypage_ranking")
* @Template("Mypage/ranking.twig")
*/
public function ranking(Request $request, PaginatorInterface $paginator)
{
$Customer = $this->getUser();
$shareKey = $this->productService->getEncodeByShareID($Customer->getId());
//Summary
$rsProductList = $this->cashbackService->getCustomerProductList($Customer);
$selCount = count($rsProductList);
$this->refreshNotificationCount();
return [
'shareKey' => $shareKey,
'selCount' => $selCount,
'productList' => $rsProductList,
];
}
/**
* ランキング明細情報. (ランキングトップ50位を表示する)
*
* @Route("/mypage/ranking_detail/{id}", name="mypage_ranking_detail")
* @Template("Mypage/ranking_detail.twig")
*/
public function ranking_detail(Request $request, $id)
{
$Customer = $this->getUser();
$productList = null;
$rsRankingList = null;
$issucceeded = false;
$totalCount = 0;
$maxCashback = $this->BaseInfo->getOptionDzxMaxCashback(); //キャッシュバック上限
$productId = $this->productService->decodeId($id);
//ProductList
//$productList = $this->cashbackSummaryRepository->getRankProduct($productId);
$productList = $this->cashbackService->getRankingList($Customer, $productId);
//Cashback Count Total
$rsCountTotal = $this->cashbackSummaryRepository->getCashbackFinishedTotal($productId, $maxCashback);
//Ranking List
$rsRankingList = $this->cashbackSummaryRepository->getRankListByDetail($productId, $maxCashback);
$this->refreshNotificationCount();
foreach($rsCountTotal as $item){
if($item["customerId"] == $Customer->getId()){
$issucceeded = true;
break;
}
}
$hasRankingList = sizeof($rsRankingList);
$hasProductList = sizeof($productList);
$totalCount = sizeof($rsCountTotal);
return [
'id' => $id,
'hasProductList' => $hasProductList,
'productList' => $productList,
'hasRankingList' => $hasRankingList,
'rankingList' => $rsRankingList,
'totalCount' => $totalCount,
'issucceeded' => $issucceeded,
'Customer' => $Customer,
];
}
/**
* お知らせ確認.
*
* @Route("/mypage/notification/", name="mypage_notification")
* @Template("Mypage/notification.twig")
*/
public function myNotification(Request $request, PaginatorInterface $paginator)
{
$Customer = $this->getUser();
//Detail
$qb = $this->notificationRepository->getQueryBuilderByDetail($Customer);
$pagination = $paginator->paginate(
$qb,
$request->get('pageno', 1),
$this->eccubeConfig['eccube_search_pmax']
);
$this->refreshNotificationCount();
return [
'pagination' => $pagination
];
}
/**
* お知らせ內容.
*
* @Route("/mypage/notification/{id}", name="mypage_notification_view")
* @Template("Mypage/notification_view.twig")
*/
public function myNotificationView(Request $request, $id)
{
$Customer = $this->getUser();
//Detail
$PreviousId = $this->notificationRepository->getPreviousRow($Customer, $id);
$NextId = $this->notificationRepository->getNextRow($Customer, $id);
$detail = $this->notificationRepository->findOneBy(['Customer' => $Customer, 'id'=>$id]);
$this->notificationService->plusNoticeViewCount($detail);
$this->refreshNotificationCount();
$newContents = $this->linkify($detail->getContents());
$detail->setContents($newContents);
$fcmlist = $this->fCMHistoryRepository->findBy(['Notification'=>$detail, 'Customer' => $Customer]);
return [
'PreviousId' => $PreviousId,
'NextId' => $NextId,
'detail' => $detail,
'fcmlist' => $fcmlist
];
}
/**
* 売上情報.
*
* @Route("/mypage/mysales/", name="mypage_mysales")
* @Template("Mypage/mysales.twig")
*/
public function mysales(Request $request, PaginatorInterface $paginator)
{
$Customer = $this->getUser();
$rsSummary = null;
$pageDetail = null;
$selDate = "";
$selDateName = "";
$selCount = 0;
$isShowCashbackAlert = true;
$showIntro = $this->BaseInfo->getOptionOrderShowIntro();
// 購入処理中/決済処理中ステータスの受注を非表示にする.
$this->entityManager
->getFilters()
->enable('incomplete_order_status_hidden');
// get date list
$lstDate = $this->cashbackSummaryRepository->getListDate($Customer);
$selCount = count($lstDate);
if(!empty($_SESSION["selDate"])){
$selDate = $_SESSION["selDate"];
$selDateName = str_replace("-", "年", $selDate)."月";
}
if(!empty($_POST)){
if(!empty($_POST["selDate"])){
$selDate = $_POST["selDate"];
$selDateName = str_replace("-", "年", $selDate)."月";
$_SESSION["selDate"]=$selDate;
}
}
if($selCount > 0){
if($selDate == ""){
$selDate = $lstDate[0]["dateVal"];
$selDateName = str_replace("-", "年", $selDate)."月";
}
//Summary
$rsSummary = $this->cashbackSummaryRepository->getQueryBuilderBySummary($Customer, $selDate);
//Detail
$qDetail = $this->orderCashbackRepository->getQueryBuilderByDetail($Customer, $selDate);
$pageDetail = $paginator->paginate(
$qDetail,
$request->get('pageno', 1),
$this->eccubeConfig['eccube_search_pmax']
);
}
$this->refreshNotificationCount();
//口座チェック
if($Customer != null){
if( $Customer->getBankName() != null && $Customer->getBankName() != "0" &&
$Customer->getBankBranchCode() != null && $Customer->getBankBranchCode() !="0" &&
$Customer->getBankAccount() != null && $Customer->getBankAccount() != "" ){
$isShowCashbackAlert = false;
}
}
return [
'showIntro' => $showIntro,
'selDate' => $selDate,
'selDateName' => $selDateName,
'selCount' => $selCount,
'listDate' => $lstDate,
'rsSummary' => $rsSummary,
'rsDetail' => $pageDetail,
'showCashbackAlert' => $isShowCashbackAlert
];
}
/**
* 商品PDFの出力.
*
* @Route("/mypage/mysales/exportpdf/summary/{selDate}", name="mypage_mysales_exportpdf_summary")
*
* @param Request $request
*
* @return StreamedResponse
*/
public function exportPdfSummary(Request $request, $selDate){
$arrData = [];
$arrData["issue_date"] = new \DateTime();
$arrData["ids"] = "32";
$arrData["title"] = "test";
// 情報からPDFを作成する
$status = $this->dzxPdfService->makePdf($arrData);
// 異常終了した場合の処理
if (!$status) {
$this->addError('admin.order.export.pdf.download.failure', 'admin');
log_info('Unable to create pdf files! Process have problems!');
return $this->render('@admin/Order/order_pdf.twig', [
'form' => $form->createView(),
]);
}
// ダウンロードする
$response = new Response(
$this->dzxPdfService->outputPdf(),
200,
['content-type' => 'application/pdf']
);
$response->headers->set('Content-Disposition', 'attachment; filename="'.$this->dzxPdfService->getPdfFileName().'"');
return $response;
}
/**
* 商品CSVの出力.
*
* @Route("/mypage/mysales/export/summary/{selDate}", name="mypage_mysales_export_summary")
*
* @param Request $request
*
* @return StreamedResponse
*/
public function exportSummary(Request $request, $selDate)
{
// タイムアウトを無効にする.
set_time_limit(0);
// sql loggerを無効にする.
$em = $this->entityManager;
$em->getConfiguration()->setSQLLogger(null);
$Customer = $this->getUser();
$filename = "summary_".$Customer->getId()."-".$selDate."-".date("Ymd").".csv";
$response = new StreamedResponse();
$response->setCallback(function () use ($request, $selDate, $Customer, $filename) {
// 商品データ検索用のクエリビルダを取得.
$rsSummary = $this->cashbackSummaryRepository->getQueryBuilderBySummary($Customer, $selDate);
// データ行の出力.
$header = [];
$header[] = "商品名称";
$header[] = "キャシュバック予定金額";
$header[] = "キャシュバック金額";
$header[] = "キャシュバック日付";
$header[] = "単価";
$header[] = "全体販売数量";
$header[] = "全体販売売上";
$header[] = "シェアポイント";
$header[] = "販売売上";
if($request->get("isApp")=="1"){
$this->csvExportService->fopen(__DIR__."/../../../../file/".$filename);
}else{
$this->csvExportService->fopen();
}
$this->csvExportService->fputcsv($header);
//
foreach($rsSummary as $row){
$data = [];
$data[] = $row["productName"];
$data[] = "¥".number_format($row["preAmt"]);
$data[] = "¥".number_format($row["finalAmt"]);
$data[] = ($row["paymentDate"] == null ? "" : date_format($row["paymentDate"], 'Y/m/d'));
$product = $row["Product"];
if($product->hasProductClass()){
if($product->getPrice02IncTaxMin() == $product->getPrice02IncTaxMax()){
$data[] = "¥".number_format($product->getPrice02IncTaxMin());
}else{
$data[] = "¥".number_format($product->getPrice02IncTaxMin())."~".number_format($product->getPrice02IncTaxMax());
}
}else{
$data[] = "¥".number_format($product->getPrice02IncTaxMin());
}
//$data[] = "¥".number_format($row["price"]);
$data[] = number_format($row["quantity"]);
$data[] = "¥".number_format($row["salesAmt"]);
$data[] = number_format($row["sharePoint"]);
$data[] = "¥".number_format($row["shareSalesAmt"]);
$this->csvExportService->fputcsv($data);
}
$this->csvExportService->fclose();
});
if($request->get("isApp")=="1"){
$url = "";
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){
$url = "https://";
}else{
$url = "http://";
}
$url.= $_SERVER['HTTP_HOST'];
echo $url."/file/".$filename;
}else{
$now = new \DateTime();
$filename = 'summary_'.$now->format('YmdHis').'.csv';
$response->headers->set('Content-Type', 'application/octet-stream');
$response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
$response->send();
log_info('商品CSV出力ファイル名', [$filename]);
}
return $response;
}
/**
* 商品CSVの出力.
*
* @Route("/mypage/mysales/export/detail/{selDate}", name="mypage_mysales_export_detail")
*
* @param Request $request
*
* @return StreamedResponse
*/
public function exportDetail(Request $request, $selDate)
{
// タイムアウトを無効にする.
set_time_limit(0);
// sql loggerを無効にする.
$em = $this->entityManager;
$em->getConfiguration()->setSQLLogger(null);
$Customer = $this->getUser();
$filename = "detail_".$Customer->getId()."-".$selDate."-".date("Ymd").".csv";
$response = new StreamedResponse();
$response->setCallback(function () use ($request, $selDate, $Customer, $filename) {
// 商品データ検索用のクエリビルダを取得.
$rsDetail = $this->orderCashbackRepository->getQueryBuilderByDetailResult($Customer, $selDate);
// データ行の出力.
$header = [];
$header[] = "購入日付";
$header[] = "注文番号";
$header[] = "売上区分";
$header[] = "商品名称";
$header[] = "単価";
$header[] = "販売数量";
$header[] = "販売売上";
$header[] = "シェアポイント";
$header[] = "シェア売上";
if($request->get("isApp")=="1"){
$this->csvExportService->fopen(__DIR__."/../../../../file/".$filename);
}else{
$this->csvExportService->fopen();
}
$this->csvExportService->fputcsv($header);
//
foreach($rsDetail as $row){
$data = [];
$data[] = ($row["Order"]["order_date"] == null ? "" : date_format($row["Order"]["order_date"], 'Y/m/d'));
$data[] = $row["Order"]["id"];
$data[] = $row["SalesStatus"]["name"];
$data[] = $row["productName"];
$data[] = "¥".number_format($row["price"]);
$data[] = number_format($row["quantity"]);
$data[] = "¥".number_format($row["salesAmt"]);
$data[] = number_format($row["sharePoint"]);
$data[] = "¥".number_format($row["shareSalesAmt"]);
$this->csvExportService->fputcsv($data);
}
$this->csvExportService->fclose();
});
if($request->get("isApp")=="1"){
$url = "";
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'){
$url = "https://";
}else{
$url = "http://";
}
$url.= $_SERVER['HTTP_HOST'];
echo $url."/file/".$filename;
}else{
$now = new \DateTime();
$filename = 'detail_'.$now->format('YmdHis').'.csv';
$response->headers->set('Content-Type', 'application/octet-stream');
$response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
$response->send();
log_info('商品CSV出力ファイル名', [$filename]);
}
return $response;
}
/**
* 取消訂單
*
* @Route("/mypage/cancel/{order_no}", name="mypage_cancel")
* @Template("Mypage/history.twig")
*/
public function cancelOrder(Request $request, $order_no)
{
$this->entityManager->getFilters()
->enable('incomplete_order_status_hidden');
$Order = $this->orderRepository->findOneBy(
[
'order_no' => $order_no,
'Customer' => $this->getUser(),
]
);
if (!$Order) {
throw new NotFoundHttpException();
}
$OrderStatus = $this->orderStatusRepository->findOneBy(['id' => OrderStatus::CANCEL]);
$orderStatus = $Order->getOrderStatus();
//只有 新規受付、入金済み 可以取消訂單
if($orderStatus->getId()==1 || $orderStatus->getId()==6){
//由 EC-Cube 判定是否能變更
if ($this->orderStateMachine->can($Order, $OrderStatus)) {
$this->orderStateMachine->apply($Order, $OrderStatus);
$this->entityManager->flush($Order);
/*
$Shippings = $Order->getShippings();
foreach ($Shippings as $Ship) {
$this->mailService->sendShippingNotifyMail($Ship);
$Ship->setMailSendDate(new \DateTime());
}
*/
$this->cashbackService->updateOrderStatus($Order, $OrderStatus);
}
}
$this->history($request, $order_no);
return $this->redirect($this->generateUrl('mypage_history', ["order_no" => $order_no]));
}
/**
* 購入履歴詳細を表示する.
*
* @Route("/mypage/history/{order_no}", name="mypage_history", methods={"GET"})
* @Template("Mypage/history.twig")
*/
public function history(Request $request, $order_no)
{
$this->entityManager->getFilters()
->enable('incomplete_order_status_hidden');
$Order = $this->orderRepository->findOneBy(
[
'order_no' => $order_no,
'Customer' => $this->getUser(),
]
);
$event = new EventArgs(
[
'Order' => $Order,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_MYPAGE_HISTORY_INITIALIZE);
/** @var Order $Order */
$Order = $event->getArgument('Order');
if (!$Order) {
throw new NotFoundHttpException();
}
//是否能取消訂單
$cancelOrder = false;
$orderStatus = $Order->getOrderStatus();
if($orderStatus->getId()==1 || $orderStatus->getId()==6){
$cancelOrder = true;
}
$stockOrder = true;
foreach ($Order->getOrderItems() as $orderItem) {
if ($orderItem->isProduct() && $orderItem->getQuantity() < 0) {
$stockOrder = false;
break;
}
}
// ▼マイページアップロード
$Myimages = $this->myimageRepository
->findBy(
['visible' => true, 'order_no' => $order_no, 'fixed' => 3],
['sort_no' => 'ASC']
);
// ▼管理画面アップロード
$adminMyimages = $this->myimageRepository
->findBy(
['visible' => true, 'order_no' => $order_no, 'fixed' => 2],
['sort_no' => 'ASC']
);
return [
'Order' => $Order,
'cancelOrder' => $cancelOrder,
'stockOrder' => $stockOrder,
'Myimages' => $Myimages, //▼マイページアップロード
'adminMyimages' => $adminMyimages, //▼管理画面アップロード
];
}
/**
* ▼領収書/購入明細書
*
* @Route("/mypage/receipt/{order_no}", name="mypage_receipt")
* @Template("Mypage/receipt.twig")
*/
public function receipt(Request $request, $order_no)
{
$this->entityManager->getFilters()
->enable('incomplete_order_status_hidden');
$Order = $this->orderRepository->findOneBy(
[
'order_no' => $order_no,
'Customer' => $this->getUser(),
]
);
$event = new EventArgs(
[
'Order' => $Order,
],
$request
);
/** @var Order $Order */
$Order = $event->getArgument('Order');
if (!$Order) {
throw new NotFoundHttpException();
}
$stockOrder = true;
foreach ($Order->getOrderItems() as $orderItem) {
if ($orderItem->isProduct() && $orderItem->getQuantity() < 0) {
$stockOrder = false;
break;
}
}
return [
'Order' => $Order,
'stockOrder' => $stockOrder,
];
}
private function refreshNotificationCount(){
$Customer = $this->getUser();
$cnt = $this->notificationService->getNoticeViewCount($Customer);
$session = $this->get('session');
$session->set('notificationCount', $cnt);
}
private function linkify($text)
{
$re = "@\b(https?://)?(([0-9a-zA-Z_!~*'().&=+$%-]+:)?[0-9a-zA-Z_!~*'().&=+$%-]+\@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\@&=+$,%#-]+)*/?)@";
preg_match_all($re, $text, $matches, PREG_OFFSET_CAPTURE);
$matches = $matches[0];
$i = count($matches);
while ($i--)
{
$url = $matches[$i][0];
if (!preg_match('@^https?://@', $url))
$url = 'http://'.$url;
$text = substr_replace($text, '<a href="'.$url.'" target="_blank">'.$matches[$i][0].'</a>', $matches[$i][1], strlen($matches[$i][0]));
}
return $text;
}
}