Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ProductController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProductController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
45 | class ProductController extends AbstractController |
||
|
|||
46 | 2 | { |
|
47 | public function index(Application $app, Request $request, $page_no = null) |
||
188 | |||
189 | public function addImage(Application $app, Request $request) |
||
227 | 19 | ||
228 | public function edit(Application $app, Request $request, $id = null) |
||
229 | 19 | { |
|
230 | 19 | $has_class = false; |
|
231 | 6 | if (is_null($id)) { |
|
232 | 6 | $Product = new \Eccube\Entity\Product(); |
|
233 | 6 | $ProductClass = new \Eccube\Entity\ProductClass(); |
|
234 | $Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); |
||
235 | 6 | $Product |
|
236 | 6 | ->setDelFlg(Constant::DISABLED) |
|
237 | 6 | ->addProductClass($ProductClass) |
|
238 | ->setStatus($Disp); |
||
239 | 6 | $ProductClass |
|
240 | 6 | ->setDelFlg(Constant::DISABLED) |
|
241 | 6 | ->setStockUnlimited(true) |
|
242 | 6 | ->setProduct($Product); |
|
243 | 6 | $ProductStock = new \Eccube\Entity\ProductStock(); |
|
244 | 6 | $ProductClass->setProductStock($ProductStock); |
|
245 | $ProductStock->setProductClass($ProductClass); |
||
246 | 13 | } else { |
|
247 | 13 | $Product = $app['eccube.repository.product']->find($id); |
|
248 | if (!$Product) { |
||
249 | throw new NotFoundHttpException(); |
||
250 | } |
||
251 | 13 | // 規格あり商品か |
|
252 | 13 | $has_class = $Product->hasProductClass(); |
|
253 | 11 | if (!$has_class) { |
|
254 | 11 | $ProductClasses = $Product->getProductClasses(); |
|
255 | 11 | $ProductClass = $ProductClasses[0]; |
|
256 | 11 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
|
257 | 6 | View Code Duplication | if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED && $ProductClass->getTaxRule() && !$ProductClass->getTaxRule()->getDelFlg()) { |
258 | $ProductClass->setTaxRate($ProductClass->getTaxRule()->getTaxRate()); |
||
259 | 11 | } |
|
260 | $ProductStock = $ProductClasses[0]->getProductStock(); |
||
261 | } |
||
262 | } |
||
263 | 19 | ||
264 | 19 | $builder = $app['form.factory'] |
|
265 | ->createBuilder(ProductType::class, $Product); |
||
266 | |||
267 | 19 | // 規格あり商品の場合、規格関連情報をFormから除外 |
|
268 | 2 | if ($has_class) { |
|
269 | $builder->remove('class'); |
||
270 | } |
||
271 | 19 | ||
272 | $event = new EventArgs( |
||
273 | 19 | array( |
|
274 | 19 | 'builder' => $builder, |
|
275 | 'Product' => $Product, |
||
276 | ), |
||
277 | $request |
||
278 | 19 | ); |
|
279 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_INITIALIZE, $event); |
||
280 | 19 | ||
281 | $form = $builder->getForm(); |
||
282 | 19 | ||
283 | 17 | if (!$has_class) { |
|
284 | 17 | $ProductClass->setStockUnlimited((boolean)$ProductClass->getStockUnlimited()); |
|
285 | $form['class']->setData($ProductClass); |
||
286 | } |
||
287 | |||
288 | 19 | // ファイルの登録 |
|
289 | 19 | $images = array(); |
|
290 | 19 | $ProductImages = $Product->getProductImage(); |
|
291 | 19 | foreach ($ProductImages as $ProductImage) { |
|
292 | $images[] = $ProductImage->getFileName(); |
||
293 | 19 | } |
|
294 | $form['images']->setData($images); |
||
295 | 19 | ||
296 | 19 | $categories = array(); |
|
297 | 19 | $ProductCategories = $Product->getProductCategories(); |
|
298 | foreach ($ProductCategories as $ProductCategory) { |
||
299 | 19 | /* @var $ProductCategory \Eccube\Entity\ProductCategory */ |
|
300 | $categories[] = $ProductCategory->getCategory(); |
||
301 | 19 | } |
|
302 | $form['Category']->setData($categories); |
||
303 | 19 | ||
304 | 19 | $Tags = array(); |
|
305 | 19 | $ProductTags = $Product->getProductTag(); |
|
306 | 19 | foreach ($ProductTags as $ProductTag) { |
|
307 | $Tags[] = $ProductTag->getTag(); |
||
308 | 19 | } |
|
309 | $form['Tag']->setData($Tags); |
||
310 | 19 | ||
311 | 14 | if ('POST' === $request->getMethod()) { |
|
312 | 14 | $form->handleRequest($request); |
|
313 | 14 | if ($form->isValid()) { |
|
314 | 14 | log_info('商品登録開始', array($id)); |
|
315 | $Product = $form->getData(); |
||
316 | 14 | ||
317 | 14 | if (!$has_class) { |
|
318 | $ProductClass = $form['class']->getData(); |
||
319 | |||
320 | 14 | // 個別消費税 |
|
321 | 14 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
|
322 | 12 | if ($BaseInfo->getOptionProductTaxRule() == Constant::ENABLED) { |
|
323 | 8 | if ($ProductClass->getTaxRate() !== null) { |
|
324 | 4 | View Code Duplication | if ($ProductClass->getTaxRule()) { |
325 | if ($ProductClass->getTaxRule()->getDelFlg() == Constant::ENABLED) { |
||
326 | $ProductClass->getTaxRule()->setDelFlg(Constant::DISABLED); |
||
327 | } |
||
328 | 4 | ||
329 | $ProductClass->getTaxRule()->setTaxRate($ProductClass->getTaxRate()); |
||
330 | 4 | } else { |
|
331 | 4 | $taxrule = $app['eccube.repository.tax_rule']->newTaxRule(); |
|
332 | 4 | $taxrule->setTaxRate($ProductClass->getTaxRate()); |
|
333 | 4 | $taxrule->setApplyDate(new \DateTime()); |
|
334 | 4 | $taxrule->setProduct($Product); |
|
335 | 8 | $taxrule->setProductClass($ProductClass); |
|
336 | $ProductClass->setTaxRule($taxrule); |
||
337 | } |
||
338 | 4 | } else { |
|
339 | 2 | if ($ProductClass->getTaxRule()) { |
|
340 | $ProductClass->getTaxRule()->setDelFlg(Constant::ENABLED); |
||
341 | } |
||
342 | } |
||
343 | 14 | } |
|
344 | $app['orm.em']->persist($ProductClass); |
||
345 | |||
346 | 14 | // 在庫情報を作成 |
|
347 | if (!$ProductClass->getStockUnlimited()) { |
||
348 | $ProductStock->setStock($ProductClass->getStock()); |
||
349 | } else { |
||
350 | 14 | // 在庫無制限時はnullを設定 |
|
351 | $ProductStock->setStock(null); |
||
352 | 14 | } |
|
353 | $app['orm.em']->persist($ProductStock); |
||
354 | } |
||
355 | |||
356 | // カテゴリの登録 |
||
357 | // 一度クリア |
||
358 | 14 | /* @var $Product \Eccube\Entity\Product */ |
|
359 | 11 | foreach ($Product->getProductCategories() as $ProductCategory) { |
|
360 | 14 | $Product->removeProductCategory($ProductCategory); |
|
361 | $app['orm.em']->remove($ProductCategory); |
||
362 | 14 | } |
|
363 | 14 | $app['orm.em']->persist($Product); |
|
364 | $app['orm.em']->flush(); |
||
365 | 14 | ||
366 | 14 | $count = 1; |
|
367 | 14 | $Categories = $form->get('Category')->getData(); |
|
368 | 14 | $categoriesIdList = array(); |
|
369 | foreach ($Categories as $Category) { |
||
370 | View Code Duplication | foreach($Category->getPath() as $ParentCategory){ |
|
371 | if (!isset($categoriesIdList[$ParentCategory->getId()])){ |
||
372 | $ProductCategory = $this->createProductCategory($Product, $ParentCategory, $count); |
||
373 | $app['orm.em']->persist($ProductCategory); |
||
374 | $count++; |
||
375 | /* @var $Product \Eccube\Entity\Product */ |
||
376 | $Product->addProductCategory($ProductCategory); |
||
377 | $categoriesIdList[$ParentCategory->getId()] = true; |
||
378 | } |
||
379 | } |
||
380 | if (!isset($categoriesIdList[$Category->getId()])){ |
||
381 | $ProductCategory = $this->createProductCategory($Product, $Category, $count); |
||
382 | $app['orm.em']->persist($ProductCategory); |
||
383 | $count++; |
||
384 | /* @var $Product \Eccube\Entity\Product */ |
||
385 | 14 | $Product->addProductCategory($ProductCategory); |
|
386 | $categoriesIdList[$Category->getId()] = true; |
||
387 | } |
||
388 | } |
||
389 | |||
390 | 14 | // 画像の登録 |
|
391 | 14 | $add_images = $form->get('add_images')->getData(); |
|
392 | foreach ($add_images as $add_image) { |
||
393 | $ProductImage = new \Eccube\Entity\ProductImage(); |
||
394 | $ProductImage |
||
395 | ->setFileName($add_image) |
||
396 | ->setProduct($Product) |
||
397 | ->setRank(1); |
||
398 | $Product->addProductImage($ProductImage); |
||
399 | $app['orm.em']->persist($ProductImage); |
||
400 | |||
401 | // 移動 |
||
402 | 14 | $file = new File($app['config']['image_temp_realdir'] . '/' . $add_image); |
|
403 | $file->move($app['config']['image_save_realdir']); |
||
404 | } |
||
405 | |||
406 | 14 | // 画像の削除 |
|
407 | 14 | $delete_images = $form->get('delete_images')->getData(); |
|
408 | foreach ($delete_images as $delete_image) { |
||
409 | $ProductImage = $app['eccube.repository.product_image'] |
||
410 | ->findOneBy(array('file_name' => $delete_image)); |
||
411 | |||
412 | // 追加してすぐに削除した画像は、Entityに追加されない |
||
413 | if ($ProductImage instanceof \Eccube\Entity\ProductImage) { |
||
414 | $Product->removeProductImage($ProductImage); |
||
415 | $app['orm.em']->remove($ProductImage); |
||
416 | |||
417 | } |
||
418 | $app['orm.em']->persist($Product); |
||
419 | |||
420 | // 削除 |
||
421 | 14 | $fs = new Filesystem(); |
|
422 | $fs->remove($app['config']['image_save_realdir'] . '/' . $delete_image); |
||
423 | 14 | } |
|
424 | 14 | $app['orm.em']->persist($Product); |
|
425 | $app['orm.em']->flush(); |
||
426 | |||
427 | 14 | ||
428 | 14 | $ranks = $request->get('rank_images'); |
|
429 | if ($ranks) { |
||
430 | foreach ($ranks as $rank) { |
||
431 | list($filename, $rank_val) = explode('//', $rank); |
||
432 | $ProductImage = $app['eccube.repository.product_image'] |
||
433 | ->findOneBy(array( |
||
434 | 'file_name' => $filename, |
||
435 | 'Product' => $Product, |
||
436 | )); |
||
437 | $ProductImage->setRank($rank_val); |
||
438 | $app['orm.em']->persist($ProductImage); |
||
439 | } |
||
440 | 14 | } |
|
441 | $app['orm.em']->flush(); |
||
442 | |||
443 | // 商品タグの登録 |
||
444 | 14 | // 商品タグを一度クリア |
|
445 | 14 | $ProductTags = $Product->getProductTag(); |
|
446 | foreach ($ProductTags as $ProductTag) { |
||
447 | 14 | $Product->removeProductTag($ProductTag); |
|
448 | $app['orm.em']->remove($ProductTag); |
||
449 | } |
||
450 | |||
451 | 14 | // 商品タグの登録 |
|
452 | 14 | $Tags = $form->get('Tag')->getData(); |
|
453 | 14 | foreach ($Tags as $Tag) { |
|
454 | $ProductTag = new ProductTag(); |
||
455 | 14 | $ProductTag |
|
456 | 14 | ->setProduct($Product) |
|
457 | 14 | ->setTag($Tag); |
|
458 | 14 | $Product->addProductTag($ProductTag); |
|
459 | $app['orm.em']->persist($ProductTag); |
||
460 | 14 | } |
|
461 | |||
462 | 14 | $Product->setUpdateDate(new \DateTime()); |
|
463 | $app['orm.em']->flush(); |
||
464 | 14 | ||
465 | log_info('商品登録完了', array($id)); |
||
466 | 14 | ||
467 | 14 | $event = new EventArgs( |
|
468 | array( |
||
469 | 'form' => $form, |
||
470 | 'Product' => $Product, |
||
471 | 14 | ), |
|
472 | $request |
||
473 | 14 | ); |
|
474 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE, $event); |
||
475 | 14 | ||
476 | $app->addSuccess('admin.register.complete', 'admin'); |
||
477 | |||
478 | return $app->redirect($app->url('admin_product_product_edit', array('id' => $Product->getId()))); |
||
479 | } else { |
||
480 | log_info('商品登録チェックエラー', array($id)); |
||
481 | $app->addError('admin.register.failed', 'admin'); |
||
482 | } |
||
483 | 5 | } |
|
484 | 5 | ||
485 | // 検索結果の保持 |
||
486 | 5 | $builder = $app['form.factory'] |
|
487 | ->createBuilder(SearchProductType::class); |
||
488 | 5 | ||
489 | 5 | $event = new EventArgs( |
|
490 | array( |
||
491 | 'builder' => $builder, |
||
492 | 'Product' => $Product, |
||
493 | 5 | ), |
|
494 | $request |
||
495 | 5 | ); |
|
496 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_SEARCH, $event); |
||
497 | 5 | ||
498 | $searchForm = $builder->getForm(); |
||
499 | |||
500 | if ('POST' === $request->getMethod()) { |
||
501 | 5 | $searchForm->handleRequest($request); |
|
502 | 5 | } |
|
503 | 5 | ||
504 | 5 | return $app->render('Product/product.twig', array( |
|
505 | 5 | 'Product' => $Product, |
|
506 | 5 | 'form' => $form->createView(), |
|
507 | 'searchForm' => $searchForm->createView(), |
||
508 | 'has_class' => $has_class, |
||
509 | 'id' => $id, |
||
510 | 2 | )); |
|
511 | } |
||
512 | 2 | ||
513 | 2 | public function delete(Application $app, Request $request, $id = null) |
|
514 | 2 | { |
|
515 | 2 | $this->isTokenValid($app); |
|
516 | $session = $request->getSession(); |
||
517 | 2 | $page_no = intval($session->get('eccube.admin.product.search.page_no')); |
|
518 | $page_no = $page_no ? $page_no : Constant::ENABLED; |
||
519 | 2 | ||
520 | 2 | if (!is_null($id)) { |
|
521 | /* @var $Product \Eccube\Entity\Product */ |
||
522 | $Product = $app['eccube.repository.product']->find($id); |
||
523 | if (!$Product) { |
||
524 | $app->deleteMessage(); |
||
525 | 2 | return $app->redirect($app->url('admin_product_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
|
526 | 2 | } |
|
527 | |||
528 | 2 | if ($Product instanceof \Eccube\Entity\Product) { |
|
529 | log_info('商品削除開始', array($id)); |
||
530 | 2 | ||
531 | 2 | $Product->setDelFlg(Constant::ENABLED); |
|
532 | 2 | ||
533 | 2 | $ProductClasses = $Product->getProductClasses(); |
|
534 | 2 | $deleteImages = array(); |
|
535 | foreach ($ProductClasses as $ProductClass) { |
||
536 | 2 | $ProductClass->setDelFlg(Constant::ENABLED); |
|
537 | 2 | $Product->removeProductClass($ProductClass); |
|
538 | 2 | ||
539 | 2 | $ProductClasses = $Product->getProductClasses(); |
|
540 | foreach ($ProductClasses as $ProductClass) { |
||
541 | 2 | $ProductClass->setDelFlg(Constant::ENABLED); |
|
542 | 2 | $Product->removeProductClass($ProductClass); |
|
543 | |||
544 | $ProductStock = $ProductClass->getProductStock(); |
||
545 | 2 | $app['orm.em']->remove($ProductStock); |
|
546 | 2 | } |
|
547 | 2 | ||
548 | 2 | $ProductImages = $Product->getProductImage(); |
|
549 | 2 | foreach ($ProductImages as $ProductImage) { |
|
550 | $Product->removeProductImage($ProductImage); |
||
551 | $deleteImages[] = $ProductImage->getFileName(); |
||
552 | 2 | $app['orm.em']->remove($ProductImage); |
|
553 | 2 | } |
|
554 | 2 | ||
555 | 2 | $ProductCategories = $Product->getProductCategories(); |
|
556 | foreach ($ProductCategories as $ProductCategory) { |
||
557 | $Product->removeProductCategory($ProductCategory); |
||
558 | $app['orm.em']->remove($ProductCategory); |
||
559 | } |
||
560 | 2 | ||
561 | } |
||
562 | 2 | ||
563 | $app['orm.em']->persist($Product); |
||
564 | 2 | ||
565 | $app['orm.em']->flush(); |
||
566 | 2 | ||
567 | 2 | $event = new EventArgs( |
|
568 | 2 | array( |
|
569 | 'Product' => $Product, |
||
570 | 'ProductClass' => $ProductClasses, |
||
571 | 'deleteImages' => $deleteImages, |
||
572 | 2 | ), |
|
573 | 2 | $request |
|
574 | ); |
||
575 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_DELETE_COMPLETE, $event); |
||
576 | 2 | $deleteImages = $event->getArgument('deleteImages'); |
|
577 | |||
578 | 2 | // 画像ファイルの削除(commit後に削除させる) |
|
579 | 2 | foreach ($deleteImages as $deleteImage) { |
|
580 | 2 | try { |
|
581 | $fs = new Filesystem(); |
||
582 | $fs->remove($app['config']['image_save_realdir'] . '/' . $deleteImage); |
||
583 | } catch (\Exception $e) { |
||
584 | // エラーが発生しても無視する |
||
585 | 2 | } |
|
586 | } |
||
587 | 2 | ||
588 | log_info('商品削除完了', array($id)); |
||
589 | |||
590 | 2 | $app->addSuccess('admin.delete.complete', 'admin'); |
|
591 | } else { |
||
592 | log_info('商品削除エラー', array($id)); |
||
593 | $app->addError('admin.delete.failed', 'admin'); |
||
594 | } |
||
595 | } else { |
||
596 | log_info('商品削除エラー', array($id)); |
||
597 | 2 | $app->addError('admin.delete.failed', 'admin'); |
|
598 | } |
||
599 | |||
600 | 2 | return $app->redirect($app->url('admin_product_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
|
601 | } |
||
602 | 2 | ||
603 | public function copy(Application $app, Request $request, $id = null) |
||
604 | 2 | { |
|
605 | 2 | $this->isTokenValid($app); |
|
606 | 2 | ||
607 | 2 | if (!is_null($id)) { |
|
608 | 2 | $Product = $app['eccube.repository.product']->find($id); |
|
609 | 2 | if ($Product instanceof \Eccube\Entity\Product) { |
|
610 | 2 | $CopyProduct = clone $Product; |
|
611 | $CopyProduct->copy(); |
||
612 | 2 | $Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); |
|
613 | 2 | $CopyProduct->setStatus($Disp); |
|
614 | 2 | ||
615 | $CopyProductCategories = $CopyProduct->getProductCategories(); |
||
616 | foreach ($CopyProductCategories as $Category) { |
||
617 | $app['orm.em']->persist($Category); |
||
618 | 2 | } |
|
619 | 2 | ||
620 | 2 | // 規格あり商品の場合は, デフォルトの商品規格を取得し登録する. |
|
621 | if ($CopyProduct->hasProductClass()) { |
||
622 | 2 | $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
623 | 2 | $softDeleteFilter->setExcludes(array( |
|
624 | 2 | 'Eccube\Entity\ProductClass' |
|
625 | )); |
||
626 | $dummyClass = $app['eccube.repository.product_class']->findOneBy(array( |
||
627 | 2 | 'del_flg' => \Eccube\Common\Constant::ENABLED, |
|
628 | 'ClassCategory1' => null, |
||
629 | 2 | 'ClassCategory2' => null, |
|
630 | 2 | 'Product' => $Product, |
|
631 | 2 | )); |
|
632 | 2 | $dummyClass = clone $dummyClass; |
|
633 | $dummyClass->setProduct($CopyProduct); |
||
634 | $CopyProduct->addProductClass($dummyClass); |
||
635 | 2 | $softDeleteFilter->setExcludes(array()); |
|
636 | 2 | } |
|
637 | 2 | ||
638 | 2 | $CopyProductClasses = $CopyProduct->getProductClasses(); |
|
639 | 2 | foreach ($CopyProductClasses as $Class) { |
|
640 | 2 | $Stock = $Class->getProductStock(); |
|
641 | $CopyStock = clone $Stock; |
||
642 | 2 | $CopyStock->setProductClass($Class); |
|
643 | $app['orm.em']->persist($CopyStock); |
||
644 | 2 | ||
645 | 2 | $app['orm.em']->persist($Class); |
|
646 | } |
||
647 | $Images = $CopyProduct->getProductImage(); |
||
648 | 2 | foreach ($Images as $Image) { |
|
649 | 2 | ||
650 | // 画像ファイルを新規作成 |
||
651 | 2 | $extension = pathinfo($Image->getFileName(), PATHINFO_EXTENSION); |
|
652 | 2 | $filename = date('mdHis') . uniqid('_') . '.' . $extension; |
|
653 | 2 | try { |
|
654 | $fs = new Filesystem(); |
||
655 | $fs->copy($app['config']['image_save_realdir'] . '/' . $Image->getFileName(), $app['config']['image_save_realdir'] . '/' . $filename); |
||
656 | 2 | } catch (\Exception $e) { |
|
657 | // エラーが発生しても無視する |
||
658 | 2 | } |
|
659 | $Image->setFileName($filename); |
||
660 | 2 | ||
661 | 2 | $app['orm.em']->persist($Image); |
|
662 | 2 | } |
|
663 | $Tags = $CopyProduct->getProductTag(); |
||
664 | foreach ($Tags as $Tag) { |
||
665 | 2 | $app['orm.em']->persist($Tag); |
|
666 | } |
||
667 | 2 | ||
668 | $app['orm.em']->persist($CopyProduct); |
||
669 | 2 | ||
670 | $app['orm.em']->flush(); |
||
671 | 2 | ||
672 | 2 | $event = new EventArgs( |
|
673 | 2 | array( |
|
674 | 2 | 'Product' => $Product, |
|
675 | 2 | 'CopyProduct' => $CopyProduct, |
|
676 | 2 | 'CopyProductCategories' => $CopyProductCategories, |
|
677 | 'CopyProductClasses' => $CopyProductClasses, |
||
678 | 'images' => $Images, |
||
679 | 'Tags' => $Tags, |
||
680 | 2 | ), |
|
681 | $request |
||
682 | 2 | ); |
|
683 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_COPY_COMPLETE, $event); |
||
684 | 2 | ||
685 | $app->addSuccess('admin.product.copy.complete', 'admin'); |
||
686 | |||
687 | return $app->redirect($app->url('admin_product_product_edit', array('id' => $CopyProduct->getId()))); |
||
688 | } else { |
||
689 | $app->addError('admin.product.copy.failed', 'admin'); |
||
690 | } |
||
691 | } else { |
||
692 | $app->addError('admin.product.copy.failed', 'admin'); |
||
693 | } |
||
694 | |||
695 | 1 | return $app->redirect($app->url('admin_product')); |
|
696 | } |
||
697 | 1 | ||
698 | 1 | public function display(Application $app, Request $request, $id = null) |
|
699 | { |
||
700 | $event = new EventArgs( |
||
701 | 1 | array(), |
|
702 | $request |
||
703 | 1 | ); |
|
704 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_DISPLAY_COMPLETE, $event); |
|
705 | |||
706 | if (!is_null($id)) { |
||
707 | return $app->redirect($app->url('product_detail', array('id' => $id, 'admin' => '1'))); |
||
708 | } |
||
709 | |||
710 | return $app->redirect($app->url('admin_product')); |
||
711 | } |
||
712 | |||
713 | /** |
||
714 | * 商品CSVの出力. |
||
715 | * |
||
716 | * @param Application $app |
||
717 | * @param Request $request |
||
718 | * @return StreamedResponse |
||
719 | */ |
||
720 | public function export(Application $app, Request $request) |
||
822 | |||
823 | /** |
||
824 | * ProductCategory作成 |
||
825 | * @param \Eccube\Entity\Product $Product |
||
826 | * @param \Eccube\Entity\Category $Category |
||
827 | * @return \Eccube\Entity\ProductCategory |
||
828 | */ |
||
829 | View Code Duplication | private function createProductCategory($Product, $Category, $count) |
|
840 | } |
||
841 |