src/Eccube/Controller/ProductController.php line 393

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Eccube\Entity\BaseInfo;
  14. use Eccube\Entity\CustomerLevel;
  15. use Eccube\Entity\Master\ProductStatus;
  16. use Eccube\Entity\Product;
  17. use Eccube\Event\EccubeEvents;
  18. use Eccube\Event\EventArgs;
  19. use Eccube\Form\Type\AddCartType;
  20. use Eccube\Form\Type\Master\ProductListMaxType;
  21. use Eccube\Form\Type\Master\ProductListOrderByType;
  22. use Eccube\Form\Type\SearchProductType;
  23. use Eccube\Repository\BaseInfoRepository;
  24. use Eccube\Repository\CustomerFavoriteProductRepository;
  25. use Eccube\Repository\Master\ProductListMaxRepository;
  26. use Eccube\Repository\ProductRepository;
  27. use Eccube\Repository\CustomerShopRepository;
  28. use Eccube\Repository\CustomerLevelRepository;
  29. use Eccube\Repository\CustomerRepository;
  30. use Eccube\Service\CartService;
  31. use Eccube\Service\PurchaseFlow\PurchaseContext;
  32. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  33. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  34. use Knp\Component\Pager\Paginator;
  35. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  36. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  37. use Symfony\Component\HttpFoundation\Request;
  38. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  39. use Symfony\Component\Routing\Annotation\Route;
  40. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  41. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  42. use Eccube\Repository\MemberRepository;
  43. use Eccube\Repository\CategoryRepository;
  44. use Eccube\Repository\Master\ProductStatusRepository;
  45. use Eccube\Repository\Master\SaleTypeRepository;
  46. use Eccube\Repository\ProductClassRepository;
  47. use Eccube\Repository\PluginnewRepository;
  48. use Symfony\Component\HttpFoundation\RedirectResponse;
  49. use Symfony\Component\HttpFoundation\Response;
  50. use Symfony\Component\HttpFoundation\StreamedResponse;
  51. use Plugin\ProductReview4\Repository\ProductReviewStatusRepository;
  52. class ProductController extends AbstractController
  53. {
  54.     /**
  55.      * @var PurchaseFlow
  56.      */
  57.     protected $purchaseFlow;
  58.     /**
  59.      * @var CustomerFavoriteProductRepository
  60.      */
  61.     protected $customerFavoriteProductRepository;
  62.     /**
  63.      * @var CartService
  64.      */
  65.     protected $cartService;
  66.     /**
  67.      * @var ProductRepository
  68.      */
  69.     protected $productRepository;
  70.     /**
  71.      * @var ProductClassRepository
  72.      */
  73.     protected $productClassRepository;
  74.     
  75.     /**
  76.      * @var BaseInfo
  77.      */
  78.     protected $BaseInfo;
  79.     /**
  80.      * @var AuthenticationUtils
  81.      */
  82.     protected $helper;
  83.     /**
  84.      * @var CustomerShopRepository
  85.      */
  86.     protected $customerShopRepository;
  87.     /**
  88.      * @var ProductListMaxRepository
  89.      */
  90.     protected $productListMaxRepository;
  91.     private $title '';
  92.     /**
  93.      * @var MemberRepository
  94.      */
  95.     protected $memberRepository;
  96.     /**
  97.      * @var ProductStatusRepository
  98.      */
  99.     protected $productStatusRepository;
  100.     /**
  101.      * @var SaleTypeRepository
  102.      */
  103.     protected $saleTypeRepository;
  104.      /**
  105.      * @var CategoryRepository
  106.      */
  107.     protected $categoryRepository;
  108.      /**
  109.      * @var ProductReviewStatusRepository
  110.      */
  111.     protected $productReviewStatusRepository;
  112.     /**
  113.      * @var PluginnewRepository
  114.      */
  115.     protected $pluginnewRepository;
  116.     
  117.     /**
  118.      * ProductController constructor.
  119.      *
  120.      * @param PurchaseFlow $cartPurchaseFlow
  121.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  122.      * @param CartService $cartService
  123.      * @param ProductRepository $productRepository
  124.      * @param BaseInfoRepository $baseInfoRepository
  125.      * @param AuthenticationUtils $helper
  126.      * @param ProductListMaxRepository $productListMaxRepository
  127.      */
  128.     public function __construct(
  129.         PurchaseFlow $cartPurchaseFlow,
  130.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  131.         CartService $cartService,
  132.         ProductRepository $productRepository,
  133.         BaseInfoRepository $baseInfoRepository,
  134.         AuthenticationUtils $helper,
  135.         ProductListMaxRepository $productListMaxRepository
  136.         CustomerShopRepository $customerShopRepository,
  137.         ProductClassRepository $productClassRepository,
  138.         MemberRepository $memberRepository,
  139.         ProductStatusRepository $productStatusRepository,
  140.         SaleTypeRepository $saleTypeRepository,
  141.         CategoryRepository $categoryRepository,
  142.         ProductReviewStatusRepository $productReviewStatusRepository,
  143.         PluginnewRepository $pluginnewRepository,
  144.         
  145.         CustomerLevelRepository $customerLevelRepository
  146.     ) {
  147.         $this->purchaseFlow $cartPurchaseFlow;
  148.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  149.         $this->cartService $cartService;
  150.         $this->productRepository $productRepository;
  151.         $this->productClassRepository $productClassRepository;
  152.         $this->BaseInfo $baseInfoRepository->get();
  153.         $this->helper $helper;
  154.         $this->productListMaxRepository $productListMaxRepository;
  155.         $this->customerShopRepository $customerShopRepository;
  156.         $this->customerLevelRepository =$customerLevelRepository;
  157.         $this->memberRepository $memberRepository;
  158.         $this->productStatusRepository $productStatusRepository;
  159.         $this->saleTypeRepository $saleTypeRepository;
  160.         $this->categoryRepository $categoryRepository;
  161.         $this->productReviewStatusRepository $productReviewStatusRepository;
  162.         $this->pluginnewRepository =$pluginnewRepository;
  163.     }
  164.     /**
  165.      * 商品一覧画面.
  166.      *
  167.      * @Route("/products/list", name="product_list")
  168.      * @Template("Product/list.twig")
  169.      */
  170.     public function index(Request $requestPaginator $paginator)
  171.     {
  172.         // Doctrine SQLFilter
  173.         if ($this->BaseInfo->isOptionNostockHidden()) {
  174.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  175.         }
  176.         // handleRequestは空のqueryの場合は無視するため
  177.         if ($request->getMethod() === 'GET') {
  178.             $request->query->set('pageno'$request->query->get('pageno'''));
  179.         }
  180.         // searchForm
  181.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  182.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  183.         if ($request->getMethod() === 'GET') {
  184.             $builder->setMethod('GET');
  185.         }
  186.         $event = new EventArgs(
  187.             [
  188.                 'builder' => $builder,
  189.             ],
  190.             $request
  191.         );
  192.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE$event);
  193.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  194.         $searchForm $builder->getForm();
  195.         $searchForm->handleRequest($request);
  196.         // paginator
  197.         $searchData $searchForm->getData();
  198.         $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  199.         $event = new EventArgs(
  200.             [
  201.                 'searchData' => $searchData,
  202.                 'qb' => $qb,
  203.             ],
  204.             $request
  205.         );
  206.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_SEARCH$event);
  207.         $searchData $event->getArgument('searchData');
  208.         $query $qb->getQuery()
  209.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  210.         /** @var SlidingPagination $pagination */
  211.         $pagination $paginator->paginate(
  212.             $query,
  213.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  214.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  215.         );
  216.         $ids = [];
  217.         foreach ($pagination as $Product) {
  218.             $ids[] = $Product->getId();
  219.         }
  220.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  221.         // addCart form
  222.         $forms = [];
  223.         foreach ($pagination as $Product) {
  224.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  225.             $builder $this->formFactory->createNamedBuilder(
  226.                 '',
  227.                 AddCartType::class,
  228.                 null,
  229.                 [
  230.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  231.                     'allow_extra_fields' => true,
  232.                 ]
  233.             );
  234.             $addCartForm $builder->getForm();
  235.             $forms[$Product->getId()] = $addCartForm->createView();
  236.         }
  237.         // 表示件数
  238.         $builder $this->formFactory->createNamedBuilder(
  239.             'disp_number',
  240.             ProductListMaxType::class,
  241.             null,
  242.             [
  243.                 'required' => false,
  244.                 'allow_extra_fields' => true,
  245.             ]
  246.         );
  247.         if ($request->getMethod() === 'GET') {
  248.             $builder->setMethod('GET');
  249.         }
  250.         $event = new EventArgs(
  251.             [
  252.                 'builder' => $builder,
  253.             ],
  254.             $request
  255.         );
  256.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_DISP$event);
  257.         $dispNumberForm $builder->getForm();
  258.         $dispNumberForm->handleRequest($request);
  259.         // ソート順
  260.         $builder $this->formFactory->createNamedBuilder(
  261.             'orderby',
  262.             ProductListOrderByType::class,
  263.             null,
  264.             [
  265.                 'required' => false,
  266.                 'allow_extra_fields' => true,
  267.             ]
  268.         );
  269.         if ($request->getMethod() === 'GET') {
  270.             $builder->setMethod('GET');
  271.         }
  272.         $event = new EventArgs(
  273.             [
  274.                 'builder' => $builder,
  275.             ],
  276.             $request
  277.         );
  278.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_ORDER$event);
  279.         $orderByForm $builder->getForm();
  280.         $orderByForm->handleRequest($request);
  281.         $Category $searchForm->get('category_id')->getData();
  282.         $tops $this->productRepository->findProductsByTop("Y");
  283.         // $forms2 = [];
  284.         // foreach ($tops as $Product) {
  285.         //     /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  286.         //     $builder = $this->formFactory->createNamedBuilder(
  287.         //         '',
  288.         //         AddCartType::class,
  289.         //         null,
  290.         //         [
  291.         //             'product' => $ProductsAndClassCategories[$Product->getId()],
  292.         //             'allow_extra_fields' => true,
  293.         //         ]
  294.         //     );
  295.         //     $addCartForm = $builder->getForm();
  296.         //     $forms2[$Product->getId()] = $addCartForm->createView();
  297.         // }
  298.         return [
  299.             'tops' => $tops,
  300.             'subtitle' => $this->getPageTitle($searchData),
  301.             'pagination' => $pagination,
  302.             'search_form' => $searchForm->createView(),
  303.             'disp_number_form' => $dispNumberForm->createView(),
  304.             'order_by_form' => $orderByForm->createView(),
  305.             'forms' => $forms,
  306.             'Category' => $Category,
  307.         ];
  308.     }
  309.     /**
  310.      * 商品詳細画面.
  311.      *
  312.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  313.      * @Template("Product/detail.twig")
  314.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  315.      *
  316.      * @param Request $request
  317.      * @param Product $Product
  318.      *
  319.      * @return array
  320.      */
  321.     public function detail(Request $requestProduct $Product)
  322.     {
  323.         if (!$this->checkVisibility($Product)) {
  324.             throw new NotFoundHttpException();
  325.         }
  326.         $builder $this->formFactory->createNamedBuilder(
  327.             '',
  328.             AddCartType::class,
  329.             null,
  330.             [
  331.                 'product' => $Product,
  332.                 'id_add_product_id' => false,
  333.             ]
  334.         );
  335.         $event = new EventArgs(
  336.             [
  337.                 'builder' => $builder,
  338.                 'Product' => $Product,
  339.             ],
  340.             $request
  341.         );
  342.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE$event);
  343.         $is_favorite false;
  344.         if ($this->isGranted('ROLE_USER')) {
  345.             $Customer $this->getUser();
  346.             $is_favorite $this->customerFavoriteProductRepository->isFavorite($Customer$Product);
  347.         }
  348.         $favorite_count $this->customerFavoriteProductRepository->getFavoriteCount($Product);
  349.         //计算能获取的积分
  350.         $points_rate=0;
  351.         if ($this->isGranted('ROLE_USER')) {
  352.             $CustomerShop $this->customerShopRepository->getCustomerShopByCustomer($this->getUser());
  353.             if($CustomerShop && $CustomerShop->getStatus() == "Y"){
  354.             }
  355.             else{
  356.                 $customerLevel $this->customerLevelRepository->getCustomerLevelByCustomer($this->getUser());
  357.                 if ($customerLevel) {
  358.                     $points_rate $customerLevel->getCustomerLevelDetail()->getDiscount();
  359.                 }
  360.             }
  361.         }
  362.         // edit by gzy 判断是否是商户用户
  363.         $is_shop false;
  364.         $discount 0;
  365.         $user_login "N";
  366.         if ($this->isGranted('ROLE_USER')) {
  367.             $CustomerShop $this->customerShopRepository->getCustomerShopByCustomer($this->getUser());
  368.             if($CustomerShop && $CustomerShop->getStatus() == "Y"){
  369.                 $is_shop true;
  370.                 $discount $CustomerShop->getCustomerShopLevel()->getDiscount();
  371.             }
  372.             $user_login "Y";
  373.         }
  374.         return [
  375.             'title' => $this->title,
  376.             'subtitle' => $Product->getName(),
  377.             'form' => $builder->getForm()->createView(),
  378.             'favorite_count' => $favorite_count,
  379.             'Product' => $Product,
  380.             'is_favorite' => $is_favorite,
  381.             'is_shop' => $is_shop,
  382.             'discount' =>$discount,
  383.             'points_rate' =>$points_rate,
  384.             'user_login' => $user_login
  385.         ];
  386.     }
  387.     /**
  388.      * お気に入り追加.
  389.      *
  390.      * @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"})
  391.      */
  392.     public function addFavorite(Request $requestProduct $Product)
  393.     {
  394.         $this->checkVisibility($Product);
  395.         $event = new EventArgs(
  396.             [
  397.                 'Product' => $Product,
  398.             ],
  399.             $request
  400.         );
  401.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE$event);
  402.         if ($this->isGranted('ROLE_USER')) {
  403.             $Customer $this->getUser();
  404.             $this->customerFavoriteProductRepository->addFavorite($Customer$Product);
  405.             $this->session->getFlashBag()->set('product_detail.just_added_favorite'$Product->getId());
  406.             $event = new EventArgs(
  407.                 [
  408.                     'Product' => $Product,
  409.                 ],
  410.                 $request
  411.             );
  412.             $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE$event);
  413.             return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]);
  414.         } else {
  415.             // 非会員の場合、ログイン画面を表示
  416.             //  ログイン後の画面遷移先を設定
  417.             $this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
  418.             $this->session->getFlashBag()->set('eccube.add.favorite'true);
  419.             $event = new EventArgs(
  420.                 [
  421.                     'Product' => $Product,
  422.                 ],
  423.                 $request
  424.             );
  425.             $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE$event);
  426.             return $this->redirectToRoute('mypage_login');
  427.         }
  428.     }
  429.     /**
  430.      * カートに追加.
  431.      *
  432.      * @Route("/products/add_cart/{id}", name="product_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
  433.      */
  434.     public function addCart(Request $requestProduct $Product)
  435.     {
  436.         // エラーメッセージの配列
  437.         $errorMessages = [];
  438.         if (!$this->checkVisibility($Product)) {
  439.             throw new NotFoundHttpException();
  440.         }
  441.         $builder $this->formFactory->createNamedBuilder(
  442.             '',
  443.             AddCartType::class,
  444.             null,
  445.             [
  446.                 'product' => $Product,
  447.                 'id_add_product_id' => false,
  448.             ]
  449.         );
  450.         $event = new EventArgs(
  451.             [
  452.                 'builder' => $builder,
  453.                 'Product' => $Product,
  454.             ],
  455.             $request
  456.         );
  457.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE$event);
  458.         /* @var $form \Symfony\Component\Form\FormInterface */
  459.         $form $builder->getForm();
  460.         $form->handleRequest($request);
  461.         if (!$form->isValid()) {
  462.             throw new NotFoundHttpException();
  463.         }
  464.         $addCartData $form->getData();
  465.         log_info(
  466.             'カート追加処理開始',
  467.             [
  468.                 'product_id' => $Product->getId(),
  469.                 'product_class_id' => $addCartData['product_class_id'],
  470.                 'quantity' => $addCartData['quantity'],
  471.             ]
  472.         );
  473.         // カートへ追加
  474.         $this->cartService->addProduct($addCartData['product_class_id'], $addCartData['quantity']);
  475.         // 明細の正規化
  476.         $Carts $this->cartService->getCarts();
  477.         foreach ($Carts as $Cart) {
  478.             $result $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart$this->getUser()));
  479.             // 復旧不可のエラーが発生した場合は追加した明細を削除.
  480.             if ($result->hasError()) {
  481.                 $this->cartService->removeProduct($addCartData['product_class_id']);
  482.                 foreach ($result->getErrors() as $error) {
  483.                     $errorMessages[] = $error->getMessage();
  484.                 }
  485.             }
  486.             foreach ($result->getWarning() as $warning) {
  487.                 $errorMessages[] = $warning->getMessage();
  488.             }
  489.         }
  490.         $this->cartService->save();
  491.         log_info(
  492.             'カート追加処理完了',
  493.             [
  494.                 'product_id' => $Product->getId(),
  495.                 'product_class_id' => $addCartData['product_class_id'],
  496.                 'quantity' => $addCartData['quantity'],
  497.             ]
  498.         );
  499.         $event = new EventArgs(
  500.             [
  501.                 'form' => $form,
  502.                 'Product' => $Product,
  503.             ],
  504.             $request
  505.         );
  506.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE$event);
  507.         if ($event->getResponse() !== null) {
  508.             return $event->getResponse();
  509.         }
  510.         if ($request->isXmlHttpRequest()) {
  511.             // ajaxでのリクエストの場合は結果をjson形式で返す。
  512.             // 初期化
  513.             $done null;
  514.             $messages = [];
  515.             if (empty($errorMessages)) {
  516.                 // エラーが発生していない場合
  517.                 $done true;
  518.                 array_push($messagestrans('front.product.add_cart_complete'));
  519.             } else {
  520.                 // エラーが発生している場合
  521.                 $done false;
  522.                 $messages $errorMessages;
  523.             }
  524.             return $this->json(['done' => $done'messages' => $messages]);
  525.         } else {
  526.             // ajax以外でのリクエストの場合はカート画面へリダイレクト
  527.             foreach ($errorMessages as $errorMessage) {
  528.                 $this->addRequestError($errorMessage);
  529.             }
  530.             return $this->redirectToRoute('cart');
  531.         }
  532.     }
  533.     /**
  534.      * ページタイトルの設定
  535.      *
  536.      * @param  null|array $searchData
  537.      *
  538.      * @return str
  539.      */
  540.     protected function getPageTitle($searchData)
  541.     {
  542.         if (isset($searchData['name']) && !empty($searchData['name'])) {
  543.             return trans('front.product.search_result');
  544.         } elseif (isset($searchData['category_id']) && $searchData['category_id']) {
  545.             return $searchData['category_id']->getName();
  546.         } else {
  547.             return trans('front.product.all_products');
  548.         }
  549.     }
  550.     /**
  551.      * 閲覧可能な商品かどうかを判定
  552.      *
  553.      * @param Product $Product
  554.      *
  555.      * @return boolean 閲覧可能な場合はtrue
  556.      */
  557.     protected function checkVisibility(Product $Product)
  558.     {
  559.         $is_admin $this->session->has('_security_admin');
  560.         // 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
  561.         if (!$is_admin) {
  562.             // 在庫なし商品の非表示オプションが有効な場合.
  563.             // if ($this->BaseInfo->isOptionNostockHidden()) {
  564.             //     if (!$Product->getStockFind()) {
  565.             //         return false;
  566.             //     }
  567.             // }
  568.             // 公開ステータスでない商品は表示しない.
  569.             if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  570.                 return false;
  571.             }
  572.         }
  573.         return true;
  574.     }
  575.     /**
  576.      * @Route("/products/createProduct", name="products_create_product", methods={"POST"})
  577.      */
  578.     public function createProduct(Request $request)
  579.     {
  580.         $json_data $request->getContent();
  581.         log_info(
  582.             'createProduct:json_data',
  583.             [
  584.                 'json_data' => $json_data,
  585.             ]
  586.         );
  587.         $datas json_decode($json_datatrue);
  588.         $ret = [];
  589.         foreach ($datas as $data) {
  590.             $name $data["name"];
  591.             $note $data["note"];
  592.             $description_list $data["description_list"];
  593.             $description_detail $data["description_detail"];
  594.             $search_word $data["search_word"];
  595.             $free_area $data["free_area"];
  596.             $product_code $data["product_code"]; 
  597.             $stock $data["stock"];
  598.             $stock_unlimited $data["stock_unlimited"];
  599.             $price01 $data["price01"];
  600.             $price02 $data["price02"];
  601.             $category_id_ec4 $data["category_id_ec4"];
  602.             $file_name_arr $data["file_name_arr"];
  603.             $keys $data["keys"];
  604.             $values $data["values"];
  605.             $Product = new \Eccube\Entity\Product();
  606.             $Member $this->memberRepository->findOneBy(['id' => 1]);
  607.             $Product->setCreator($Member);
  608.             $ProductStatus $this->productStatusRepository->findOneBy(['id' => 1]);
  609.             $Product->setStatus($ProductStatus);
  610.             $Product->setCreateDate(new \DateTime());
  611.             $Product->setUpdateDate(new \DateTime());
  612.             $Product->setName($name);
  613.             $Product->setNote($note);
  614.             $Product->setDescriptionList($description_list);
  615.             $Product->setDescriptionDetail($description_detail);
  616.             $Product->setSearchWord($search_word);
  617.             $Product->setFreeArea($free_area);
  618.             $this->entityManager->persist($Product);
  619.             $this->entityManager->flush();
  620.             $ProductClass = new \Eccube\Entity\ProductClass();
  621.             $SaleType $this->saleTypeRepository->findOneBy(['id' => 1]);
  622.             $ProductClass->setSaleType($SaleType);
  623.             $ProductClass->setCreator($Member);
  624.             $ProductClass->setVisible(1);
  625.             $ProductClass->setCreateDate(new \DateTime());
  626.             $ProductClass->setUpdateDate(new \DateTime());
  627.             $ProductClass->setCurrencyCode("JPY");
  628.             $ProductClass->setProduct($Product);
  629.             $ProductClass->setCode($product_code);
  630.             $ProductClass->setStock($stock);
  631.             $ProductClass->setStockUnlimited($stock_unlimited);
  632.             $ProductClass->setPrice01($price01);
  633.             $ProductClass->setPrice02($price02);
  634.             $this->entityManager->persist($ProductClass);
  635.             $this->entityManager->flush();
  636.             $ProductStock = new \Eccube\Entity\ProductStock();
  637.             $ProductStock->setCreateDate(new \DateTime());
  638.             $ProductStock->setUpdateDate(new \DateTime());
  639.             $ProductStock->setProductClass($ProductClass);
  640.             $ProductStock->setCreator($Member);
  641.             $ProductStock->setStock($stock);
  642.             $this->entityManager->persist($ProductStock);
  643.             $this->entityManager->flush();
  644.             $index 1;
  645.             foreach ($file_name_arr as $file_name) {
  646.                 $ProductImage = new \Eccube\Entity\ProductImage();
  647.                 $ProductImage->setCreator($Member);
  648.                 $ProductImage->setCreateDate(new \DateTime());
  649.                 $ProductImage->setSortNo($index);
  650.                 $ProductImage->setProduct($Product);
  651.                 $ProductImage->setFileName($file_name);
  652.                 $index += 1;
  653.                 $this->entityManager->persist($ProductImage);
  654.                 $this->entityManager->flush();
  655.             }
  656.             
  657.             $Category $this->categoryRepository->findOneBy(['id' => $category_id_ec4]);
  658.             if($Category){
  659.                 $ProductCategory = new \Eccube\Entity\ProductCategory();
  660.                 $ProductCategory->setProduct($Product);
  661.                 $ProductCategory->setProductId($Product->getId());
  662.                 $ProductCategory->setCategory($Category);
  663.                 $ProductCategory->setCategoryId($Category->getId());
  664.                 $this->entityManager->persist($ProductCategory);
  665.                 $this->entityManager->flush();
  666.             }
  667.             else{
  668.                 $Category $this->categoryRepository->findOneBy(['id' => 7]);
  669.                 $ProductCategory = new \Eccube\Entity\ProductCategory();
  670.                 $ProductCategory->setProduct($Product);
  671.                 $ProductCategory->setProductId($Product->getId());
  672.                 $ProductCategory->setCategory($Category);
  673.                 $ProductCategory->setCategoryId($Category->getId());
  674.                 $this->entityManager->persist($ProductCategory);
  675.                 $this->entityManager->flush();
  676.                 $ret[] = $category_id_ec4;
  677.             }
  678.             
  679.             $index 1;
  680.             $key_index 0;
  681.             foreach ($keys as $key) {
  682.                 $ProductOptionName = new \Plugin\ProductOption4\Entity\ProductOptionName();
  683.                 $ProductOptionName->setShowFlg(1);
  684.                 $ProductOptionName->setUid(1);
  685.                 $ProductOptionName->setProduct($Product);
  686.                 $ProductOptionName->setName($key);
  687.                 $ProductOptionName->setRank($index);
  688.                 $ProductOptionName->setCreateDate(new \DateTime());
  689.                 $ProductOptionName->setUpdateDate(new \DateTime());
  690.                 $this->entityManager->persist($ProductOptionName);
  691.                 $this->entityManager->flush();
  692.                 foreach ($values[$key_index] as $v) {
  693.                     $ProductOptionCategory = new \Plugin\ProductOption4\Entity\ProductOptionCategory();
  694.                     $ProductOptionCategory->setProductOptionName($ProductOptionName);
  695.                     $ProductOptionCategory->setName($v);
  696.                     $ProductOptionCategory->setCode($product_code "-" strval($index));
  697.                     $ProductOptionCategory->setVisible(1);
  698.                     $ProductOptionCategory->setPrice(0);
  699.                     $ProductOptionCategory->setRank($index);
  700.                     $ProductOptionCategory->setCreateDate(new \DateTime());
  701.                     $ProductOptionCategory->setUpdateDate(new \DateTime());
  702.                     $this->entityManager->persist($ProductOptionCategory);
  703.                     $this->entityManager->flush();
  704.                     $index += 1;
  705.                 }
  706.                 $key_index += 1;
  707.             }
  708.         }
  709.         $response = new Response();
  710.         $response->headers->set('Content-Type''application/json');
  711.         if(count($ret) > 0){
  712.             $response->setContent(json_encode($ret));
  713.         }
  714.         else{
  715.             $response->setContent(json_encode("Y"));
  716.         }
  717.         
  718.         return $response;
  719.     }
  720.     /**
  721.      * @Route("/products/ec4autoFavReview", name="products_fav_review", methods={"POST"})
  722.      */
  723.     public function ec4autoFavReview(Request $request)
  724.     {
  725.         $json_data $request->getContent();
  726.         log_info(
  727.             'ec4autoFavReview:json_data',
  728.             [
  729.                 'json_data' => $json_data,
  730.             ]
  731.         );
  732.         $datas json_decode($json_datatrue);
  733.         foreach ($datas as $data) {
  734.             // $reviewer_url = $data["reviewer_url"];
  735.             $product_id $data["product_id"];
  736.             $reviewer_name $data["reviewer_name"];
  737.             $title $data["title"];
  738.             $comment $data["comment"];
  739.             $recommend_level $data["recommend_level"];
  740.             $fav $data["fav"];
  741.             $Product $this->productRepository->findOneBy(['id' => $product_id]);
  742.             for ($i 1$i <= $fav$i++) {
  743.                 $CustomerFavoriteProduct = new \Eccube\Entity\CustomerFavoriteProduct();
  744.                 $CustomerFavoriteProduct->setProduct($Product);
  745.                 $CustomerFavoriteProduct->setCreateDate(new \DateTime());
  746.                 $CustomerFavoriteProduct->setUpdateDate(new \DateTime());
  747.                 $this->entityManager->persist($CustomerFavoriteProduct);
  748.                 $this->entityManager->flush();
  749.             }
  750.             
  751.             $ProductReview = new \Plugin\ProductReview4\Entity\ProductReview();
  752.             $ProductReview->setProduct($Product);
  753.             $ProductReviewStatus $this->productReviewStatusRepository->findOneBy(['id' => 1]);
  754.             $ProductReview->setStatus($ProductReviewStatus);
  755.             $ProductReview->setReviewerName($reviewer_name);
  756.             // $ProductReview->setReviewerUrl($reviewer_url);
  757.             $ProductReview->setTitle($title);
  758.             $ProductReview->setComment($comment);
  759.             $ProductReview->setRecommendLevel($recommend_level);
  760.             $ProductReview->setCreateDate(new \DateTime());
  761.             $ProductReview->setUpdateDate(new \DateTime());
  762.              $this->entityManager->persist($ProductReview);
  763.             $this->entityManager->flush();
  764.         }
  765.         $response = new Response();
  766.         $response->headers->set('Content-Type''application/json');
  767.         $response->setContent(json_encode("Y"));
  768.         return $response;
  769.     }
  770.     /**
  771.      * @Route("/products/udpateGigaStock", name="products_udpate_giga_stock", methods={"POST"})
  772.      */
  773.     public function udpateGigaStock(Request $request)
  774.     {
  775.         try {
  776.             $json_data $request->getContent();
  777.             $datas json_decode($json_datatrue);
  778.             // log_info(
  779.             //     'udpateGigaStock:json_data',
  780.             //     [
  781.             //         'json_data' => $json_data,
  782.             //     ]
  783.             // );
  784.             foreach ($datas as $data) {
  785.                 $ret "Y";
  786.                 $product_code $data['product_code'];
  787.                 $stock $data['stock'];
  788.                 log_info(
  789.                     'udpateGigaStock:product_code',
  790.                     [
  791.                         'product_code' => $product_code,
  792.                     ]
  793.                 );
  794.                 log_info(
  795.                     'udpateGigaStock:stock',
  796.                     [
  797.                         'stock' => $stock,
  798.                     ]
  799.                 );
  800.                 $productClass $this->productClassRepository->findOneBy([
  801.                     'code' => $product_code,
  802.                 ]);
  803.                 if($productClass && !empty($productClass)){
  804.                     // log_info(
  805.                     //     'udpateGigaStock:productClass',
  806.                     //     [
  807.                     //         'productClass' => $productClass->getId(),
  808.                     //     ]
  809.                     // );
  810.                     $productClass->setStock($stock);
  811.                     $ProductStock $productClass->getProductStock();
  812.                     if($ProductStock){
  813.                         $ProductStock->setStock($stock);
  814.                         $this->entityManager->persist($ProductStock);
  815.                     }
  816.                     $this->entityManager->flush();
  817.                 }
  818.                 else{
  819.                     log_info(
  820.                         'udpateGigaStock:nonono',
  821.                         [
  822.                             'nonono' => "nonono productClass",
  823.                         ]
  824.                     );
  825.                     $ret "No Product in this site.";
  826.                 }
  827.             }
  828.             $ret = array(
  829.                 'status' => $ret
  830.             );
  831.         } catch (\Exception $e) {
  832.             log_info(
  833.                 'udpateGigaStock:eeeeeeee',
  834.                 [
  835.                     'eeeeeeee' => json_encode($e),
  836.                 ]
  837.             );
  838.             $ret = array(
  839.                 'status' => "N",
  840.                 'eee' => $e
  841.             );
  842.         }
  843.         $response = new Response();
  844.         $response->headers->set('Content-Type''application/json');
  845.         $response->setContent(json_encode($ret));
  846.         return $response;
  847.         
  848.     }
  849.     /**
  850.      * query getNews
  851.      * @Route("/products/getNews", name="products_news")
  852.      */
  853.     public function getNews(Request $request) {
  854.         $Pluginnews $this->pluginnewRepository->getNews();
  855.         $rets = [];
  856.         foreach ($Pluginnews as $Pluginnew) {
  857.             $ret = array(
  858.                 'name'=>$Pluginnew->getName()
  859.             );
  860.             $rets[] = $ret;
  861.         }
  862.         $response = new Response();
  863.         $response->headers->set('Content-Type''application/json');
  864.         
  865.         $response->setContent(json_encode($rets));
  866.         return $response;
  867.     }
  868.     /**
  869.      * @Route("/products/setNews", name="products_set_news", methods={"POST"})
  870.      */
  871.     public function setNews(Request $request)
  872.     {
  873.         $json_data $request->getContent();
  874.         $datas json_decode($json_datatrue);
  875.         foreach ($datas as $data) {
  876.             $Pluginnew = new \Eccube\Entity\Pluginnew();
  877.             $Pluginnew->setName($data["name"]);
  878.             $Pluginnew->setCreateDate(new \DateTime());
  879.             $Pluginnew->setUpdateDate(new \DateTime());
  880.             $this->entityManager->persist($Pluginnew);
  881.             $this->entityManager->flush();
  882.         }
  883.         $response = new Response();
  884.         $response->headers->set('Content-Type''application/json');
  885.         $response->setContent(json_encode("Y"));
  886.         return $response;
  887.     }
  888.     /**
  889.      * @Route("/products/createRakutenCategory", name="products_create_rakuten_category", methods={"POST"})
  890.      */
  891.     public function createRakutenCategory(Request $request)
  892.     {
  893.         $json_data $request->getContent();
  894.         log_info(
  895.             'createRakutenCategory:json_data',
  896.             [
  897.                 'json_data' => $json_data,
  898.             ]
  899.         );
  900.         $datas json_decode($json_datatrue);
  901.         $ret = [];
  902.         foreach ($datas as $data) {
  903.             $code $data["code"];
  904.             $name1 $data["name1"];
  905.             $name2 $data["name2"];
  906.             $name3 $data["name3"];
  907.             $project $data["project"];
  908.             $bitian $data["bitian"];
  909.             $RakutenCategory = new \Eccube\Entity\RakutenCategory();
  910.             $RakutenCategory->setCode($code);
  911.             $RakutenCategory->setName1($name1);
  912.             $RakutenCategory->setName2($name2);
  913.             $RakutenCategory->setName3($name3);
  914.             $RakutenCategory->setProject($project);
  915.             $RakutenCategory->setBitian($bitian);
  916.             $this->entityManager->persist($RakutenCategory);
  917.             $this->entityManager->flush();
  918.         }
  919.         $response = new Response();
  920.         $response->headers->set('Content-Type''application/json');
  921.         if(count($ret) > 0){
  922.             $response->setContent(json_encode($ret));
  923.         }
  924.         else{
  925.             $response->setContent(json_encode("Y"));
  926.         }
  927.         
  928.         return $response;
  929.     }
  930. }