app/Customize/Form/Extension/AddCartTypeEx.php line 706

Open in your IDE?
  1. <?php
  2. /**
  3.  * EntityType
  4.  * https://symfony.com/doc/current/reference/forms/types/entity.html#expanded
  5.  */
  6. namespace Customize\Form\Extension;
  7. use Eccube\Form\Type\AddCartType;
  8. use Symfony\Component\Form\AbstractTypeExtension;
  9. use Doctrine\ORM\EntityManager;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Eccube\Common\EccubeConfig;
  12. use Eccube\Entity\CartItem;
  13. use Eccube\Entity\ProductClass;
  14. use Eccube\Form\DataTransformer\EntityToIdTransformer;
  15. use Eccube\Repository\ProductClassRepository;
  16. use Eccube\Repository\ProductRepository;
  17. use Symfony\Component\Form\AbstractType;
  18. use Symfony\Component\Form\Extension\Core\Type\FileType;
  19. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextType;
  21. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  22. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  23. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  24. use Symfony\Component\Form\Extension\Core\Type\DateType;
  25. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  26. use Symfony\Component\Form\FormBuilderInterface;
  27. use Symfony\Component\Form\FormEvent;
  28. use Symfony\Component\Form\FormEvents;
  29. use Symfony\Component\Form\FormInterface;
  30. use Symfony\Component\Form\FormView;
  31. use Symfony\Component\OptionsResolver\OptionsResolver;
  32. use Symfony\Component\Validator\Constraints as Assert;
  33. use Symfony\Component\Validator\Context\ExecutionContext;
  34. use Eccube\Service\CartService;
  35. use Customize\Service\FileUploader;
  36. class AddCartTypeEx extends AbstractTypeExtension
  37. {    
  38.     /**
  39.      * @var EccubeConfig
  40.      */
  41.     protected $eccubeConfig;
  42.     protected $productRepository;
  43.     protected $cartService;
  44.     /**
  45.      * @var FileUploader
  46.      */
  47.     protected $fileUploader;
  48.     /**
  49.      * ContactType constructor.
  50.      *
  51.      * @param EccubeConfig $eccubeConfig
  52.      */
  53.     public function __construct(
  54.         FileUploader $fileUploader,
  55.         ProductRepository $productRepository,
  56.         CartService $cartService,
  57.         EccubeConfig $eccubeConfig) {
  58.         $this->fileUploader $fileUploader;
  59.         $this->productRepository $productRepository;
  60.         $this->cartService $cartService;
  61.         $this->eccubeConfig $eccubeConfig;
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public function buildForm(FormBuilderInterface $builder, array $options)
  67.     {   
  68.         $builder            
  69.             ->add('express_tickets_price'HiddenType::class, [])
  70.             ->add('construction_air'HiddenType::class, [])
  71.             ->add('construction_6'NumberType::class, [])
  72.             ->add('construction_16'NumberType::class, [])
  73.             ->add('construction_23'NumberType::class, [])
  74.             ->add('number_install'HiddenType::class, [])
  75.             ->add('number_install_price'HiddenType::class, [])
  76.             ->add('construction_type_07_02_v1_price'HiddenType::class, [])
  77.             ->add('construction_type_07_03_v2_price'HiddenType::class, [])
  78.             ->add('construction_type_07_04_v1_price'HiddenType::class, [])
  79.             ->add('construction_type_07_04_v2_price'HiddenType::class, [])
  80.             ->add('construction_type_07_04_v3_price'HiddenType::class, [])
  81.             ->add('elevator_07_price'HiddenType::class, [])
  82.             ->add('electrical_outlet_07_price'HiddenType::class, [])
  83.             ->add('electrical_outlet_07_02_price'HiddenType::class, [])
  84.             ->add('room_size_07_03_v1_price'HiddenType::class, [])
  85.             ->add('room_size_07_03_v2_price'HiddenType::class, [])
  86.             ->add('piping_status_07_02_price'HiddenType::class, [])
  87.             ->add('indoor_cover_07_price'HiddenType::class, [])
  88.             ->add('outdoor_cover_02_price'HiddenType::class, [])
  89.             ->add('construction_outdoor_07_price'HiddenType::class, [])
  90.             ->add('construction_method_07_v1_price'HiddenType::class, [])
  91.             ->add('construction_method_07_v2_price'HiddenType::class, [])
  92.             ->add('construction_base_price_1'HiddenType::class, [])
  93.             ->add('construction_base_price_2'HiddenType::class, [])
  94.             ->add('construction_base_price_3'HiddenType::class, [])
  95.             ->add('construction_total_price'HiddenType::class, [])
  96.             ->add('construction_discount'HiddenType::class, [])
  97.             //希望する工事
  98.             ->add('desired_construction_work'ChoiceType::class, [
  99.                 'choices'  => [
  100.                     'エアコン本体のみ購入の方' => 'エアコン本体のみ購入の方',
  101.                     'エアコン本体と設置工事をご希望の方' => 'エアコン本体と設置工事をご希望の方',
  102.                 ],
  103.                 'expanded' => true,
  104.                 'multiple' => false,
  105.                 'required' => false,
  106.             ])
  107.             //希望する工事 → エアコン本体と設置工事をご希望の方
  108.             ->add('desired_construction_work_02'ChoiceType::class, [
  109.                 'choices'  => [
  110.                     '最終金額算出' => '最終金額算出',
  111.                     '新居等への引越しのため設置場所の詳細確認不可' => '新居等への引越しのため設置場所の詳細確認不可',
  112.                 ],
  113.                 'expanded' => true,
  114.                 'multiple' => false,
  115.                 'required' => false,
  116.             ])
  117.             // 特急券の購入
  118.             ->add('express_tickets'ChoiceType::class, [
  119.                 'choices'  => [
  120.                     'する' => 'する',
  121.                     'しない' => 'しない',
  122.                 ],
  123.                 'expanded' => true,
  124.                 'multiple' => false,
  125.                 'required' => false,
  126.                 'choice_attr' => function($choice$key$value) {
  127.                     if ($choice === 'する') {
  128.                         return ['price' => 5500];
  129.                     } elseif ($choice === 'しない') {
  130.                         return ['price' => 0];
  131.                     }
  132.                     return [];
  133.                 },
  134.             ])
  135.             // お住まい
  136.             ->add('osumai'ChoiceType::class, [
  137.                 'choices'  => [
  138.                     '一戸建て' => '一戸建て',
  139.                     '集合住宅' => '集合住宅',
  140.                 ],
  141.                 'expanded' => true,
  142.                 'multiple' => false,
  143.                 'required' => false,
  144.             ])
  145.             // 建物の所有
  146.             ->add('building_ownership'ChoiceType::class, [
  147.                 'choices'  => [
  148.                     '持ち家' => '持ち家',
  149.                     '賃貸' => '賃貸',
  150.                 ],
  151.                 'expanded' => true,
  152.                 'multiple' => false,
  153.                 'required' => false,
  154.             ])
  155.             // 構造
  156.             ->add('structure'ChoiceType::class, [
  157.                 'choices'  => [
  158.                     '木造' => '木造',
  159.                     '鉄骨' => '鉄骨',
  160.                     'コンクリート(RC)' => 'コンクリート(RC)',
  161.                     'その他' => 'その他',
  162.                     '不明' => '不明',
  163.                 ],
  164.                 'expanded' => true,
  165.                 'multiple' => false,
  166.                 'required' => false,
  167.             ])
  168.             // // 設置台数
  169.             // ->add('number_install', ChoiceType::class, [
  170.             //     'choices'  => [
  171.             //         '1台' => '1台',
  172.             //         '2台' => '2台',
  173.             //         '3台' => '3台',
  174.             //         '4台以上' => '4台以上',
  175.             //     ],
  176.             //     'expanded' => true,
  177.             //     'multiple' => false,
  178.             //     'required' => false,
  179.             //     'choice_attr' => function($choice, $key, $value) {
  180.             //         if ($choice === '1台') {
  181.             //             return ['percent' => 0];
  182.             //         } elseif ($choice === '2台') {
  183.             //             return ['percent' => 0.05];
  184.             //         } elseif ($choice === '3台') {
  185.             //             return ['percent' => 0.1];
  186.             //         } elseif ($choice === '4台以上') {
  187.             //             return ['percent' => 0.15];
  188.             //         }
  189.             //         return [];
  190.             //     },
  191.             // ])            
  192.             //工事希望日1
  193.             ->add('construction_date_1'DateType::class, [
  194.                 'required' => false,
  195.                 'input' => 'datetime',
  196.                 'widget' => 'single_text',
  197.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  198.             ])
  199.             //工事希望日2
  200.             ->add('construction_date_2'DateType::class, [
  201.                 'required' => false,
  202.                 'input' => 'datetime',
  203.                 'widget' => 'single_text',
  204.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  205.             ])
  206.             //工事希望日3
  207.             ->add('construction_date_3'DateType::class, [
  208.                 'required' => false,
  209.                 'input' => 'datetime',
  210.                 'widget' => 'single_text',
  211.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  212.             ])
  213.             // 希望時間帯_1
  214.             ->add('time_slot_1'ChoiceType::class, [
  215.                 'choices'  => [
  216.                     '午前' => '午前',
  217.                     '午後' => '午後',
  218.                 ],
  219.                 'expanded' => true,
  220.                 'multiple' => false,
  221.                 'required' => false,
  222.             ])
  223.             // 希望時間帯_2
  224.             ->add('time_slot_2'ChoiceType::class, [
  225.                 'choices'  => [
  226.                     '午前' => '午前',
  227.                     '午後' => '午後',
  228.                 ],
  229.                 'expanded' => true,
  230.                 'multiple' => false,
  231.                 'required' => false,
  232.             ])
  233.             // 希望時間帯_3
  234.             ->add('time_slot_3'ChoiceType::class, [
  235.                 'choices'  => [
  236.                     '午前' => '午前',
  237.                     '午後' => '午後',
  238.                 ],
  239.                 'expanded' => true,
  240.                 'multiple' => false,
  241.                 'required' => false,
  242.             ])
  243.             //その他希望
  244.             ->add('contents'TextareaType::class, [
  245.                 'required' => false,
  246.                 'constraints' => [
  247.                     // new Assert\NotBlank(),
  248.                     new Assert\Length([
  249.                         'max' => $this->eccubeConfig['eccube_lltext_len'],
  250.                     ])
  251.                 ],
  252.             ])
  253.             // 工事内訳
  254.             ->add('construction_type_07'ChoiceType::class, [
  255.                 'choices'  => [
  256.                     '新設' => '新設',
  257.                     '交換' => '交換',
  258.                     '新設工事に加えて移設工事も希望' => '新設工事に加えて移設工事も希望',
  259.                 ],
  260.                 'expanded' => true,
  261.                 'multiple' => false,
  262.                 'required' => false,
  263.             ])
  264.             // 工事内訳 → 交換
  265.             ->add('construction_type_07_02_v1'ChoiceType::class, [
  266.                 'choices'  => [
  267.                     '処分を希望する(リサイクル&収集運搬費)' => '処分を希望する(リサイクル&収集運搬費)',
  268.                     '処分を希望しない' => '処分を希望しない',
  269.                 ],
  270.                 'expanded' => true,
  271.                 'multiple' => false,
  272.                 'required' => false,
  273.                 'choice_attr' => function($choice$key$value) {
  274.                     if ($choice === '処分を希望する(リサイクル&収集運搬費)') {
  275.                         return ['price' => 7180];
  276.                     } elseif ($choice === '処分を希望しない') {
  277.                         return ['price' => 5980];
  278.                     }
  279.                     return [];
  280.                 },
  281.             ])
  282.             // 工事内訳 → 新設工事に加えて移設工事も希望
  283.             ->add('construction_type_07_02_v2'ChoiceType::class, [
  284.                 'choices'  => [
  285.                     '分解洗浄を希望する' => '分解洗浄を希望する',
  286.                     '分解洗浄を希望しない' => '分解洗浄を希望しない',
  287.                 ],
  288.                 'expanded' => true,
  289.                 'multiple' => false,
  290.                 'required' => false,
  291.             ])
  292.             // 工事内訳 → 新設工事に加えて移設工事も希望 → 分解洗浄を希望する
  293.             ->add('construction_type_07_03_v1'ChoiceType::class, [
  294.                 'choices'  => [
  295.                     '移設6~14畳(取外し含む)' => '移設6~14畳(取外し含む)',
  296.                     '移設16~20畳(取外し含む)' => '移設16~20畳(取外し含む)',
  297.                     '移設23畳~(取外し含む)' => '移設23畳~(取外し含む)',
  298.                 ],
  299.                 'expanded' => true,
  300.                 'multiple' => false,
  301.                 'required' => false,
  302.             ])
  303.             // 工事内訳 → 新設工事に加えて移設工事も希望 → 分解洗浄を希望しない
  304.             ->add('construction_type_07_03_v2'ChoiceType::class, [
  305.                 'choices'  => [
  306.                     '移設6~14畳(取外し含む)' => '移設6~14畳(取外し含む)',
  307.                     '移設16~20畳(取外し含む)' => '移設16~20畳(取外し含む)',
  308.                     '移設23畳~(取外し含む)' => '移設23畳~(取外し含む)',
  309.                 ],
  310.                 'expanded' => true,
  311.                 'multiple' => false,
  312.                 'required' => false,
  313.                 'choice_attr' => function($choice$key$value) {
  314.                     if ($choice === '移設6~14畳(取外し含む)') {
  315.                         return ['price' => 24980];
  316.                     } elseif ($choice === '移設16~20畳(取外し含む)') {
  317.                         return ['price' => 28980];
  318.                     } elseif ($choice === '移設23畳~(取外し含む)') {
  319.                         return ['price' => 32980];
  320.                     }
  321.                     return [];
  322.                 },
  323.             ])
  324.             // 工事内訳 → 新設工事に加えて移設工事も希望 → 分解洗浄を希望する → 移設6~14畳(取外し含む)
  325.             ->add('construction_type_07_04_v1'ChoiceType::class, [
  326.                 'choices'  => [
  327.                     '掃除機能付き' => '掃除機能付き',
  328.                     '掃除機能なし' => '掃除機能なし',
  329.                 ],
  330.                 'expanded' => true,
  331.                 'multiple' => false,
  332.                 'required' => false,
  333.                 'choice_attr' => function($choice$key$value) {
  334.                     if ($choice === '掃除機能付き') {
  335.                         return ['price' => 50980];
  336.                     } elseif ($choice === '掃除機能なし') {
  337.                         return ['price' => 47980];
  338.                     }
  339.                     return [];
  340.                 },
  341.             ])
  342.             // 工事内訳 → 新設工事に加えて移設工事も希望 → 分解洗浄を希望する → 移設16~20畳(取外し含む)
  343.             ->add('construction_type_07_04_v2'ChoiceType::class, [
  344.                 'choices'  => [
  345.                     '掃除機能付き' => '掃除機能付き',
  346.                     '掃除機能なし' => '掃除機能なし',
  347.                 ],
  348.                 'expanded' => true,
  349.                 'multiple' => false,
  350.                 'required' => false,
  351.                 'choice_attr' => function($choice$key$value) {
  352.                     if ($choice === '掃除機能付き') {
  353.                         return ['price' => 54980];
  354.                     } elseif ($choice === '掃除機能なし') {
  355.                         return ['price' => 51980];
  356.                     }
  357.                     return [];
  358.                 },
  359.             ])
  360.             // 工事内訳 → 新設工事に加えて移設工事も希望 → 分解洗浄を希望する → 移設23畳~(取外し含む)
  361.             ->add('construction_type_07_04_v3'ChoiceType::class, [
  362.                 'choices'  => [
  363.                     '掃除機能付き' => '掃除機能付き',
  364.                     '掃除機能なし' => '掃除機能なし',
  365.                 ],
  366.                 'expanded' => true,
  367.                 'multiple' => false,
  368.                 'required' => false,
  369.                 'choice_attr' => function($choice$key$value) {
  370.                     if ($choice === '掃除機能付き') {
  371.                         return ['price' => 58980];
  372.                     } elseif ($choice === '掃除機能なし') {
  373.                         return ['price' => 55980];
  374.                     }
  375.                     return [];
  376.                 },
  377.             ])
  378.             // エアコン設置場所
  379.             ->add('construction_floor_07'ChoiceType::class, [
  380.                 'choices'  => [
  381.                     '1階' => '1階',
  382.                     '2階' => '2階',
  383.                     '3階' => '3階',
  384.                     '4階以上' => '4階以上',
  385.                     '未定' => '未定',
  386.                 ],
  387.                 'expanded' => true,
  388.                 'multiple' => false,
  389.                 'required' => false,
  390.             ])
  391.             // エレベーターの有無
  392.             ->add('elevator_07'ChoiceType::class, [
  393.                 'choices'  => [
  394.                     'あり' => 'あり',
  395.                     'なし(新設)' => 'なし(新設)',
  396.                     'なし(交換)' => 'なし(交換)',
  397.                 ],
  398.                 'expanded' => true,
  399.                 'multiple' => false,
  400.                 'required' => false,
  401.                 'choice_attr' => function($choice$key$value) {
  402.                     if ($choice === 'あり') {
  403.                         return ['price' => 0];
  404.                     } elseif ($choice === 'なし(新設)') {
  405.                         return ['price' => 5980];
  406.                     } elseif ($choice === 'なし(交換)') {
  407.                         return ['price' => 11980];
  408.                     }
  409.                     return [];
  410.                 },
  411.             ])
  412.             // コンセントの有無
  413.             ->add('electrical_outlet_07'ChoiceType::class, [
  414.                 'choices'  => [
  415.                     'あり' => 'あり',
  416.                     'なし(別途工事が必要になります)' => 'なし(別途工事が必要になります)',
  417.                     '不明' => '不明',
  418.                 ],
  419.                 'expanded' => true,
  420.                 'multiple' => false,
  421.                 'required' => false,
  422.                 'choice_attr' => function($choice$key$value) {
  423.                     if ($choice === 'なし(別途工事が必要になります)') {
  424.                         return ['price' => 16980];
  425.                     }
  426.                     return [];
  427.                 },
  428.             ])
  429.             // コンセントの有無 → あり
  430.             ->add('electrical_outlet_07_02'ChoiceType::class, [
  431.                 'choices'  => [
  432.                     '既存コンセントの延長の有' => '既存コンセントの延長の有',
  433.                     '既存コンセントの延長の無' => '既存コンセントの延長の無',
  434.                 ],
  435.                 'expanded' => true,
  436.                 'multiple' => false,
  437.                 'required' => false,
  438.                 'choice_attr' => function($choice$key$value) {
  439.                     if ($choice === '既存コンセントの延長の有') {
  440.                         return ['price' => 3980];
  441.                     } elseif ($choice === '既存コンセントの延長の無') {
  442.                         return ['price' => 0];
  443.                     }
  444.                     return [];
  445.                 },
  446.             ])
  447.             // 建物の契約アンペア
  448.             ->add('contract_amp'ChoiceType::class, [
  449.                 'choices'  => [
  450.                     '30A' => '30A',
  451.                     '40A' => '40A',
  452.                     '50A' => '50A',
  453.                     '50A以上' => '50A以上',
  454.                     '不明' => '不明',
  455.                 ],
  456.                 'expanded' => true,
  457.                 'multiple' => false,
  458.                 'required' => false,
  459.             ])
  460.             // コンセントアース端子
  461.             ->add('outlet_earth'ChoiceType::class, [
  462.                 'choices'  => [
  463.                     'あり' => 'あり',
  464.                     'なし' => 'なし',
  465.                     '不明' => '不明',
  466.                 ],
  467.                 'expanded' => true,
  468.                 'multiple' => false,
  469.                 'required' => false,
  470.             ])
  471.             // 配管穴の有無
  472.             ->add('room_size_07'ChoiceType::class, [
  473.                 'choices'  => [
  474.                     'あり' => 'あり',
  475.                     'なし' => 'なし',
  476.                     '不明' => '不明',
  477.                 ],
  478.                 'expanded' => true,
  479.                 'multiple' => false,
  480.                 'required' => false,
  481.             ])
  482.             // 配管穴の有無 → なし
  483.             ->add('room_size_07_02'ChoiceType::class, [
  484.                 'choices'  => [
  485.                     '建物が2009年6月以降に着工した証明書あり' => '建物が2009年6月以降に着工した証明書あり',
  486.                     '建物が2009年6月以降に着工した証明書なし' => '建物が2009年6月以降に着工した証明書なし',
  487.                 ],
  488.                 'expanded' => true,
  489.                 'multiple' => false,
  490.                 'required' => false,
  491.             ])
  492.             // 配管穴の有無 → なし → 建物が2009年6月以降に着工した証明書あり
  493.             ->add('room_size_07_03_v1'ChoiceType::class, [
  494.                 'choices'  => [
  495.                     '木造' => '木造',
  496.                     'コンクリート' => 'コンクリート',
  497.                     '鉄骨系(ALC)' => '鉄骨系(ALC)',
  498.                     'その他' => 'その他',
  499.                     '不明' => '不明',
  500.                 ],
  501.                 'expanded' => true,
  502.                 'multiple' => false,
  503.                 'required' => false,
  504.                 'choice_attr' => function($choice$key$value) {
  505.                     if ($choice === '木造') {
  506.                         return ['price' => 7980];
  507.                     } elseif ($choice === 'コンクリート') {
  508.                         return ['price' => 39980];
  509.                     } elseif ($choice === '鉄骨系(ALC)') {
  510.                         return ['price' => 7980];
  511.                     }
  512.                     return [];
  513.                 },
  514.             ])
  515.             // 配管穴の有無 → なし → 建物が2009年6月以降に着工した証明書なし
  516.             ->add('room_size_07_03_v2'ChoiceType::class, [
  517.                 'choices'  => [
  518.                     '木造' => '木造',
  519.                     'コンクリート' => 'コンクリート',
  520.                     '鉄骨系(ALC)' => '鉄骨系(ALC)',
  521.                     'その他' => 'その他',
  522.                     '不明' => '不明',
  523.                 ],
  524.                 'expanded' => true,
  525.                 'multiple' => false,
  526.                 'required' => false,
  527.                 'choice_attr' => function($choice$key$value) {
  528.                     if ($choice === '木造') {
  529.                         return ['price' => 34980];
  530.                     } elseif ($choice === 'コンクリート') {
  531.                         return ['price' => 74980];
  532.                     } elseif ($choice === '鉄骨系(ALC)') {
  533.                         return ['price' => 34980];
  534.                     }
  535.                     return [];
  536.                 },
  537.             ])
  538.             //設置予定場所の配管の状態
  539.             ->add('piping_status_07'ChoiceType::class, [
  540.                 'choices'  => [
  541.                     '通常配管' => '通常配管',
  542.                     '隠蔽配管' => '隠蔽配管',
  543.                     '不明' => '不明',
  544.                 ],
  545.                 'expanded' => true,
  546.                 'multiple' => false,
  547.                 'required' => false,
  548.             ])
  549.             // 設置予定場所の配管の状態 → 隠蔽配管
  550.             ->add('piping_status_07_02'ChoiceType::class, [
  551.                 'choices'  => [
  552.                     '新設' => '新設',
  553.                     '交換(再使用接続・洗浄費含む)' => '交換(再使用接続・洗浄費含む)',
  554.                 ],
  555.                 'expanded' => true,
  556.                 'multiple' => false,
  557.                 'required' => false,
  558.                 'choice_attr' =>  function($choice$key$value) {
  559.                     if ($choice === '新設') {
  560.                         return ['price' => 9800];
  561.                     } elseif ($choice === '交換(再使用接続・洗浄費含む)') {
  562.                         return ['price' => 49800];
  563.                     }
  564.                     return [];
  565.                 },
  566.             ])
  567.             //室内化粧カバー
  568.             ->add('indoor_cover_07'ChoiceType::class, [
  569.                 'choices'  => [
  570.                     '必要(2m以内)' => '必要(2m以内)',
  571.                     '不要' => '不要',
  572.                     '未定' => '未定',
  573.                 ],
  574.                 'expanded' => true,
  575.                 'multiple' => false,
  576.                 'required' => false,
  577.                 'choice_attr' =>  function($choice$key$value) {
  578.                     if ($choice === '必要(2m以内)') {
  579.                         return ['price' => 9980];
  580.                     }
  581.                     return [];
  582.                 },
  583.             ])
  584.             // 室外化粧カバー
  585.             ->add('outdoor_cover'ChoiceType::class, [
  586.                 'choices'  => [
  587.                     '必要' => '必要',
  588.                     '不要' => '不要',
  589.                     'その他' => 'その他',
  590.                 ],
  591.                 'expanded' => true,
  592.                 'multiple' => false,
  593.                 'required' => false,
  594.             ])
  595.             // 室外化粧カバー
  596.             ->add('outdoor_cover_02'ChoiceType::class, [
  597.                 'choices'  => [
  598.                     '新規同階' => '新規同階',
  599.                     '新規異階' => '新規異階',
  600.                     '再使用(交換)同階' => '再使用(交換)同階',
  601.                     '再使用(交換)異階' => '再使用(交換)異階',
  602.                 ],
  603.                 'expanded' => true,
  604.                 'multiple' => false,
  605.                 'required' => false,
  606.                 'choice_attr' =>  function($choice$key$value) {
  607.                     if ($choice === '新規同階') {
  608.                         return ['price' => 9980];
  609.                     } elseif ($choice === '新規異階') {
  610.                         return ['price' => 44960];
  611.                     } elseif ($choice === '再使用(交換)同階') {
  612.                         return ['price' => 3380];
  613.                     } elseif ($choice === '再使用(交換)異階') {
  614.                         return ['price' => 19880];
  615.                     }
  616.                     return [];
  617.                 },
  618.             ])
  619.             // 室外機の設置場所
  620.             ->add('construction_outdoor_07'ChoiceType::class, [
  621.                 'choices'  => [
  622.                     '室内機と同階' => '室内機と同階',
  623.                     '1階差(室内機2階、室外機1階)' => '1階差(室内機2階、室外機1階)',
  624.                     '2階差(室内機3階、室外機1階)' => '2階差(室内機3階、室外機1階)',
  625.                     'その他' => 'その他',
  626.                 ],
  627.                 'expanded' => true,
  628.                 'multiple' => false,
  629.                 'required' => false,
  630.                 'choice_attr' =>  function($choice$key$value) {
  631.                     if ($choice === '1階差(室内機2階、室外機1階)') {
  632.                         return ['price' => 33880];
  633.                     } elseif ($choice === '2階差(室内機3階、室外機1階)') {
  634.                         return ['price' => 66880];
  635.                     }
  636.                     return [];
  637.                 },
  638.             ])
  639.             //設置方法
  640.             ->add('setting_install_method'ChoiceType::class, [
  641.                 'choices'  => [
  642.                     '新規取付' => '新規取付',
  643.                     '交換' => '交換',
  644.                 ],
  645.                 'expanded' => true,
  646.                 'multiple' => false,
  647.                 'required' => false,
  648.             ])
  649.             // 設置方法 → 新規取付
  650.             ->add('construction_method_07_v1'ChoiceType::class, [
  651.                 'choices'  => [
  652.                     '①床置き(基本料金に含まれます)' => '①床置き(基本料金に含まれます)',
  653.                     '②二段置き' => '②二段置き',
  654.                     '③壁掛け' => '③壁掛け',
  655.                     '④屋根置き(屋根に対して垂直)' => '④屋根置き(屋根に対して垂直)',
  656.                     '⑤屋根置き(屋根に対して水平)' => '⑤屋根置き(屋根に対して水平)',
  657.                     '⑥公団吊り(天井吊り)' => '⑥公団吊り(天井吊り)',
  658.                     '⑦サービスバルコニー' => '⑦サービスバルコニー',
  659.                     '⑧不明(記載)' => '⑧不明(記載)',
  660.                 ],
  661.                 'expanded' => true,
  662.                 'multiple' => false,
  663.                 'required' => false,
  664.                 'choice_attr' =>  function($choice$key$value) {
  665.                     if ($choice === '②二段置き') {
  666.                         return ['price' => 29800];
  667.                     } elseif ($choice === '③壁掛け') {
  668.                         return ['price' => 17800];
  669.                     } elseif ($choice === '④屋根置き(屋根に対して垂直)') {
  670.                         return ['price' => 21980];
  671.                     } elseif ($choice === '⑤屋根置き(屋根に対して水平)') {
  672.                         return ['price' => 21980];
  673.                     } elseif ($choice === '⑥公団吊り(天井吊り)') {
  674.                         return ['price' => 28800];
  675.                     } elseif ($choice === '⑦サービスバルコニー') {
  676.                         return ['price' => 7980];
  677.                     }
  678.                     return [];
  679.                 },
  680.             ])
  681.             // 設置方法 → 交換
  682.             ->add('construction_method_07_v2'ChoiceType::class, [
  683.                 'choices'  => [
  684.                     '①床置き(基本料金に含まれます)' => '①床置き(基本料金に含まれます)',
  685.                     '②二段置き' => '②二段置き',
  686.                     '③壁掛け' => '③壁掛け',
  687.                     '④屋根置き(屋根に対して垂直)' => '④屋根置き(屋根に対して垂直)',
  688.                     '⑤屋根置き(屋根に対して水平)' => '⑤屋根置き(屋根に対して水平)',
  689.                     '⑥公団吊り(天井吊り)' => '⑥公団吊り(天井吊り)',
  690.                     '⑦サービスバルコニー' => '⑦サービスバルコニー',
  691.                     '⑧不明(記載)' => '⑧不明(記載)',
  692.                 ],
  693.                 'expanded' => true,
  694.                 'multiple' => false,
  695.                 'required' => false,
  696.                 'choice_attr' =>  function($choice$key$value) {
  697.                     if ($choice === '②二段置き') {
  698.                         return ['price' => 7280];
  699.                     } elseif ($choice === '③壁掛け') {
  700.                         return ['price' => 21800];
  701.                     } elseif ($choice === '④屋根置き(屋根に対して垂直)') {
  702.                         return ['price' => 21980];
  703.                     } elseif ($choice === '⑤屋根置き(屋根に対して水平)') {
  704.                         return ['price' => 21980];
  705.                     } elseif ($choice === '⑥公団吊り(天井吊り)') {
  706.                         return ['price' => 21800];
  707.                     } elseif ($choice === '⑦サービスバルコニー') {
  708.                         return ['price' => 7980];
  709.                     }
  710.                     return [];
  711.                 },
  712.             ])
  713.             ->add('image_1'FileType::class, [
  714.                 'multiple' => false,
  715.                 'required' => false,
  716.                 'mapped' => false,
  717.             ])
  718.             ->add('image_2'FileType::class, [
  719.                 'multiple' => false,
  720.                 'required' => false,
  721.                 'mapped' => false,
  722.             ])
  723.             ->add('image_3'FileType::class, [
  724.                 'multiple' => false,
  725.                 'required' => false,
  726.                 'mapped' => false,
  727.             ])
  728.             ->add('image_4'FileType::class, [
  729.                 'multiple' => false,
  730.                 'required' => false,
  731.                 'mapped' => false,
  732.             ])
  733.             ->add('image_5'FileType::class, [
  734.                 'multiple' => false,
  735.                 'required' => false,
  736.                 'mapped' => false,
  737.             ])
  738.             ->add('image_reason'FileType::class, [
  739.                 'multiple' => false,
  740.                 'required' => false,
  741.                 'mapped' => false,
  742.             ])
  743.             ->add('filename_image_1'HiddenType::class)
  744.             ->add('filename_image_2'HiddenType::class)
  745.             ->add('filename_image_3'HiddenType::class)
  746.             ->add('filename_image_4'HiddenType::class)
  747.             ->add('filename_image_5'HiddenType::class)
  748.             ->add('location'TextType::class, [
  749.                 'required' => false,
  750.             ])
  751.             ->add('floor'FileType::class, [
  752.                 'multiple' => false,
  753.                 'required' => false,
  754.                 'mapped' => false,
  755.             ])
  756.             ->add('filename_floor'HiddenType::class)
  757.         ;
  758.         // 工事するエアコン
  759.         $Product $this->productRepository->find(1289);
  760.         $constructionItems = array();
  761.         $constructionTatamis = array();
  762.         $Carts $this->cartService->getCarts();
  763.         foreach ($Carts as $Cart) {
  764.             foreach ($Cart->getCartItems() as $CartItem) {
  765.                 if ($CartItem->getProductClass()->getProduct()->getId() == $Product->getId()) {
  766.                 }
  767.                 else {
  768.                     foreach ($CartItem->getProductClass()->getProduct()->getProductCategories() as $ProductCategories) {
  769.                         $categoryName $ProductCategories->getCategory()->getName();
  770.                         $categoryId $ProductCategories->getCategory()->getId();
  771.                         
  772.                         //おすすめと自社ローンは標準工事費込み為
  773.                         if ($categoryId == 118 || $categoryId == 34) {
  774.                             $productId $CartItem->getProductClass()->getProduct()->getId();
  775.                             $productLoan 1;
  776.                             $constructionTatamis[$productId]['data-loan'] = $productLoan;
  777.                         }
  778.                         if (mb_strpos($categoryName"畳") !== false) {
  779.                             $productId $CartItem->getProductClass()->getProduct()->getId();
  780.                             $productName $CartItem->getProductClass()->getProduct()->getName();
  781.                             $quantity $CartItem->getQuantity();
  782.                             $constructionItems[$productId] = $productName {$categoryName}{$quantity}台)";
  783.                             $constructionTatamis[$productId]['data-tatami'] = str_replace("畳"""$categoryName);
  784.                             $constructionTatamis[$productId]['data-quantity'] = $quantity;
  785.                         }
  786.                     }
  787.                 }
  788.             }
  789.         }
  790.         $builder->add('construction_airs'ChoiceType::class, [
  791.             'choices'  => $constructionItems,
  792.             'expanded' => true,
  793.             'multiple' => true,
  794.             'required' => false,
  795.             'choice_attr' =>  function($choice$key$value) use ($constructionTatamis){   
  796.                 return empty($constructionTatamis[$key]) ? [] : $constructionTatamis[$key];
  797.             },
  798.         ]);
  799.         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  800.             /** @var CartItem $CartItem */
  801.             $CartItem $event->getData();
  802.             $ProductClass $CartItem->getProductClass();
  803.             // 工事費用の商品は単価をカートから引用
  804.             if ($ProductClass && !empty($_POST['construction_total_price'])) {
  805.                 if ($ProductClass->getProduct()->getId() == 1289) {
  806.                     $CartItem->setPrice($_POST['construction_total_price']);
  807.                 }
  808.             }
  809.         });
  810.         /**
  811.          * SUBMIT前にファイルをアップロードしてfilenameにセットする
  812.          */
  813.         $builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
  814.             $data $event->getData();
  815.             // ファイルをアップロード
  816.             if (!empty($data['image_1'])) {
  817.                 $filename $this->fileUploader->upload($data['image_1'], 'construction');
  818.                 $data['filename_image_1'] = $filename;
  819.                 unset($data['image_1']);
  820.             }
  821.             if (!empty($data['image_2'])) {
  822.                 $filename $this->fileUploader->upload($data['image_2'], 'construction');
  823.                 $data['filename_image_2'] = $filename;
  824.                 unset($data['image_2']);
  825.             }
  826.             if (!empty($data['image_3'])) {
  827.                 $filename $this->fileUploader->upload($data['image_3'], 'construction');
  828.                 $data['filename_image_3'] = $filename;
  829.                 unset($data['image_3']);
  830.             }
  831.             if (!empty($data['image_4'])) {
  832.                 $filename $this->fileUploader->upload($data['image_4'], 'construction');
  833.                 $data['filename_image_4'] = $filename;
  834.                 unset($data['image_4']);
  835.             }
  836.             if (!empty($data['image_5'])) {
  837.                 $filename $this->fileUploader->upload($data['image_5'], 'construction');
  838.                 $data['filename_image_5'] = $filename;
  839.                 unset($data['image_5']);
  840.             }
  841.             if (!empty($data['floor'])) {
  842.                 $filename $this->fileUploader->upload($data['floor'], 'construction');
  843.                 $data['filename_floor'] = $filename;
  844.                 unset($data['floor']);
  845.             }
  846.             // アップロードしたデータを保存
  847.             $event->setData($data);
  848.         });
  849.     }
  850.     /**
  851.      * {@inheritdoc}
  852.      */
  853.     public function getExtendedType()
  854.     {
  855.         return AddCartType::class;
  856.     }
  857.     /**
  858.      * {@inheritdoc}
  859.      */
  860.     public static function getExtendedTypes(): iterable
  861.     {
  862.         yield AddCartType::class;
  863.     }
  864. }