<?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;
use Customize\Entity\School;
use Customize\Form\Type\MatomeCartType;
use Eccube\Controller\AbstractController;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Master\ProductStatus;
use Eccube\Entity\Product;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\AddCartType;
use Eccube\Form\Type\Master\ProductListMaxType;
use Eccube\Form\Type\Master\ProductListOrderByType;
use Eccube\Form\Type\SearchProductType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerFavoriteProductRepository;
use Eccube\Repository\Master\ProductListMaxRepository;
use Customize\Repository\ProductRepository;
use Customize\Repository\RecommendXRepository;
use Customize\Repository\RecommendYRepository;
use Customize\Repository\RecommendSizeRepository;
use Customize\Repository\ProductSchoolRepository;
use Customize\Repository\SetProductRepository;
use Customize\Repository\SchoolRepository;
use Eccube\Repository\ProductClassRepository;
use Customize\Service\CartService;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Customize\Repository\BrotherRepository;
class ProductController extends AbstractController
{
/**
* @var PurchaseFlow
*/
protected $purchaseFlow;
/**
* @var CustomerFavoriteProductRepository
*/
protected $customerFavoriteProductRepository;
/**
* @var CartService
*/
protected $cartService;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var BaseInfo
*/
protected $BaseInfo;
/**
* @var AuthenticationUtils
*/
protected $helper;
/**
* @var ProductListMaxRepository
*/
protected $productListMaxRepository;
private $title = '';
/**
* @var RecommendXRepository
*/
protected $recommendXRepository;
/**
* @var RecommendYRepository
*/
protected $recommendYRepository;
/**
* @var RecommendSizeRepository
*/
protected $recommendSizeRepository;
/**
* @var ProductSchoolRepository
*/
protected $productSchoolRepository;
/**
* @var SetProductRepository
*/
protected $setProductRepository;
/**
* @var SchoolRepository
*/
protected $schoolRepository;
/**
* @var ProductClassRepository
*/
protected $productClassRepository;
/**
* @var BrotherRepository
*/
protected $brotherRepository;
/**
* ProductController constructor.
*
* @param PurchaseFlow $cartPurchaseFlow
* @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
* @param CartService $cartService
* @param ProductRepository $productRepository
* @param BaseInfoRepository $baseInfoRepository
* @param AuthenticationUtils $helper
* @param ProductListMaxRepository $productListMaxRepository
* @param RecommendXRepository $recommendXRepository
* @param RecommendYRepository $recommendYRepository
* @param RecommendSizeRepository $recommendSizeRepository
* @param ProductSchoolRepository $productSchoolRepository
* @param SetProductRepository $setProductRepository
* @param SchoolRepository $schoolRepository
* @param ProductClassRepository $productClassRepository
*/
public function __construct(
PurchaseFlow $cartPurchaseFlow,
CustomerFavoriteProductRepository $customerFavoriteProductRepository,
CartService $cartService,
ProductRepository $productRepository,
BaseInfoRepository $baseInfoRepository,
AuthenticationUtils $helper,
ProductListMaxRepository $productListMaxRepository,
RecommendXRepository $recommendXRepository,
RecommendYRepository $recommendYRepository,
RecommendSizeRepository $recommendSizeRepository,
ProductSchoolRepository $productSchoolRepository ,
SetProductRepository $setProductRepository,
SchoolRepository $schoolRepository,
ProductClassRepository $productClassRepository,
BrotherRepository $brotherRepository
) {
$this->purchaseFlow = $cartPurchaseFlow;
$this->customerFavoriteProductRepository = $customerFavoriteProductRepository;
$this->cartService = $cartService;
$this->productRepository = $productRepository;
$this->BaseInfo = $baseInfoRepository->get();
$this->helper = $helper;
$this->productListMaxRepository = $productListMaxRepository;
$this->recommendXRepository = $recommendXRepository;
$this->recommendYRepository = $recommendYRepository;
$this->recommendSizeRepository = $recommendSizeRepository;
$this->productSchoolRepository = $productSchoolRepository;
$this->setProductRepository = $setProductRepository;
$this->schoolRepository = $schoolRepository;
$this->productClassRepository = $productClassRepository;
$this->brotherRepository = $brotherRepository;
}
/**
* 商品一覧画面.
*
* @Route("/products/list", name="product_list", methods={"GET", "POST"})
* @Template("Product/list.twig")
*/
public function index(Request $request, PaginatorInterface $paginator)
{
// Doctrine SQLFilter
if ($this->BaseInfo->isOptionNostockHidden()) {
$this->entityManager->getFilters()->enable('option_nostock_hidden');
}
// handleRequestは空のqueryの場合は無視するため
if ($request->getMethod() === 'GET') {
$request->query->set('pageno', $request->query->get('pageno', ''));
}
// searchForm
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */
$builder = $this->formFactory->createNamedBuilder('', SearchProductType::class);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
/* @var $searchForm \Symfony\Component\Form\FormInterface */
$searchForm = $builder->getForm();
$searchForm->handleRequest($request);
// paginator
$searchData = $searchForm->getData();
$Customer = $this->getUser();
$brother_id = $request->get('brother_id', '');
if (!empty($brother_id)) {
$Brother = $this->brotherRepository->find($brother_id);
if ($Brother) {
$Customer = $Brother->getCustomer();
}
}
//default sex filtering
$School = $Customer->getSchool();
if($School->getDefaultSexProductsFilteringFlag() == 1){
$customer_sex = $Customer->getSex()->getId() == 1 ? '男子' : '女子';
$searchData['name'] = $customer_sex;
}
$temporaryOrder = false;
if(is_object($Customer) && !$this->session->get('update_temporary_order_id')){
if($School){
$this->session->set('storeMeasuringFlag', $School->getStoreMeasuringFlag());
$this->session->set('schoolMeasuringFlag', $School->getSchoolMeasuringFlag());
$this->session->set('onlineFlag', $School->getOnlineFlag());
if($this->session->get('temporary_order_id') || $School->getOnlineFlag() == 0){
$temporaryOrder = true;
}
else{
$temporaryOrder = false;
}
}
}
$searchData['school_id'] = $request->get('s');
$qb = $this->productRepository->getQueryBuilderBySearchData($searchData);
$event = new EventArgs(
[
'searchData' => $searchData,
'qb' => $qb,
],
$request
);
// $this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
$searchData = $event->getArgument('searchData');
$query = $qb->getQuery()
->useResultCache(true, $this->eccubeConfig['eccube_result_cache_lifetime_short']);
/** @var SlidingPagination $pagination */
if( $School->getItemVisibleType()==School::ITEM_VISIBLE_TYPE_MATOME){
$limit = 1000000;
}else{
$limit = !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId();
}
$pagination = $paginator->paginate(
$query,
!empty($searchData['pageno']) ? $searchData['pageno'] : 1,
$limit,array('wrap-queries' => true)
);
$ids = [];
foreach ($pagination as $Product) {
$ids[] = $Product->getId();
}
$ProductsAndClassCategories = $this->productRepository->findProductsWithSortedClassCategories($ids, 'p.id');
// addCart form
$forms = [];
$ProductInSets = [];
foreach ($pagination as $index=> $Product) {
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */
$builder = $this->formFactory->createNamedBuilder(
'',
AddCartType::class,
null,
[
'product' => $ProductsAndClassCategories[$Product->getId()],
'allow_extra_fields' => true,
]
);
$addCartForm = $builder->getForm();
$forms[$Product->getId()] = $addCartForm->createView();
$product_ids[$index]=$Product->getId();
if($Product->getProductType() == 'set'){
$ProductInSets[$Product->getId()] = [];
$pis_all = $this->setProductRepository->findOneBy(['set_product_id'=>$Product->getSetProductId()])->getSetProductProduct();
foreach($pis_all as $pis)
if( !in_array($pis->getProduct(), $ProductInSets[$Product->getId()]))
array_push($ProductInSets[$Product->getId()], $pis->getProduct());
}
}
// 表示件数
$builder = $this->formFactory->createNamedBuilder(
'disp_number',
ProductListMaxType::class,
null,
[
'required' => false,
'allow_extra_fields' => true,
]
);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_INDEX_DISP);
$dispNumberForm = $builder->getForm();
$dispNumberForm->handleRequest($request);
// ソート順
$builder = $this->formFactory->createNamedBuilder(
'orderby',
ProductListOrderByType::class,
null,
[
'required' => false,
'allow_extra_fields' => true,
]
);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_INDEX_ORDER);
$orderByForm = $builder->getForm();
$orderByForm->handleRequest($request);
$Category = $searchForm->get('category_id')->getData();
//まとめて購入処理 >>>
$builder = $this->formFactory->createNamedBuilder(
'',
MatomeCartType::class,
null,
[
'products' => $pagination,
'ProductInSets' => $ProductInSets,
'allow_extra_fields' => true,
]
);
/* @var $searchForm \Symfony\Component\Form\FormInterface */
$matomeForm = $builder->getForm();
$matomeForm->handleRequest($request);
$back = $request->get('back', false);
$refresh = $this->session->get('refresh', true);
if($back && $request->getMethod() == "GET" && !$refresh){
$old_matomete_items = $this->session->get('matomeItems');
foreach($old_matomete_items as $product_class_id => $omi){
$old_product_class = $this->productClassRepository->find($product_class_id);
if(isset($omi['set_product_class']['class_list'])){
$this->cartService->addProduct($old_product_class, -abs($omi['quantity']), $omi['set_product_class']['class_list'],null,null);
}
}
$Carts = $this->cartService->getCarts();
foreach ($Carts as $Cart) {
$result = $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart, $this->getUser()));
// 復旧不可のエラーが発生した場合は追加した明細を削除.
if ($result->hasError()) {
foreach($old_matomete_items as $product_class_id => $omi){
if(!empty($omi['quantity'])){
$this->cartService->removeProduct($omi['product_class_id']);
}
}
foreach ($result->getErrors() as $error) {
$errorMessages[] = $error->getMessage();
}
}
foreach ($result->getWarning() as $warning) {
$errorMessages[] = $warning->getMessage();
}
}
$this->cartService->save();
$refresh = $this->session->set('refresh', true);
}
if($matomeForm->isSubmitted() && $matomeForm->isValid()){
$data = $matomeForm->getData();
$isValid = false;
foreach ($data as $item){
foreach ($item as $cart_item){
if(!empty($cart_item['quantity'])){
$isValid = true;
}
}
}
if($isValid){
$mData = [];
//Go Shopping
foreach ($data as $itemKey => $item){
foreach ($item as $cart_index => $cart_item){
if(!empty($cart_item['quantity'])){
$cartProduct = $request->get($itemKey)[$cart_index];
$setProductClass = [];
foreach ($cartProduct as $attrKey => $attr){
if(!empty($attr['ProductClass'])){
$setProductClass[] = $attr['ProductClass'];
}
}
$this->cartService->addProduct($cart_item['product_class_id'], $cart_item['quantity'], $setProductClass, $cart_item['remarks'],null);
$mItem = [];
$mItem['quantity'] = $cart_item['quantity'];
$mItem['set_product_class'] = [];
foreach($setProductClass as $spc){
$spc_class = $this->productClassRepository->find($spc);
$productInSet = $spc_class->getProduct();
if($spc_class && $productInSet){
$spc_class_category1 = $spc_class->getClassCategory1();
$class_cat_tmp = [];
if($spc_class_category1){
$class_cat_tmp['class_category1_id'] = $spc_class_category1->getId();
}
$spc_class_category2 = $spc_class->getClassCategory2();
if($spc_class_category2){
$class_cat_tmp['class_category2_id'] = $spc_class_category2->getId();
}
$mItem['set_product_class'][$productInSet->getId()] = $class_cat_tmp;
$class_cat_tmp['product_class_id'] = $spc;
$mItem['set_product_class'][$productInSet->getId()] = $class_cat_tmp;
}
}
$mItem['set_product_class']['class_list'] = $setProductClass;
$mItem['remarks'] = $cart_item['remarks'];
$productClass = $this->productClassRepository->find($cart_item['product_class_id']);
if($productClass){
$product_class_category1 = $productClass->getClassCategory1();
if($product_class_category1){
$mItem['class_category1_id'] = $product_class_category1->getId();
}
$product_class_category2 = $productClass->getClassCategory2();
if($product_class_category2){
$mItem['class_category2_id'] = $product_class_category2->getId();
}
}
$mData[$cart_item['product_class_id']] = $mItem;
}
}
}
// 明細の正規化
$Carts = $this->cartService->getCarts();
foreach ($Carts as $Cart) {
$result = $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart, $this->getUser()));
// 復旧不可のエラーが発生した場合は追加した明細を削除.
if ($result->hasError()) {
foreach ($data as $item){
foreach ($item as $cart_item){
if(!empty($cart_item['quantity'])){
$this->cartService->removeProduct($cart_item['product_class_id']);
}
}
}
foreach ($result->getErrors() as $error) {
$errorMessages[] = $error->getMessage();
}
}
foreach ($result->getWarning() as $warning) {
$errorMessages[] = $warning->getMessage();
}
}
$this->cartService->save();
if(empty($errorMessages)){
if($temporaryOrder){
$this->session->set('matomeItems', $mData);
$this->session->set('refresh', false);
return $this->redirectToRoute('shopping_temporary');
}
else
return $this->redirectToRoute('shopping');
}
}
}
//<<<
return [
'matomeForm' => $matomeForm->createView(), //まとめ購入用
'ProductInSets' => $ProductInSets, //まとめ購入用
'subtitle' => $this->getPageTitle($searchData),
'pagination' => $pagination,
'search_form' => $searchForm->createView(),
'disp_number_form' => $dispNumberForm->createView(),
'order_by_form' => $orderByForm->createView(),
'forms' => $forms,
'Category' => $Category,
'School' => $School,
'product_type' => isset($searchData['product_type']) ? $searchData['product_type'] : null,
'matomeItems' => $this->session->get('matomeItems'),
'back' => $back,
'FilterSchool' => $request->get('s') ? $this->schoolRepository->find($request->get('s')) : null
];
}
/**
* 商品詳細画面.
*
* @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
* @Template("Product/detail.twig")
*
* @param Request $request
* @param Product $Product
*
* @return array
*/
public function detail(Request $request, $id)
{
$Product = $this->productRepository->findWithSortedClassCategories($id);
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
$builder = $this->formFactory->createNamedBuilder(
'',
AddCartType::class,
null,
[
'product' => $Product,
'id_add_product_id' => false,
]
);
$event = new EventArgs(
[
'builder' => $builder,
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
$is_favorite = false;
if ($this->isGranted('ROLE_USER')) {
$Customer = $this->getUser();
$is_favorite = $this->customerFavoriteProductRepository->isFavorite($Customer, $Product);
}
$Place = [
1=>'肩幅',
2=>'袖丈',
3=>'裄丈',
4=>'総丈',
5=>'首回り',
11=>'バスト',
12=>'ウェスト',
13=>'ヒップ',
21=>'股下',
22=>'スカート丈',
31=>'身長',
32=>'体重',
];
$RecommendSize = [];
$xValue = 0;
$yValue = 0;
$Recommend = $Product->getRecommend();
if(!$Recommend) {
//学校ID->オススメサイズを取得する
$Recommend = $this->productSchoolRepository->getRecommend($Product);
}
if($Recommend) {
$Recommend->getRecommendXplace();
$xKey = 'getDr'.sprintf('%02d', $Recommend->getRecommendXplace());
$yKey = 'getDr'.sprintf('%02d', $Recommend->getRecommendYplace());
$Customer = $this->getUser();
$xValue = 0;
$yValue = 0;
if(method_exists($Customer,$xKey)) $xValue =$Customer->$xKey();
if(method_exists($Customer,$yKey)) $yValue =$Customer->$yKey();
$RecommendX = $this->recommendXRepository->searchOne($Recommend, $xValue);
$RecommendY = $this->recommendYRepository->searchOne($Recommend, $yValue);
if($RecommendX && $RecommendY)
$RecommendSize = $this->recommendSizeRepository->searchOne($Recommend,$RecommendX[0],$RecommendY[0]);
}
$ProductInSet = [];
if($Product->getProductType() == 'set'){
$pis_all = $this->setProductRepository->findOneBy(['set_product_id'=>$Product->getSetProductId()])->getSetProductProduct();
foreach($pis_all as $pis)
if(!in_array($pis->getProduct(), $ProductInSet))
array_push($ProductInSet, $pis->getProduct());
}
return [
'title' => $this->title,
'subtitle' => $Product->getName(),
'form' => $builder->getForm()->createView(),
'Product' => $Product,
'is_favorite' => $is_favorite,
'RecommendSize' => $RecommendSize,
'Place' => $Place,
'x' => $xValue,
'y' => $yValue,
'ProductInSet' => $ProductInSet,
'SetProduct' => $Product->getProductType() == 'set' ? $this->setProductRepository->findOneBy(['set_product_id'=>$Product->getSetProductId()]) : null
];
}
/**
* お気に入り追加.
*
* @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"}, methods={"GET", "POST"})
*/
public function addFavorite(Request $request, Product $Product)
{
$this->checkVisibility($Product);
$event = new EventArgs(
[
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE);
if ($this->isGranted('ROLE_USER')) {
$Customer = $this->getUser();
$this->customerFavoriteProductRepository->addFavorite($Customer, $Product);
$this->session->getFlashBag()->set('product_detail.just_added_favorite', $Product->getId());
$event = new EventArgs(
[
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]);
} else {
// 非会員の場合、ログイン画面を表示
// ログイン後の画面遷移先を設定
$this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
$this->session->getFlashBag()->set('eccube.add.favorite', true);
$event = new EventArgs(
[
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
return $this->redirectToRoute('mypage_login');
}
}
/**
* カートに追加.
*
* @Route("/products/add_cart/{id}", name="product_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
*/
public function addCart(Request $request, Product $Product)
{
// エラーメッセージの配列
$errorMessages = [];
if (!$this->checkVisibility($Product)) {
throw new NotFoundHttpException();
}
$builder = $this->formFactory->createNamedBuilder(
'',
AddCartType::class,
null,
[
'product' => $Product,
'id_add_product_id' => false,
]
);
$event = new EventArgs(
[
'builder' => $builder,
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE);
/* @var $form \Symfony\Component\Form\FormInterface */
$form = $builder->getForm();
$form->handleRequest($request);
if ($Product->getProductType() != 'set' && !$form->isValid()) {
throw new NotFoundHttpException();
}
$addCartData = $form->getData();
log_info(
'カート追加処理開始',
[
'product_id' => $Product->getId(),
'product_class_id' => $addCartData['product_class_id'],
'quantity' => $addCartData['quantity'],
]
);
// カートへ追加
$this->cartService->addProduct($addCartData['product_class_id'], $addCartData['quantity'], $request->get('SetProductClass', []), null, isset($addCartData['brother']) ? $addCartData['brother'] : null);
// 明細の正規化
$Carts = $this->cartService->getCarts();
foreach ($Carts as $Cart) {
$result = $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart, $this->getUser()));
// 復旧不可のエラーが発生した場合は追加した明細を削除.
if ($result->hasError()) {
$this->cartService->removeProduct($addCartData['product_class_id']);
foreach ($result->getErrors() as $error) {
$errorMessages[] = $error->getMessage();
}
}
foreach ($result->getWarning() as $warning) {
$errorMessages[] = $warning->getMessage();
}
}
$this->cartService->save();
log_info(
'カート追加処理完了',
[
'product_id' => $Product->getId(),
'product_class_id' => $addCartData['product_class_id'],
'quantity' => $addCartData['quantity'],
]
);
$event = new EventArgs(
[
'form' => $form,
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE);
if ($event->getResponse() !== null) {
return $event->getResponse();
}
if ($request->isXmlHttpRequest()) {
// ajaxでのリクエストの場合は結果をjson形式で返す。
// 初期化
$done = null;
$messages = [];
if (empty($errorMessages)) {
// エラーが発生していない場合
$done = true;
array_push($messages, trans('front.product.add_cart_complete'));
} else {
// エラーが発生している場合
$done = false;
$messages = $errorMessages;
}
return $this->json(['done' => $done, 'messages' => $messages]);
} else {
// ajax以外でのリクエストの場合はカート画面へリダイレクト
foreach ($errorMessages as $errorMessage) {
$this->addRequestError($errorMessage);
}
return $this->redirectToRoute('cart');
}
}
/**
* ページタイトルの設定
*
* @param array|null $searchData
*
* @return str
*/
protected function getPageTitle($searchData)
{
if (isset($searchData['name']) && !empty($searchData['name'])) {
return trans('front.product.search_result');
} elseif (isset($searchData['category_id']) && $searchData['category_id']) {
return $searchData['category_id']->getName();
} else {
return trans('front.product.all_products');
}
}
/**
* 閲覧可能な商品かどうかを判定
*
* @param Product $Product
*
* @return boolean 閲覧可能な場合はtrue
*/
protected function checkVisibility(Product $Product)
{
$is_admin = $this->session->has('_security_admin');
// 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
if (!$is_admin) {
// 在庫なし商品の非表示オプションが有効な場合.
// if ($this->BaseInfo->isOptionNostockHidden()) {
// if (!$Product->getStockFind()) {
// return false;
// }
// }
// 公開ステータスでない商品は表示しない.
if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
return false;
}
}
return true;
}
/**
* 価格取得.
*
* @Route("/products/get_product_price", name="get_product_price", methods={"POST"})
*/
public function getPriceByProductClass(Request $request)
{
$product_class_id = $request->get('product_class_id', null);
$done = false;
if($product_class_id){
$done = true;
$ProductClass = $this->productClassRepository->find($product_class_id);
$Customer = $this->getUser();
if($Customer->getSchool()->isOnSale() && !empty($ProductClass->getPrice03IncTax())){
return $this->json(['done' => $done, 'price' => $ProductClass->getPrice03IncTax()]);
}
else
return $this->json(['done' => $done, 'price' => $ProductClass->getPrice02IncTax()]);
}
return $this->json(['done' => false, 'price' => null]);
}
}