質問編集履歴
9
PHP整形いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -170,110 +170,266 @@
|
|
170
170
|
|
171
171
|
```ここに言語を入力
|
172
172
|
|
173
|
-
i
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
173
|
+
public function detail(Application $app, Request $request, $id)
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
$BaseInfo = $app['eccube.repository.base_info']->get();
|
178
|
+
|
179
|
+
if ($BaseInfo->getNostockHidden() === Constant::ENABLED) {
|
180
|
+
|
181
|
+
$app['orm.em']->getFilters()->enable('nostock_hidden');
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
/* @var $Product \Eccube\Entity\Product */
|
186
|
+
|
187
|
+
$Product = $app['eccube.repository.product']->get($id);
|
188
|
+
|
189
|
+
if (!$request->getSession()->has('_security_admin') && $Product->getStatus()->getId() !== 1) {
|
190
|
+
|
191
|
+
throw new NotFoundHttpException();
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
if (count($Product->getProductClasses()) < 1) {
|
196
|
+
|
197
|
+
throw new NotFoundHttpException();
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */
|
202
|
+
|
203
|
+
$builder = $app['form.factory']->createNamedBuilder('', 'add_cart', null, array(
|
204
|
+
|
205
|
+
'product' => $Product,
|
206
|
+
|
207
|
+
'id_add_product_id' => false,
|
208
|
+
|
209
|
+
));
|
210
|
+
|
211
|
+
$event = new EventArgs(
|
212
|
+
|
213
|
+
array(
|
214
|
+
|
215
|
+
'builder' => $builder,
|
216
|
+
|
217
|
+
'Product' => $Product,
|
218
|
+
|
219
|
+
),
|
220
|
+
|
221
|
+
$request
|
222
|
+
|
223
|
+
);
|
224
|
+
|
225
|
+
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE, $event);
|
226
|
+
|
227
|
+
/* @var $form \Symfony\Component\Form\FormInterface */
|
228
|
+
|
229
|
+
$form = $builder->getForm();
|
230
|
+
|
231
|
+
if ($request->getMethod() === 'POST') {
|
232
|
+
|
233
|
+
$form->handleRequest($request);
|
234
|
+
|
235
|
+
if ($form->isValid()) {
|
236
|
+
|
237
|
+
$addCartData = $form->getData();
|
238
|
+
|
239
|
+
if ($addCartData['mode'] === 'add_favorite') {
|
240
|
+
|
241
|
+
if ($app->isGranted('ROLE_USER')) {
|
242
|
+
|
243
|
+
$Customer = $app->user();
|
244
|
+
|
245
|
+
$app['eccube.repository.customer_favorite_product']->addFavorite($Customer, $Product);
|
246
|
+
|
247
|
+
$app['session']->getFlashBag()->set('product_detail.just_added_favorite', $Product->getId());
|
248
|
+
|
249
|
+
$event = new EventArgs(
|
250
|
+
|
251
|
+
array(
|
252
|
+
|
253
|
+
'form' => $form,
|
254
|
+
|
255
|
+
'Product' => $Product,
|
256
|
+
|
257
|
+
),
|
258
|
+
|
259
|
+
$request
|
260
|
+
|
261
|
+
);
|
262
|
+
|
263
|
+
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_FAVORITE, $event);
|
264
|
+
|
265
|
+
if ($event->getResponse() !== null) {
|
266
|
+
|
267
|
+
return $event->getResponse();
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
return $app->redirect($app->url('product_detail', array('id' => $Product->getId())));
|
272
|
+
|
273
|
+
} else {
|
274
|
+
|
275
|
+
// 非会員の場合、ログイン画面を表示
|
276
|
+
|
277
|
+
// ログイン後の画面遷移先を設定
|
278
|
+
|
279
|
+
$app->setLoginTargetPath($app->url('product_detail', array('id' => $Product->getId())));
|
280
|
+
|
281
|
+
$app['session']->getFlashBag()->set('eccube.add.favorite', true);
|
282
|
+
|
283
|
+
return $app->redirect($app->url('mypage_login'));
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
} elseif ($addCartData['mode'] === 'add_cart') {
|
288
|
+
|
289
|
+
log_info('カート追加処理開始', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity']));
|
290
|
+
|
291
|
+
try {
|
292
|
+
|
293
|
+
$app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity'])->save();
|
294
|
+
|
295
|
+
} catch (CartException $e) {
|
296
|
+
|
297
|
+
log_info('カート追加エラー', array($e->getMessage()));
|
298
|
+
|
299
|
+
$app->addRequestError($e->getMessage());
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
log_info('カート追加処理完了', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity']));
|
304
|
+
|
305
|
+
$event = new EventArgs(
|
306
|
+
|
307
|
+
array(
|
308
|
+
|
309
|
+
'form' => $form,
|
310
|
+
|
311
|
+
'Product' => $Product,
|
312
|
+
|
313
|
+
),
|
314
|
+
|
315
|
+
$request
|
316
|
+
|
317
|
+
);
|
318
|
+
|
319
|
+
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_COMPLETE, $event);
|
320
|
+
|
321
|
+
if ($event->getResponse() !== null) {
|
322
|
+
|
323
|
+
return $event->getResponse();
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
return $app->redirect($app->url('cart'));
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
elseif ($addCartData['mode'] === 'clear-cart') {
|
332
|
+
|
333
|
+
try {
|
334
|
+
|
335
|
+
$app['eccube.service.cart']->clear()->save();
|
336
|
+
|
337
|
+
} catch (CartException $e) {
|
338
|
+
|
339
|
+
log_info('カートクリアエラー', array($e->getMessage()));
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
return $app->redirect($app->url('product_detail', array('id' => $Product->getId())));
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
} else {
|
350
|
+
|
351
|
+
$addFavorite = $app['session']->getFlashBag()->get('eccube.add.favorite');
|
352
|
+
|
353
|
+
if (!empty($addFavorite)) {
|
354
|
+
|
355
|
+
// お気に入り登録時にログインされていない場合、ログイン後にお気に入り追加処理を行う
|
356
|
+
|
357
|
+
if ($app->isGranted('ROLE_USER')) {
|
358
|
+
|
359
|
+
$Customer = $app->user();
|
360
|
+
|
361
|
+
$app['eccube.repository.customer_favorite_product']->addFavorite($Customer, $Product);
|
362
|
+
|
363
|
+
$app['session']->getFlashBag()->set('product_detail.just_added_favorite', $Product->getId());
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
```
|
372
|
+
|
373
|
+
AddCartType.php
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
```ここに言語を入力
|
378
|
+
|
379
|
+
public function validate($data, ExecutionContext $context)
|
380
|
+
|
381
|
+
{
|
382
|
+
|
383
|
+
if ($mode !== 'add_favorite' && $mode !== 'clear-cart') {
|
384
|
+
|
385
|
+
$context->validateValue($data['product_class_id'], array(
|
386
|
+
|
387
|
+
new Assert\NotBlank(),
|
388
|
+
|
389
|
+
), '[product_class_id]');
|
390
|
+
|
391
|
+
if ($this->Product->getClassName1()) {
|
392
|
+
|
393
|
+
$context->validateValue($data['classcategory_id1'], array(
|
394
|
+
|
395
|
+
new Assert\NotBlank(),
|
396
|
+
|
397
|
+
new Assert\NotEqualTo(array(
|
398
|
+
|
399
|
+
'value' => '__unselected',
|
400
|
+
|
401
|
+
'message' => 'form.type.select.notselect'
|
402
|
+
|
403
|
+
)),
|
404
|
+
|
405
|
+
), '[classcategory_id1]');
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
//商品規格2初期状態(未選択)の場合の返却値は「NULL」で「__unselected」ではない
|
410
|
+
|
411
|
+
if ($this->Product->getClassName2()) {
|
412
|
+
|
413
|
+
$context->validateValue($data['classcategory_id2'], array(
|
414
|
+
|
415
|
+
new Assert\NotBlank(),
|
416
|
+
|
417
|
+
new Assert\NotEqualTo(array(
|
418
|
+
|
419
|
+
'value' => '__unselected',
|
420
|
+
|
421
|
+
'message' => 'form.type.select.notselect'
|
422
|
+
|
423
|
+
)),
|
424
|
+
|
425
|
+
), '[classcategory_id2]');
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
}
|
184
430
|
|
185
431
|
}
|
186
432
|
|
187
|
-
elseif ($addCartData['mode'] === 'clear-cart')
|
188
|
-
|
189
|
-
{
|
190
|
-
|
191
|
-
try
|
192
|
-
|
193
|
-
{
|
194
|
-
|
195
|
-
$app['eccube.service.cart']->clear()->save();
|
196
|
-
|
197
|
-
|
433
|
+
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
catch(CartException $e)
|
202
|
-
|
203
|
-
{
|
204
|
-
|
205
|
-
log_info('カートクリアエラー', array(
|
206
|
-
|
207
|
-
$e->getMessage()
|
208
|
-
|
209
|
-
));
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
return $app->redirect($app->url('product_detail', array(
|
216
|
-
|
217
|
-
'id' => $Product->getId()
|
218
|
-
|
219
|
-
)));
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
else
|
228
|
-
|
229
|
-
{
|
230
|
-
|
231
|
-
$addFavorite = $app['session']->getFlashBag()->get('eccube.add.favorite');```
|
232
434
|
|
233
435
|
```
|
234
|
-
|
235
|
-
AddCartType.php
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
```ここに言語を入力
|
240
|
-
|
241
|
-
public
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
function validate($data, ExecutionContext $context)
|
246
|
-
|
247
|
-
{
|
248
|
-
|
249
|
-
if ($mode !== 'add_favorite' && $mode !== 'clear-cart')
|
250
|
-
|
251
|
-
{
|
252
|
-
|
253
|
-
$context->validateValue($data['product_class_id'], array(
|
254
|
-
|
255
|
-
new AssertNotBlank() ,
|
256
|
-
|
257
|
-
) , '[product_class_id]');
|
258
|
-
|
259
|
-
if ($this->Product->getClassName1())
|
260
|
-
|
261
|
-
{
|
262
|
-
|
263
|
-
$context->validateValue($data['classcategory_id1'], array(
|
264
|
-
|
265
|
-
new AssertNotBlank() ,
|
266
|
-
|
267
|
-
new AssertNotEqualTo(array(
|
268
|
-
|
269
|
-
'value' => '__unselected',
|
270
|
-
|
271
|
-
'message' => 'form.type.select.notselect'
|
272
|
-
|
273
|
-
)) ,
|
274
|
-
|
275
|
-
) , '[classcategory_id1]');
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
```
|
8
PHPの整形を致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -230,9 +230,11 @@
|
|
230
230
|
|
231
231
|
$addFavorite = $app['session']->getFlashBag()->get('eccube.add.favorite');```
|
232
232
|
|
233
|
+
```
|
234
|
+
|
233
235
|
AddCartType.php
|
234
236
|
|
235
|
-
|
237
|
+
|
236
238
|
|
237
239
|
```ここに言語を入力
|
238
240
|
|
7
PHPの整形をしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -232,6 +232,8 @@
|
|
232
232
|
|
233
233
|
AddCartType.php
|
234
234
|
|
235
|
+
```
|
236
|
+
|
235
237
|
```ここに言語を入力
|
236
238
|
|
237
239
|
public
|
6
phpの整形をしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -170,148 +170,106 @@
|
|
170
170
|
|
171
171
|
```ここに言語を入力
|
172
172
|
|
173
|
-
|
173
|
+
if ($event->getResponse() !== null)
|
174
|
-
|
175
|
-
|
174
|
+
|
176
|
-
|
177
|
-
|
175
|
+
{
|
178
|
-
|
176
|
+
|
179
|
-
|
177
|
+
return $event->getResponse();
|
180
|
-
|
178
|
+
|
181
|
-
|
179
|
+
}
|
182
|
-
|
183
|
-
|
180
|
+
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
181
|
+
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
182
|
+
|
192
|
-
|
193
|
-
$app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity'])->save();
|
194
|
-
|
195
|
-
} catch (CartException $e) {
|
196
|
-
|
197
|
-
log_info('カート追加エラー', array($e->getMessage()));
|
198
|
-
|
199
|
-
$app->addRequestError($e->getMessage());
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
log_info('カート追加処理完了', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity']));
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
$event = new EventArgs(
|
210
|
-
|
211
|
-
array(
|
212
|
-
|
213
|
-
'form' => $form,
|
214
|
-
|
215
|
-
'Product' => $Product,
|
216
|
-
|
217
|
-
),
|
218
|
-
|
219
|
-
$request
|
220
|
-
|
221
|
-
);
|
222
|
-
|
223
|
-
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_COMPLETE, $event);
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
if ($event->getResponse() !== null) {
|
228
|
-
|
229
|
-
return $event->getResponse();
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
183
|
+
return $app->redirect($app->url('cart'));
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
elseif ($addCartData['mode'] === 'clear-cart') {
|
240
|
-
|
241
|
-
try {
|
242
|
-
|
243
|
-
$app['eccube.service.cart']->clear()->save();
|
244
|
-
|
245
|
-
} catch (CartException $e) {
|
246
|
-
|
247
|
-
log_info('カートクリアエラー', array($e->getMessage()));
|
248
184
|
|
249
185
|
}
|
250
186
|
|
251
|
-
|
187
|
+
elseif ($addCartData['mode'] === 'clear-cart')
|
188
|
+
|
252
|
-
|
189
|
+
{
|
190
|
+
|
191
|
+
try
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
$app['eccube.service.cart']->clear()->save();
|
196
|
+
|
253
|
-
}
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
254
|
-
|
201
|
+
catch(CartException $e)
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
log_info('カートクリアエラー', array(
|
206
|
+
|
207
|
+
$e->getMessage()
|
208
|
+
|
209
|
+
));
|
210
|
+
|
255
|
-
}
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
256
|
-
|
215
|
+
return $app->redirect($app->url('product_detail', array(
|
216
|
+
|
217
|
+
'id' => $Product->getId()
|
218
|
+
|
219
|
+
)));
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
257
|
-
|
227
|
+
else
|
228
|
+
|
258
|
-
|
229
|
+
{
|
230
|
+
|
259
|
-
|
231
|
+
$addFavorite = $app['session']->getFlashBag()->get('eccube.add.favorite');```
|
232
|
+
|
260
|
-
|
233
|
+
AddCartType.php
|
234
|
+
|
235
|
+
```ここに言語を入力
|
236
|
+
|
237
|
+
public
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
function validate($data, ExecutionContext $context)
|
242
|
+
|
243
|
+
{
|
244
|
+
|
245
|
+
if ($mode !== 'add_favorite' && $mode !== 'clear-cart')
|
246
|
+
|
247
|
+
{
|
248
|
+
|
249
|
+
$context->validateValue($data['product_class_id'], array(
|
250
|
+
|
251
|
+
new AssertNotBlank() ,
|
252
|
+
|
253
|
+
) , '[product_class_id]');
|
254
|
+
|
255
|
+
if ($this->Product->getClassName1())
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
$context->validateValue($data['classcategory_id1'], array(
|
260
|
+
|
261
|
+
new AssertNotBlank() ,
|
262
|
+
|
261
|
-
|
263
|
+
new AssertNotEqualTo(array(
|
264
|
+
|
262
|
-
|
265
|
+
'value' => '__unselected',
|
266
|
+
|
263
|
-
|
267
|
+
'message' => 'form.type.select.notselect'
|
268
|
+
|
269
|
+
)) ,
|
270
|
+
|
271
|
+
) , '[classcategory_id1]');
|
272
|
+
|
273
|
+
}
|
264
274
|
|
265
275
|
```
|
266
|
-
|
267
|
-
AddCartType.php
|
268
|
-
|
269
|
-
```ここに言語を入力
|
270
|
-
|
271
|
-
/**
|
272
|
-
|
273
|
-
* validate
|
274
|
-
|
275
|
-
*
|
276
|
-
|
277
|
-
* @param type $data
|
278
|
-
|
279
|
-
* @param ExecutionContext $context
|
280
|
-
|
281
|
-
*/
|
282
|
-
|
283
|
-
public function validate($data, ExecutionContext $context)
|
284
|
-
|
285
|
-
{
|
286
|
-
|
287
|
-
if ($mode !== 'add_favorite' && $mode !== 'clear-cart') {
|
288
|
-
|
289
|
-
$context->validateValue($data['product_class_id'], array(
|
290
|
-
|
291
|
-
new Assert\NotBlank(),
|
292
|
-
|
293
|
-
), '[product_class_id]');
|
294
|
-
|
295
|
-
if ($this->Product->getClassName1()) {
|
296
|
-
|
297
|
-
$context->validateValue($data['classcategory_id1'], array(
|
298
|
-
|
299
|
-
new Assert\NotBlank(),
|
300
|
-
|
301
|
-
new Assert\NotEqualTo(array(
|
302
|
-
|
303
|
-
'value' => '__unselected',
|
304
|
-
|
305
|
-
'message' => 'form.type.select.notselect'
|
306
|
-
|
307
|
-
)),
|
308
|
-
|
309
|
-
), '[classcategory_id1]');
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
//商品規格2初期状態(未選択)の場合の返却値は「NULL」で「__unselected」ではない
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
```
|
5
PHPの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -263,3 +263,55 @@
|
|
263
263
|
// お気に入り登録時にログインされていない場合、ログイン後にお気に入り追加処理を行う
|
264
264
|
|
265
265
|
```
|
266
|
+
|
267
|
+
AddCartType.php
|
268
|
+
|
269
|
+
```ここに言語を入力
|
270
|
+
|
271
|
+
/**
|
272
|
+
|
273
|
+
* validate
|
274
|
+
|
275
|
+
*
|
276
|
+
|
277
|
+
* @param type $data
|
278
|
+
|
279
|
+
* @param ExecutionContext $context
|
280
|
+
|
281
|
+
*/
|
282
|
+
|
283
|
+
public function validate($data, ExecutionContext $context)
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
if ($mode !== 'add_favorite' && $mode !== 'clear-cart') {
|
288
|
+
|
289
|
+
$context->validateValue($data['product_class_id'], array(
|
290
|
+
|
291
|
+
new Assert\NotBlank(),
|
292
|
+
|
293
|
+
), '[product_class_id]');
|
294
|
+
|
295
|
+
if ($this->Product->getClassName1()) {
|
296
|
+
|
297
|
+
$context->validateValue($data['classcategory_id1'], array(
|
298
|
+
|
299
|
+
new Assert\NotBlank(),
|
300
|
+
|
301
|
+
new Assert\NotEqualTo(array(
|
302
|
+
|
303
|
+
'value' => '__unselected',
|
304
|
+
|
305
|
+
'message' => 'form.type.select.notselect'
|
306
|
+
|
307
|
+
)),
|
308
|
+
|
309
|
+
), '[classcategory_id1]');
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
//商品規格2初期状態(未選択)の場合の返却値は「NULL」で「__unselected」ではない
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
```
|
4
phpファイルの記述
test
CHANGED
File without changes
|
test
CHANGED
@@ -164,4 +164,102 @@
|
|
164
164
|
|
165
165
|
|
166
166
|
|
167
|
+
※6/9追記です。
|
168
|
+
|
169
|
+
ProductController.php
|
170
|
+
|
171
|
+
```ここに言語を入力
|
172
|
+
|
173
|
+
// ログイン後の画面遷移先を設定
|
174
|
+
|
175
|
+
$app->setLoginTargetPath($app->url('product_detail', array('id' => $Product->getId())));
|
176
|
+
|
167
|
-
s
|
177
|
+
$app['session']->getFlashBag()->set('eccube.add.favorite', true);
|
178
|
+
|
179
|
+
return $app->redirect($app->url('mypage_login'));
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
} elseif ($addCartData['mode'] === 'add_cart') {
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
log_info('カート追加処理開始', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity']));
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
try {
|
192
|
+
|
193
|
+
$app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity'])->save();
|
194
|
+
|
195
|
+
} catch (CartException $e) {
|
196
|
+
|
197
|
+
log_info('カート追加エラー', array($e->getMessage()));
|
198
|
+
|
199
|
+
$app->addRequestError($e->getMessage());
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
log_info('カート追加処理完了', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity']));
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
$event = new EventArgs(
|
210
|
+
|
211
|
+
array(
|
212
|
+
|
213
|
+
'form' => $form,
|
214
|
+
|
215
|
+
'Product' => $Product,
|
216
|
+
|
217
|
+
),
|
218
|
+
|
219
|
+
$request
|
220
|
+
|
221
|
+
);
|
222
|
+
|
223
|
+
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_COMPLETE, $event);
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
if ($event->getResponse() !== null) {
|
228
|
+
|
229
|
+
return $event->getResponse();
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
return $app->redirect($app->url('cart'));
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
elseif ($addCartData['mode'] === 'clear-cart') {
|
240
|
+
|
241
|
+
try {
|
242
|
+
|
243
|
+
$app['eccube.service.cart']->clear()->save();
|
244
|
+
|
245
|
+
} catch (CartException $e) {
|
246
|
+
|
247
|
+
log_info('カートクリアエラー', array($e->getMessage()));
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
return $app->redirect($app->url('product_detail', array('id' => $Product->getId())));
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
} else {
|
258
|
+
|
259
|
+
$addFavorite = $app['session']->getFlashBag()->get('eccube.add.favorite');
|
260
|
+
|
261
|
+
if (!empty($addFavorite)) {
|
262
|
+
|
263
|
+
// お気に入り登録時にログインされていない場合、ログイン後にお気に入り追加処理を行う
|
264
|
+
|
265
|
+
```
|
3
タグの追加を致しました。
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
要点を簡潔にまとめました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -113,3 +113,55 @@
|
|
113
113
|
削除処理後のリダイレクト先が、商品詳細ページでないので、
|
114
114
|
|
115
115
|
なんとか商品詳細ページにリダイレクトさせたいというのが実現したいことです。
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
※6/8追記2です。
|
120
|
+
|
121
|
+
自分の環境を前提でお話すると分かりにくいようなので、デモを利用してご説明しますと、
|
122
|
+
|
123
|
+
例えばhttps://demo3.ec-cube.net/products/detail/23で商品をカートに入れた場合、
|
124
|
+
|
125
|
+
ショッピングカート(https://demo3.ec-cube.net/cart)に移動します。
|
126
|
+
|
127
|
+
この時、画面遷移せずに買い物カゴの商品が増え、
|
128
|
+
|
129
|
+
なおかつ買い物カゴの商品を空にできる削除ボタンが欲しいということです。
|
130
|
+
|
131
|
+
画面遷移させないプラグインはあるので、あとは買い物カゴの商品を削除する仕組みがあればと。。。
|
132
|
+
|
133
|
+
現状はショッピングカート(https://demo3.ec-cube.net/cart)の画面でないと商品の削除ができないため、
|
134
|
+
|
135
|
+
商品詳細ページ(https://demo3.ec-cube.net/products/detail/23)で買い物カゴの中身を削除する機能が
|
136
|
+
|
137
|
+
あれば使い勝手が良くなるのではと思った次第です。
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
EC-CUBEコミュニティで教えていただいたのは以下の部分です。
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
> 引用テキスト
|
146
|
+
|
147
|
+
カートの中身を消すには基本的に、src/Eccube/Service/CartService.phpというクラスのclearメソッドを呼べば良いので、3系ではさほど難しくはございません。
|
148
|
+
|
149
|
+
下記のように使用できます。
|
150
|
+
|
151
|
+
$app['eccube.service.cart']->clear()->save();
|
152
|
+
|
153
|
+
ボタンを押したときにこのメソッドが呼ばれるようにカスタマイズしてやればOKです。
|
154
|
+
|
155
|
+
> 引用テキスト
|
156
|
+
|
157
|
+
・削除ボタンをカートブロック内に追加
|
158
|
+
|
159
|
+
・削除ボタンを押すと、カート商品削除専用URLへ遷移(URLは・FrontControllerProviderでコントローラーを定義。/Block/CartClearController.phpで問題ございません)
|
160
|
+
|
161
|
+
・上記で定義したコントローラーでclearする。
|
162
|
+
|
163
|
+
・元のページにリダイレクト
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
src/Eccube/Service/CartService.phpのコードは文字数オーバーになってしまうため記載できませんでした。。
|
1
皆様からご指摘頂いた件について
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,3 +77,39 @@
|
|
77
77
|
カートの商品を削除した後に商品詳細ページ(product_detail)に戻ってくる方法を教えて頂きたいです。
|
78
78
|
|
79
79
|
よろしくお願いいたします。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
※6/8追記です。
|
84
|
+
|
85
|
+
マルチポストの件は知りませんでした。
|
86
|
+
|
87
|
+
大変申し訳ありません。
|
88
|
+
|
89
|
+
EC-CUBEコミュニティで投稿した内容は以下のページです。
|
90
|
+
|
91
|
+
https://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=20466&forum=2
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
プラグインは改造しないほうが良いとのご指摘をいただきましたが、
|
96
|
+
|
97
|
+
カート削除後のリダイレクト処理を変更するという1点だけなので可能なのかなと考えていました。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
自分がどうして商品詳細ページにリダイレクトさせたいかといいますと、カート遷移しませんプラグインというプラグインを使用して
|
102
|
+
|
103
|
+
購入手続き画面に行く前に合計金額と商品の数量を表示させてから
|
104
|
+
|
105
|
+
「購入へ進む」ボタンを押すようにしてあるからです。
|
106
|
+
|
107
|
+
この時に商品の数を間違えたという場合に、いったんカートをクリアできる削除ボタンがあれば便利なのではないかと。。。
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
カートクリアプラグインは商品詳細ページに設置できますが、
|
112
|
+
|
113
|
+
削除処理後のリダイレクト先が、商品詳細ページでないので、
|
114
|
+
|
115
|
+
なんとか商品詳細ページにリダイレクトさせたいというのが実現したいことです。
|