app/Customize/Controller/CustomProduct/CustomBreathred/CustomBreathredBaseController.php line 73

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller\CustomProduct\CustomBreathred;
  3. use Codeception\Lib\Di;
  4. use Codeception\Util\FileSystem as UtilFileSystem;
  5. use Customize\Entity\CustomJewel;
  6. use Customize\Entity\Jewel;
  7. use Customize\Entity\JewelPart;
  8. use Customize\Entity\Breathred;
  9. use Customize\Form\Type\JewelType;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Eccube\Repository\Master\SaleTypeRepository;
  14. use Customize\Repository\JewelRepository;
  15. use Customize\Repository\CustomProductRepository;
  16. use Customize\Repository\JewelPartRepository;
  17. use Customize\Repository\BreathredRepository;
  18. use Customize\Repository\RepairRepository;
  19. use Doctrine\ORM\Query\Expr\Func;
  20. use Eccube\Controller\AbstractController;
  21. use Eccube\Entity\CartItem;
  22. use Eccube\Util\CacheUtil;
  23. use Eccube\Entity\BaseInfo;
  24. use Eccube\Entity\Master\ProductStatus;
  25. use Eccube\Entity\Master\SaleType;
  26. use Eccube\Entity\Product;
  27. use Eccube\Entity\ProductCategory;
  28. use Eccube\Entity\ProductClass;
  29. use Eccube\Entity\ProductImage;
  30. use Eccube\Entity\ProductStock;
  31. use Eccube\Entity\ProductTag;
  32. use Eccube\Entity\TaxRule;
  33. use Eccube\Repository\TaxRuleRepository;
  34. use Eccube\Service\PurchaseFlow\PurchaseContext;
  35. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  36. use Customize\Service\CartService;
  37. use Eccube\Service\TaxRuleService;
  38. use Eccube\Event\EccubeEvents;
  39. use Eccube\Event\EventArgs;
  40. use Eccube\Form\Type\AddCartType;
  41. use Eccube\Form\Type\Admin\ProductType;
  42. use Google\Service\Adsense\Alert;
  43. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  44. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  45. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  46. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  47. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  48. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  49. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  50. use Symfony\Component\Form\Extension\Core\Type\TextType;
  51. use Symfony\Component\Form\FormBuilder;
  52. use Symfony\Component\HttpFoundation\JsonResponse;
  53. use Symfony\Component\HttpFoundation\Request;
  54. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  55. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  56. use Eccube\Repository\BaseInfoRepository;
  57. use Symfony\Component\Routing\Annotation\Route;
  58. use Eccube\Repository\Master\ProductStatusRepository;
  59. use Google\Service\HangoutsChat\Resource\Dms;
  60. use Knp\Component\Pager\PaginatorInterface;
  61. use PDO;
  62. use Symfony\Component\Filesystem\Filesystem;
  63. use Symfony\Component\Finder\Finder;
  64. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  65. use Symfony\Component\Form\Extension\Core\Type\FileType;
  66. use Symfony\Component\HttpFoundation\File\File;
  67. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  68. use function GuzzleHttp\Promise\each;
  69. class CustomBreathredBaseController extends AbstractController
  70. {
  71.    /**
  72.     * @var ProductStatusRepository
  73.     */
  74.    protected $productStatusRepository;
  75.    /**
  76.     * @var SaleTypeRepository
  77.     */
  78.    protected $saleTypeRepository;
  79.    /**
  80.     * @var PurchaseFlow
  81.     */
  82.    protected $purchaseFlow;
  83.    /**
  84.     * @var CartService
  85.     */
  86.    protected $cartService;
  87.    /**
  88.     * @var JewelRepository
  89.     */
  90.    protected $jewelRepository;
  91.    /**
  92.     * @var JewelPartRepository
  93.     */
  94.    protected $jewelPartRepository;
  95.    /**
  96.     * @var CustomProductRepository
  97.     */
  98.    protected $customProductRepository;
  99.    /**
  100.     * @var BaseInfo
  101.     */
  102.    protected $BaseInfo;
  103.    /**
  104.     * @var TaxRuleService
  105.     */
  106.    protected $taxRuleService;
  107.    /**
  108.     * @var TaxRuleRepository
  109.     */
  110.    protected $taxRuleRepository;
  111.    /**
  112.     * @var SessionInterface
  113.     */
  114.    protected $session;
  115.    /**
  116.     * @var RepairRepository
  117.     */
  118.    protected $repairRepository;
  119.    /**
  120.     * @var BreathredRepository
  121.     */
  122.    protected $breathredRepository;
  123.    /**
  124.     *
  125.     *
  126.     * constructor.
  127.     *
  128.     *  @param JewelRepository $jewelRepository
  129.     *  @param CustomProductRepository $customProductRepository
  130.     *  @param CartService $cartService
  131.     *  @param ProductStatusRepository $productStatusRepository
  132.     *  @param BaseInfoRepository $baseInfoRepository
  133.     *  @param SaleTypeRepository $saleTypeRepository
  134.     *  @param PurchaseFlow $cartPurchaseFlow
  135.     *  @param TaxRuleService $taxRuleService
  136.     *  @param TaxRuleRepository $taxRuleRepository
  137.     *  @param SessionInterface $session
  138.     *  @param JewelPartRepository $jewelPartRepository
  139.     *  @param RepairRepository $repairRepository
  140.     *  @param BreathredRepository $breathredRepository
  141.     *
  142.     */
  143.    public function __construct(
  144.       JewelRepository $jewelRepository,
  145.       CartService $cartService,
  146.       CustomProductRepository $customProductRepository,
  147.       ProductStatusRepository $productStatusRepository,
  148.       BaseInfoRepository $baseInfoRepository,
  149.       SaleTypeRepository $saleTypeRepository,
  150.       PurchaseFlow $cartPurchaseFlow,
  151.       TaxRuleService $taxRuleService,
  152.       TaxRuleRepository $taxRuleRepository,
  153.       SessionInterface $session,
  154.       JewelPartRepository $jewelPartRepository,
  155.       RepairRepository $repairRepository,
  156.       BreathredRepository $breathredRepository
  157.    ) {
  158.       $this->jewelRepository $jewelRepository;
  159.       $this->cartService $cartService;
  160.       $this->customProductRepository $customProductRepository;
  161.       $this->productStatusRepository $productStatusRepository;
  162.       $this->BaseInfo $baseInfoRepository->get();
  163.       $this->saleTypeRepository $saleTypeRepository;
  164.       $this->purchaseFlow $cartPurchaseFlow;
  165.       $this->taxRuleService $taxRuleService;
  166.       $this->taxRuleRepository $taxRuleRepository;
  167.       $this->session $session;
  168.       $this->jewelPartRepository $jewelPartRepository;
  169.       $this->repairRepository $repairRepository;
  170.       $this->breathredRepository $breathredRepository;
  171.    }
  172.    /**
  173.     * //選んだカスタムリングとジュエルのidをsessionにセーブ
  174.     * @Route("/custom_breathred_session", name="custom_breathred_session")
  175.     */
  176.    public function BreathredSession(Request $request)
  177.    {
  178.       if ($request->isXmlHttpRequest()) {
  179.          $doct $this->getDoctrine()->getManager();
  180.          $session $request->getSession();
  181.          
  182.          
  183.          if ($request->request->get('breathred_id') != null) {
  184.             $id intval($request->request->get('breathred_id'));
  185.             $session->set('breathred_id'$id);
  186.             $breathred $doct->getRepository(Breathred::class)->find($id);
  187.             if ($breathred === null) {
  188.                return new JsonResponse(array('status' => 'Error'), 400);
  189.             }
  190.             $breathred_price $breathred->getPrice();
  191.             $socket $breathred->getSocket();
  192.             $session->set('breathred_price'$breathred_price);
  193.             $upload_directory $this->getParameter('uploads_directory');
  194.             $finder = new Finder();
  195.             //image
  196.             $display_image 'html/upload/save_image/customRing/breathred/' $breathred->getBreathredShape() . '/' $breathred->getBreathredType() . '/main/' $breathred->getImageName();
  197.             $list_image 'html/upload/save_image/customRing/breathred/' $breathred->getBreathredShape() . '/' $breathred->getBreathredType() . '/list/' $breathred->getImageName();
  198.             //vrの画像
  199.             $vr 'VR';
  200.             $upload 'html/upload/save_image/customRing/breathred/' $breathred->getBreathredShape() . '/' $breathred->getBreathredType() . '/main/' $vr '/';
  201.             
  202.             $finder->in($upload)->directories()->depth("==0");
  203.             $path = array();
  204.             $vr_image = array();
  205.             if ($finder->hasResults()) {
  206.                foreach ($finder as $folder) {
  207.                   $folder $folder '/';
  208.                   array_push($path$folder);
  209.                }
  210.                //image path
  211.                for ($i 0$i count($path); $i++) {
  212.                   $images glob($path[$i] . "*.{jpg,png,jpeg,JPG,JPEG,PNG}"GLOB_BRACE);
  213.                   $img_temp explode('save_image/'$images[1]);
  214.                   $temp explode('save_image/'$path[$i]);
  215.                   $path[$i] = $temp[1];
  216.                   array_push($vr_image$img_temp[1]);
  217.                }
  218.             }
  219.             return new JsonResponse(array('status' => 'done''item_price' => $breathred_price'path' => $path'image' => $display_image'list_image'=> $list_image'vr_img' => $vr_image'socket' => $socket), 200);
  220.          }
  221.       }
  222.       return new JsonResponse(array('status' => 'Error'), 400);
  223.    }
  224.    /**
  225.     * 
  226.     * @Method("GET", "POST")
  227.     * @Route("/custom_breathred_base", name="custom_breathred_base") #URLを指定
  228.     * @Template("CustomProduct/CustomBreathred/custom_base.twig") #ページ遷移先を指定
  229.     *
  230.     */
  231.    public function CustomBreathredBase(Request $requestPaginatorInterface $paginator)
  232.    {
  233.       if(!array_key_exists('HTTP_REFERER'$_SERVER)){
  234.          return $this->redirectToRoute('homepage');
  235.      }
  236.       $breathred $this->breathredRepository->customFindAll();
  237.       
  238.       $session $request->getSession();
  239.       //mypageから移動させられないとカスタマイズのsessionを除去
  240.       if(str_contains($_SERVER['HTTP_REFERER'], 'mypage')){
  241.          
  242.          //dd($_SERVER);
  243.       }else{
  244.          $session->remove('customize_part_id');
  245.          $session->remove('customize_part_type');
  246.          $session->remove('customize_product_name');
  247.          $session->remove('customize_custom_id');
  248.       }
  249.       $customize_type $session->get('customize_part_type');
  250.       $customize_id $session->get('customize_part_id');
  251.       $customize_jewel $session->get('customize_jewel');
  252.       
  253.       if($customize_type == 'jewel_part'){
  254.          $jewel $this->jewelRepository->CustomFindWithID($customize_jewel)[0];
  255.          $jewel_part $this->jewelPartRepository->CustomFindWithID($customize_id)[0];
  256.          $breathred $this->breathredRepository->CustomFindWithType($jewel_part->getJewelPartType());
  257.        }
  258.        else if($customize_type == 'jewel'){
  259.          $jewel $this->jewelRepository->CustomFindWithID($customize_id)[0];
  260.          $jewel_part['image_name'] = null;
  261.        }
  262.        else{
  263.          $jewel['image_name'] = null;
  264.          $jewel_part['image_name'] = null;
  265.        }
  266.       
  267.       
  268.       return [
  269.          'breathreds' => $breathred,
  270.          'customize_type' => $customize_type,
  271.          'customize_id' => $customize_id,
  272.          'customize_jewel' => $customize_jewel,
  273.          'jewel' => $jewel,
  274.          'jewel_part' => $jewel_part
  275.       ];
  276.    }
  277. }