1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Eccube\Controller; |
25
|
|
|
|
26
|
|
|
use Eccube\Entity\BaseInfo; |
27
|
|
|
use Eccube\Entity\Master\ProductStatus; |
28
|
|
|
use Eccube\Entity\Product; |
29
|
|
|
use Eccube\Event\EccubeEvents; |
30
|
|
|
use Eccube\Event\EventArgs; |
31
|
|
|
use Eccube\Exception\CartException; |
32
|
|
|
use Eccube\Form\Type\AddCartType; |
33
|
|
|
use Eccube\Form\Type\Master\ProductListMaxType; |
34
|
|
|
use Eccube\Form\Type\Master\ProductListOrderByType; |
35
|
|
|
use Eccube\Form\Type\SearchProductType; |
36
|
|
|
use Eccube\Repository\CustomerFavoriteProductRepository; |
37
|
|
|
use Eccube\Repository\ProductRepository; |
38
|
|
|
use Eccube\Service\CartService; |
39
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
40
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlow; |
41
|
|
|
use Knp\Component\Pager\Paginator; |
42
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
43
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
44
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
45
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
46
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
47
|
|
|
use Symfony\Component\HttpFoundation\Request; |
48
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
49
|
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Route(service=ProductController::class) |
53
|
|
|
*/ |
54
|
|
|
class ProductController extends AbstractController |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* @var PurchaseFlow |
58
|
|
|
*/ |
59
|
|
|
protected $purchaseFlow; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var CustomerFavoriteProductRepository |
63
|
|
|
*/ |
64
|
|
|
protected $customerFavoriteProductRepository; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var CartService |
68
|
|
|
*/ |
69
|
|
|
protected $cartService; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var ProductRepository |
73
|
|
|
*/ |
74
|
|
|
protected $productRepository; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var BaseInfo |
78
|
|
|
*/ |
79
|
|
|
protected $BaseInfo; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var AuthenticationUtils |
83
|
|
|
*/ |
84
|
|
|
protected $helper; |
85
|
|
|
|
86
|
|
|
private $title = ''; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* ProductController constructor. |
90
|
|
|
* |
91
|
|
|
* @param PurchaseFlow $cartPurchaseFlow |
|
|
|
|
92
|
|
|
* @param CustomerFavoriteProductRepository $customerFavoriteProductRepository |
93
|
|
|
* @param CartService $cartService |
|
|
|
|
94
|
|
|
* @param ProductRepository $productRepository |
|
|
|
|
95
|
|
|
* @param BaseInfo $BaseInfo |
|
|
|
|
96
|
|
|
* @param AuthenticationUtils $helper |
|
|
|
|
97
|
|
|
*/ |
98
|
45 |
|
public function __construct( |
99
|
|
|
PurchaseFlow $cartPurchaseFlow, |
100
|
|
|
CustomerFavoriteProductRepository $customerFavoriteProductRepository, |
101
|
|
|
CartService $cartService, |
102
|
|
|
ProductRepository $productRepository, |
103
|
|
|
BaseInfo $BaseInfo, |
104
|
|
|
AuthenticationUtils $helper |
105
|
|
|
) { |
106
|
45 |
|
$this->purchaseFlow = $cartPurchaseFlow; |
107
|
45 |
|
$this->customerFavoriteProductRepository = $customerFavoriteProductRepository; |
108
|
45 |
|
$this->cartService = $cartService; |
109
|
45 |
|
$this->productRepository = $productRepository; |
110
|
45 |
|
$this->BaseInfo = $BaseInfo; |
111
|
45 |
|
$this->helper = $helper; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
|
|
|
|
115
|
|
|
* 商品一覧画面. |
116
|
|
|
* |
117
|
|
|
* @Route("/products/list", name="product_list") |
118
|
|
|
* @Template("Product/list.twig") |
119
|
|
|
*/ |
|
|
|
|
120
|
3 |
|
public function index(Request $request, Paginator $paginator) |
121
|
|
|
{ |
122
|
|
|
// Doctrine SQLFilter |
123
|
|
|
// if ($this->BaseInfo->isOptionNostockHidden()) { |
|
|
|
|
124
|
|
|
// $this->entityManager->getFilters()->enable('option_nostock_hidden'); |
|
|
|
|
125
|
|
|
// } |
126
|
|
|
|
127
|
|
|
// handleRequestは空のqueryの場合は無視するため |
128
|
3 |
|
if ($request->getMethod() === 'GET') { |
129
|
3 |
|
$request->query->set('pageno', $request->query->get('pageno', '')); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
// searchForm |
133
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
134
|
3 |
|
$builder = $this->formFactory->createNamedBuilder('', SearchProductType::class); |
135
|
3 |
|
$builder->setAttribute('freeze', true); |
136
|
3 |
|
$builder->setAttribute('freeze_display_text', false); |
137
|
3 |
|
if ($request->getMethod() === 'GET') { |
138
|
3 |
|
$builder->setMethod('GET'); |
139
|
|
|
} |
140
|
|
|
|
141
|
3 |
|
$event = new EventArgs( |
142
|
|
|
[ |
143
|
3 |
|
'builder' => $builder, |
144
|
|
|
], |
145
|
3 |
|
$request |
146
|
|
|
); |
147
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE, $event); |
148
|
|
|
|
149
|
|
|
/* @var $searchForm \Symfony\Component\Form\FormInterface */ |
150
|
3 |
|
$searchForm = $builder->getForm(); |
151
|
|
|
|
152
|
3 |
|
$searchForm->handleRequest($request); |
153
|
|
|
|
154
|
|
|
// paginator |
155
|
3 |
|
$searchData = $searchForm->getData(); |
156
|
3 |
|
$qb = $this->productRepository->getQueryBuilderBySearchData($searchData); |
157
|
|
|
|
158
|
3 |
|
$event = new EventArgs( |
159
|
|
|
[ |
160
|
3 |
|
'searchData' => $searchData, |
161
|
3 |
|
'qb' => $qb, |
162
|
|
|
], |
163
|
3 |
|
$request |
164
|
|
|
); |
165
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_SEARCH, $event); |
166
|
3 |
|
$searchData = $event->getArgument('searchData'); |
167
|
|
|
|
168
|
3 |
|
$pagination = $paginator->paginate( |
169
|
3 |
|
$qb, |
170
|
3 |
|
!empty($searchData['pageno']) ? $searchData['pageno'] : 1, |
171
|
3 |
|
$searchData['disp_number']->getId() |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
// addCart form |
175
|
3 |
|
$forms = []; |
176
|
3 |
|
foreach ($pagination as $Product) { |
|
|
|
|
177
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
178
|
3 |
|
$builder = $this->formFactory->createNamedBuilder( |
179
|
3 |
|
'', |
180
|
3 |
|
AddCartType::class, |
181
|
3 |
|
null, |
182
|
|
|
[ |
183
|
3 |
|
'product' => $Product, |
184
|
|
|
'allow_extra_fields' => true, |
185
|
|
|
] |
186
|
|
|
); |
187
|
3 |
|
$addCartForm = $builder->getForm(); |
188
|
|
|
|
189
|
3 |
|
if ($request->getMethod() === 'POST' && (string) $Product->getId() === $request->get('product_id')) { |
190
|
|
|
$addCartForm->handleRequest($request); |
191
|
|
|
|
192
|
|
|
if ($addCartForm->isValid()) { |
193
|
|
|
$addCartData = $addCartForm->getData(); |
194
|
|
|
|
195
|
|
|
try { |
196
|
|
|
$this->cartService->addProduct( |
|
|
|
|
197
|
|
|
$addCartData['product_class_id'], |
198
|
|
|
$addCartData['quantity'] |
199
|
|
|
)->save(); |
200
|
|
|
} catch (CartException $e) { |
201
|
|
|
$this->addRequestError($e->getMessage()); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$event = new EventArgs( |
205
|
|
|
[ |
206
|
|
|
'form' => $addCartForm, |
207
|
|
|
'Product' => $Product, |
208
|
|
|
], |
209
|
|
|
$request |
210
|
|
|
); |
211
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_COMPLETE, $event); |
212
|
|
|
|
213
|
|
|
if ($event->getResponse() !== null) { |
214
|
|
|
return $event->getResponse(); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return $this->redirectToRoute('cart'); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
3 |
|
$forms[$Product->getId()] = $addCartForm->createView(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// 表示件数 |
225
|
3 |
|
$builder = $this->formFactory->createNamedBuilder( |
226
|
3 |
|
'disp_number', |
227
|
3 |
|
ProductListMaxType::class, |
228
|
3 |
|
null, |
229
|
|
|
[ |
230
|
3 |
|
'required' => false, |
231
|
3 |
|
'label' => trans('productcontroller.label.result'), |
232
|
|
|
'allow_extra_fields' => true, |
233
|
|
|
] |
234
|
|
|
); |
235
|
3 |
|
if ($request->getMethod() === 'GET') { |
236
|
3 |
|
$builder->setMethod('GET'); |
237
|
|
|
} |
238
|
|
|
|
239
|
3 |
|
$event = new EventArgs( |
240
|
|
|
[ |
241
|
3 |
|
'builder' => $builder, |
242
|
|
|
], |
243
|
3 |
|
$request |
244
|
|
|
); |
245
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_DISP, $event); |
246
|
|
|
|
247
|
3 |
|
$dispNumberForm = $builder->getForm(); |
248
|
|
|
|
249
|
3 |
|
$dispNumberForm->handleRequest($request); |
250
|
|
|
|
251
|
|
|
// ソート順 |
252
|
3 |
|
$builder = $this->formFactory->createNamedBuilder( |
253
|
3 |
|
'orderby', |
254
|
3 |
|
ProductListOrderByType::class, |
255
|
3 |
|
null, |
256
|
|
|
[ |
257
|
3 |
|
'required' => false, |
258
|
3 |
|
'label' => trans('productcontroller.label.sort'), |
259
|
|
|
'allow_extra_fields' => true, |
260
|
|
|
] |
261
|
|
|
); |
262
|
3 |
|
if ($request->getMethod() === 'GET') { |
263
|
3 |
|
$builder->setMethod('GET'); |
264
|
|
|
} |
265
|
|
|
|
266
|
3 |
|
$event = new EventArgs( |
267
|
|
|
[ |
268
|
3 |
|
'builder' => $builder, |
269
|
|
|
], |
270
|
3 |
|
$request |
271
|
|
|
); |
272
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_ORDER, $event); |
273
|
|
|
|
274
|
3 |
|
$orderByForm = $builder->getForm(); |
275
|
|
|
|
276
|
3 |
|
$orderByForm->handleRequest($request); |
277
|
|
|
|
278
|
3 |
|
$Category = $searchForm->get('category_id')->getData(); |
279
|
|
|
|
280
|
|
|
return [ |
281
|
3 |
|
'subtitle' => $this->getPageTitle($searchData), |
282
|
3 |
|
'pagination' => $pagination, |
283
|
3 |
|
'search_form' => $searchForm->createView(), |
284
|
3 |
|
'disp_number_form' => $dispNumberForm->createView(), |
285
|
3 |
|
'order_by_form' => $orderByForm->createView(), |
286
|
3 |
|
'forms' => $forms, |
287
|
3 |
|
'Category' => $Category, |
288
|
|
|
]; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* 商品詳細画面. |
293
|
|
|
* |
294
|
|
|
* @Method("GET") |
295
|
|
|
* @Route("/products/detail/{id}", name="product_detail", requirements={"id" = "\d+"}) |
296
|
|
|
* @Template("Product/detail.twig") |
297
|
|
|
* @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"}) |
298
|
|
|
* |
299
|
|
|
* @param Request $request |
300
|
|
|
* @param Product $Product |
301
|
|
|
* |
302
|
|
|
* @return array |
303
|
|
|
*/ |
304
|
11 |
|
public function detail(Request $request, Product $Product) |
305
|
|
|
{ |
306
|
11 |
|
if (!$this->checkVisibility($Product)) { |
307
|
|
|
throw new NotFoundHttpException(); |
308
|
|
|
} |
309
|
|
|
|
310
|
11 |
|
$builder = $this->formFactory->createNamedBuilder( |
311
|
11 |
|
'', |
312
|
11 |
|
AddCartType::class, |
313
|
11 |
|
null, |
314
|
|
|
[ |
315
|
11 |
|
'product' => $Product, |
316
|
|
|
'id_add_product_id' => false, |
317
|
|
|
] |
318
|
|
|
); |
319
|
|
|
|
320
|
11 |
|
$event = new EventArgs( |
321
|
|
|
[ |
322
|
11 |
|
'builder' => $builder, |
323
|
11 |
|
'Product' => $Product, |
324
|
|
|
], |
325
|
11 |
|
$request |
326
|
|
|
); |
327
|
11 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE, $event); |
328
|
|
|
|
329
|
11 |
|
$is_favorite = false; |
330
|
11 |
|
if ($this->isGranted('ROLE_USER')) { |
331
|
2 |
|
$Customer = $this->getUser(); |
332
|
2 |
|
$is_favorite = $this->customerFavoriteProductRepository->isFavorite($Customer, $Product); |
|
|
|
|
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
return [ |
336
|
11 |
|
'title' => $this->title, |
337
|
11 |
|
'subtitle' => $Product->getName(), |
338
|
11 |
|
'form' => $builder->getForm()->createView(), |
339
|
11 |
|
'Product' => $Product, |
340
|
11 |
|
'is_favorite' => $is_favorite, |
341
|
|
|
]; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
|
|
|
|
345
|
|
|
* お気に入り追加. |
346
|
|
|
* |
347
|
|
|
* @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"}) |
348
|
|
|
*/ |
|
|
|
|
349
|
3 |
|
public function addFavorite(Request $request, Product $Product) |
350
|
|
|
{ |
351
|
3 |
|
$this->checkVisibility($Product); |
352
|
|
|
|
353
|
3 |
|
$event = new EventArgs( |
354
|
|
|
[ |
355
|
3 |
|
'Product' => $Product, |
356
|
|
|
], |
357
|
3 |
|
$request |
358
|
|
|
); |
359
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE, $event); |
360
|
|
|
|
361
|
3 |
|
if ($this->isGranted('ROLE_USER')) { |
362
|
2 |
|
$Customer = $this->getUser(); |
363
|
2 |
|
$this->customerFavoriteProductRepository->addFavorite($Customer, $Product); |
|
|
|
|
364
|
2 |
|
$this->session->getFlashBag()->set('product_detail.just_added_favorite', $Product->getId()); |
365
|
|
|
|
366
|
2 |
|
$event = new EventArgs( |
367
|
|
|
[ |
368
|
2 |
|
'Product' => $Product, |
369
|
|
|
], |
370
|
2 |
|
$request |
371
|
|
|
); |
372
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE, $event); |
373
|
|
|
|
374
|
2 |
|
return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]); |
375
|
|
|
} else { |
376
|
|
|
// 非会員の場合、ログイン画面を表示 |
377
|
|
|
// ログイン後の画面遷移先を設定 |
378
|
1 |
|
$this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()])); |
379
|
1 |
|
$this->session->getFlashBag()->set('eccube.add.favorite', true); |
|
|
|
|
380
|
|
|
|
381
|
1 |
|
$event = new EventArgs( |
382
|
|
|
[ |
383
|
1 |
|
'Product' => $Product, |
384
|
|
|
], |
385
|
1 |
|
$request |
386
|
|
|
); |
387
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE, $event); |
388
|
|
|
|
389
|
1 |
|
return $this->redirectToRoute('mypage_login'); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
|
|
|
|
394
|
|
|
* カートに追加. |
395
|
|
|
* |
396
|
|
|
* @Method("POST") |
397
|
|
|
* @Route("/products/add_cart/{id}", name="product_add_cart", requirements={"id" = "\d+"}) |
398
|
|
|
*/ |
|
|
|
|
399
|
36 |
|
public function addCart(Request $request, Product $Product) |
400
|
|
|
{ |
401
|
|
|
// エラーメッセージの配列 |
402
|
36 |
|
$errorMessages = []; |
403
|
36 |
|
if (!$this->checkVisibility($Product)) { |
404
|
1 |
|
throw new NotFoundHttpException(); |
405
|
|
|
} |
406
|
|
|
|
407
|
35 |
|
$builder = $this->formFactory->createNamedBuilder( |
408
|
35 |
|
'', |
409
|
35 |
|
AddCartType::class, |
410
|
35 |
|
null, |
411
|
|
|
[ |
412
|
35 |
|
'product' => $Product, |
413
|
|
|
'id_add_product_id' => false, |
414
|
|
|
] |
415
|
|
|
); |
416
|
|
|
|
417
|
35 |
|
$event = new EventArgs( |
418
|
|
|
[ |
419
|
35 |
|
'builder' => $builder, |
420
|
35 |
|
'Product' => $Product, |
421
|
|
|
], |
422
|
35 |
|
$request |
423
|
|
|
); |
424
|
35 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE, $event); |
425
|
|
|
|
426
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
427
|
35 |
|
$form = $builder->getForm(); |
428
|
35 |
|
$form->handleRequest($request); |
429
|
|
|
|
430
|
35 |
|
if (!$form->isValid()) { |
431
|
|
|
throw new NotFoundHttpException(); |
432
|
|
|
} |
433
|
|
|
|
434
|
35 |
|
$addCartData = $form->getData(); |
435
|
|
|
|
436
|
35 |
|
log_info( |
437
|
35 |
|
'カート追加処理開始', |
438
|
|
|
[ |
439
|
35 |
|
'product_id' => $Product->getId(), |
440
|
35 |
|
'product_class_id' => $addCartData['product_class_id'], |
441
|
35 |
|
'quantity' => $addCartData['quantity'], |
442
|
|
|
] |
443
|
|
|
); |
444
|
|
|
|
445
|
|
|
// カートへ追加 |
446
|
35 |
|
$this->cartService->addProduct($addCartData['product_class_id'], $addCartData['quantity']); |
447
|
|
|
|
448
|
|
|
// 明細の正規化 |
449
|
35 |
|
$flow = $this->purchaseFlow; |
450
|
35 |
|
$Cart = $this->cartService->getCart(); |
451
|
35 |
|
$result = $flow->calculate($Cart, new PurchaseContext($Cart, $this->getUser())); |
452
|
|
|
|
453
|
|
|
// 復旧不可のエラーが発生した場合は追加した明細を削除. |
454
|
35 |
|
if ($result->hasError()) { |
455
|
|
|
$this->cartService->removeProduct($addCartData['product_class_id']); |
456
|
|
|
foreach ($result->getErrors() as $error) { |
457
|
|
|
$errorMessages[] = $error->getMessage(); |
458
|
|
|
} |
459
|
|
|
} |
460
|
|
|
|
461
|
35 |
|
foreach ($result->getWarning() as $warning) { |
462
|
5 |
|
$errorMessages[] = $warning->getMessage(); |
463
|
|
|
} |
464
|
|
|
|
465
|
35 |
|
$this->cartService->save(); |
466
|
|
|
|
467
|
35 |
|
log_info( |
468
|
35 |
|
'カート追加処理完了', |
469
|
|
|
[ |
470
|
35 |
|
'product_id' => $Product->getId(), |
471
|
35 |
|
'product_class_id' => $addCartData['product_class_id'], |
472
|
35 |
|
'quantity' => $addCartData['quantity'], |
473
|
|
|
] |
474
|
|
|
); |
475
|
|
|
|
476
|
35 |
|
$event = new EventArgs( |
477
|
|
|
[ |
478
|
35 |
|
'form' => $form, |
479
|
35 |
|
'Product' => $Product, |
480
|
|
|
], |
481
|
35 |
|
$request |
482
|
|
|
); |
483
|
35 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE, $event); |
484
|
|
|
|
485
|
35 |
|
if ($event->getResponse() !== null) { |
486
|
|
|
return $event->getResponse(); |
487
|
|
|
} |
488
|
|
|
|
489
|
35 |
|
if ($request->isXmlHttpRequest()) { |
490
|
|
|
// ajaxでのリクエストの場合は結果をjson形式で返す。 |
491
|
|
|
|
492
|
|
|
// 初期化 |
493
|
|
|
$done = null; |
|
|
|
|
494
|
|
|
$messages = []; |
495
|
|
|
|
496
|
|
|
if (empty($errorMessages)) { |
497
|
|
|
// エラーが発生していない場合 |
498
|
|
|
$done = true; |
499
|
|
|
array_push($messages, 'カートに追加しました。'); |
500
|
|
|
} else { |
501
|
|
|
// エラーが発生している場合 |
502
|
|
|
$done = false; |
503
|
|
|
$messages = $errorMessages; |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
return new JsonResponse(['done' => $done, 'messages' => $messages]); |
507
|
|
|
} else { |
508
|
|
|
// ajax以外でのリクエストの場合はカート画面へリダイレクト |
509
|
35 |
|
foreach ($errorMessages as $errorMessage) { |
510
|
5 |
|
$this->addRequestError($errorMessage); |
511
|
|
|
} |
512
|
|
|
|
513
|
35 |
|
return $this->redirectToRoute('cart'); |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
/** |
518
|
|
|
* ページタイトルの設定 |
519
|
|
|
* |
520
|
|
|
* @param null|array $searchData |
521
|
|
|
* |
522
|
|
|
* @return str |
523
|
|
|
*/ |
524
|
3 |
|
private function getPageTitle($searchData) |
525
|
|
|
{ |
526
|
3 |
|
if (isset($searchData['name']) && !empty($searchData['name'])) { |
527
|
|
|
return trans('productcontroller.text.return.search'); |
528
|
3 |
|
} elseif (isset($searchData['category_id']) && $searchData['category_id']) { |
529
|
1 |
|
return $searchData['category_id']->getName(); |
530
|
|
|
} else { |
531
|
2 |
|
return trans('productcontroller.text.return.all_products'); |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* 閲覧可能な商品かどうかを判定 |
537
|
|
|
* |
538
|
|
|
* @param Product $Product |
539
|
|
|
* |
540
|
|
|
* @return boolean 閲覧可能な場合はtrue |
541
|
|
|
*/ |
542
|
42 |
|
private function checkVisibility(Product $Product) |
543
|
|
|
{ |
544
|
42 |
|
$is_admin = $this->session->has('_security_admin'); |
545
|
|
|
|
546
|
|
|
// 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能. |
547
|
42 |
|
if (!$is_admin) { |
548
|
|
|
// 在庫なし商品の非表示オプションが有効な場合. |
549
|
|
|
// if ($this->BaseInfo->isOptionNostockHidden()) { |
|
|
|
|
550
|
|
|
// if (!$Product->getStockFind()) { |
|
|
|
|
551
|
|
|
// return false; |
552
|
|
|
// } |
553
|
|
|
// } |
554
|
|
|
// 公開ステータスでない商品は表示しない. |
555
|
42 |
|
if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) { |
556
|
1 |
|
return false; |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
|
560
|
42 |
|
return true; |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
|