From f38f876b2ba76559b186f223fdc710885210cf32 Mon Sep 17 00:00:00 2001 From: Takuya Sawada Date: Tue, 11 Aug 2020 10:23:07 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E5=80=A4=E3=81=AB=E5=9F=BA?= =?UTF-8?q?=E3=81=A5=E3=81=84=E3=81=A6=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=81=AE=E3=82=AB=E3=83=8A=E3=82=92=E5=BF=85=E9=A0=88=E9=A0=85?= =?UTF-8?q?=E7=9B=AE=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E6=B1=BA=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NonMemberShoppingController.php | 36 +++++++++++-------- src/Eccube/Form/Type/Admin/CustomerType.php | 4 +-- src/Eccube/Form/Type/Admin/OrderType.php | 9 +---- src/Eccube/Form/Type/Admin/ShippingType.php | 18 ++-------- src/Eccube/Form/Type/Front/ContactType.php | 4 +-- .../Form/Type/Front/CustomerAddressType.php | 4 +-- src/Eccube/Form/Type/Front/EntryType.php | 2 +- src/Eccube/Form/Type/Front/NonMemberType.php | 5 ++- src/Eccube/Form/Type/KanaType.php | 14 ++++++-- .../template/admin/Customer/edit.twig | 2 ++ .../Resource/template/admin/Order/edit.twig | 14 ++++++-- .../template/admin/Order/shipping.twig | 4 ++- .../template/default/Shopping/index.twig | 2 +- 13 files changed, 60 insertions(+), 58 deletions(-) diff --git a/src/Eccube/Controller/NonMemberShoppingController.php b/src/Eccube/Controller/NonMemberShoppingController.php index 5daf7b093f3..cf3321dcf6c 100644 --- a/src/Eccube/Controller/NonMemberShoppingController.php +++ b/src/Eccube/Controller/NonMemberShoppingController.php @@ -13,7 +13,9 @@ namespace Eccube\Controller; +use Eccube\Entity\BaseInfo; use Eccube\Entity\Customer; +use Eccube\Repository\BaseInfoRepository; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Form\Type\Front\NonMemberType; @@ -49,21 +51,29 @@ class NonMemberShoppingController extends AbstractShoppingController */ protected $cartService; + /** + * @var BaseInfo + */ + protected $baseInfo; + /** * NonMemberShoppingController constructor. * * @param ValidatorInterface $validator + * @param BaseInfoRepository $baseInfoRepository * @param PrefRepository $prefRepository * @param OrderHelper $orderHelper * @param CartService $cartService */ public function __construct( ValidatorInterface $validator, + BaseInfoRepository $baseInfoRepository, PrefRepository $prefRepository, OrderHelper $orderHelper, CartService $cartService ) { $this->validator = $validator; + $this->baseInfo = $baseInfoRepository->get(); $this->prefRepository = $prefRepository; $this->orderHelper = $orderHelper; $this->cartService = $cartService; @@ -269,24 +279,20 @@ protected function customerValidation(array &$data) ] ); - $data['customer_kana01'] = mb_convert_kana($data['customer_kana01'], 'CV', 'utf-8'); - $errors[] = $this->validator->validate( - $data['customer_kana01'], - [ - new Assert\NotBlank(), + $kanaValidators = [ new Assert\Length(['max' => $this->eccubeConfig['eccube_kana_len']]), new Assert\Regex(['pattern' => '/^[ァ-ヶヲ-゚ー]+$/u']), - ] - ); - $data['customer_kana02'] = mb_convert_kana($data['customer_kana02'], 'CV', 'utf-8'); - $errors[] = $this->validator->validate( - $data['customer_kana02'], - [ - new Assert\NotBlank(), - new Assert\Length(['max' => $this->eccubeConfig['eccube_kana_len']]), - new Assert\Regex(['pattern' => '/^[ァ-ヶヲ-゚ー]+$/u']), - ]); + ]; + if ($this->baseInfo->isOptionRequireKana()) { + $kanaValidators []= new Assert\NotBlank(); + } + + $data['customer_kana01'] = mb_convert_kana($data['customer_kana01'], 'CV', 'utf-8'); + $errors[] = $this->validator->validate($data['customer_kana01'], $kanaValidators); + + $data['customer_kana02'] = mb_convert_kana($data['customer_kana02'], 'CV', 'utf-8'); + $errors[] = $this->validator->validate($data['customer_kana02'], $kanaValidators); $errors[] = $this->validator->validate( $data['customer_company_name'], [ diff --git a/src/Eccube/Form/Type/Admin/CustomerType.php b/src/Eccube/Form/Type/Admin/CustomerType.php index d53b7fe3cd9..fce04ebaecc 100644 --- a/src/Eccube/Form/Type/Admin/CustomerType.php +++ b/src/Eccube/Form/Type/Admin/CustomerType.php @@ -64,9 +64,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('name', NameType::class, [ 'required' => true, ]) - ->add('kana', KanaType::class, [ - 'required' => true, - ]) + ->add('kana', KanaType::class) ->add('company_name', TextType::class, [ 'required' => false, 'constraints' => [ diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index 6205343f9d2..53cab0e3641 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -99,14 +99,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ], ], ]) - ->add('kana', KanaType::class, [ - 'required' => false, - 'options' => [ - 'constraints' => [ - new Assert\NotBlank(), - ], - ], - ]) + ->add('kana', KanaType::class) ->add('company_name', TextType::class, [ 'required' => false, 'constraints' => [ diff --git a/src/Eccube/Form/Type/Admin/ShippingType.php b/src/Eccube/Form/Type/Admin/ShippingType.php index a1c54287976..77272a00f4b 100644 --- a/src/Eccube/Form/Type/Admin/ShippingType.php +++ b/src/Eccube/Form/Type/Admin/ShippingType.php @@ -90,22 +90,8 @@ public function __construct( public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name', NameType::class, [ - 'required' => false, - 'options' => [ - 'constraints' => [ - new Assert\NotBlank(), - ], - ], - ]) - ->add('kana', KanaType::class, [ - 'required' => false, - 'options' => [ - 'constraints' => [ - new Assert\NotBlank(), - ], - ], - ]) + ->add('name', NameType::class) + ->add('kana', KanaType::class) ->add('company_name', TextType::class, [ 'required' => false, 'constraints' => [ diff --git a/src/Eccube/Form/Type/Front/ContactType.php b/src/Eccube/Form/Type/Front/ContactType.php index 49bf97361a1..49ea22db080 100644 --- a/src/Eccube/Form/Type/Front/ContactType.php +++ b/src/Eccube/Form/Type/Front/ContactType.php @@ -52,9 +52,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('name', NameType::class, [ 'required' => true, ]) - ->add('kana', KanaType::class, [ - 'required' => false, - ]) + ->add('kana', KanaType::class) ->add('postal_code', PostalType::class, [ 'required' => false, ]) diff --git a/src/Eccube/Form/Type/Front/CustomerAddressType.php b/src/Eccube/Form/Type/Front/CustomerAddressType.php index e676b2139f5..a96f1313735 100644 --- a/src/Eccube/Form/Type/Front/CustomerAddressType.php +++ b/src/Eccube/Form/Type/Front/CustomerAddressType.php @@ -49,9 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('name', NameType::class, [ 'required' => true, ]) - ->add('kana', KanaType::class, [ - 'required' => true, - ]) + ->add('kana', KanaType::class) ->add('company_name', TextType::class, [ 'required' => false, 'constraints' => [ diff --git a/src/Eccube/Form/Type/Front/EntryType.php b/src/Eccube/Form/Type/Front/EntryType.php index 7982f497a20..473042fdcb7 100644 --- a/src/Eccube/Form/Type/Front/EntryType.php +++ b/src/Eccube/Form/Type/Front/EntryType.php @@ -61,7 +61,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('name', NameType::class, [ 'required' => true, ]) - ->add('kana', KanaType::class, []) + ->add('kana', KanaType::class) ->add('company_name', TextType::class, [ 'required' => false, 'constraints' => [ diff --git a/src/Eccube/Form/Type/Front/NonMemberType.php b/src/Eccube/Form/Type/Front/NonMemberType.php index f4ceb1d8133..8ebe65bc4c0 100644 --- a/src/Eccube/Form/Type/Front/NonMemberType.php +++ b/src/Eccube/Form/Type/Front/NonMemberType.php @@ -14,6 +14,7 @@ namespace Eccube\Form\Type\Front; use Eccube\Common\EccubeConfig; +use Eccube\Repository\BaseInfoRepository; use Eccube\Form\Type\AddressType; use Eccube\Form\Type\KanaType; use Eccube\Form\Type\NameType; @@ -51,9 +52,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('name', NameType::class, [ 'required' => true, ]) - ->add('kana', KanaType::class, [ - 'required' => true, - ]) + ->add('kana', KanaType::class) ->add('company_name', TextType::class, [ 'required' => false, 'constraints' => [ diff --git a/src/Eccube/Form/Type/KanaType.php b/src/Eccube/Form/Type/KanaType.php index 9a5666886dd..63c69a3759e 100644 --- a/src/Eccube/Form/Type/KanaType.php +++ b/src/Eccube/Form/Type/KanaType.php @@ -14,6 +14,8 @@ namespace Eccube\Form\Type; use Eccube\Common\EccubeConfig; +use Eccube\Entity\BaseInfo; +use Eccube\Repository\BaseInfoRepository; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -22,18 +24,25 @@ class KanaType extends AbstractType { /** - * @var \Eccube\Common\EccubeConfig + * @var EccubeConfig */ protected $eccubeConfig; + /** + * @var BaseInfo + */ + protected $baseInfo; + /** * KanaType constructor. * * @param EccubeConfig $eccubeConfig + * @param BaseInfoRepository $baseInfoRepository */ - public function __construct(EccubeConfig $eccubeConfig) + public function __construct(EccubeConfig $eccubeConfig, BaseInfoRepository $baseInfoRepository) { $this->eccubeConfig = $eccubeConfig; + $this->baseInfo = $baseInfoRepository->get(); } /** @@ -52,6 +61,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ + 'required' => $this->baseInfo->isOptionRequireKana(), 'lastname_options' => [ 'attr' => [ 'placeholder' => 'common.last_name_kana', diff --git a/src/Eccube/Resource/template/admin/Customer/edit.twig b/src/Eccube/Resource/template/admin/Customer/edit.twig index d5cda78bad3..384b794cc3f 100644 --- a/src/Eccube/Resource/template/admin/Customer/edit.twig +++ b/src/Eccube/Resource/template/admin/Customer/edit.twig @@ -87,7 +87,9 @@ file that was distributed with this source code.
{{ 'admin.common.kana'|trans }} + {% if BaseInfo.option_require_kana %} {{ 'admin.common.required'|trans }} + {% endif %}
diff --git a/src/Eccube/Resource/template/admin/Order/edit.twig b/src/Eccube/Resource/template/admin/Order/edit.twig index e65e7067ce2..54377873ec9 100644 --- a/src/Eccube/Resource/template/admin/Order/edit.twig +++ b/src/Eccube/Resource/template/admin/Order/edit.twig @@ -409,7 +409,12 @@ file that was distributed with this source code.
- +
@@ -552,7 +557,12 @@ file that was distributed with this source code.
- +
diff --git a/src/Eccube/Resource/template/admin/Order/shipping.twig b/src/Eccube/Resource/template/admin/Order/shipping.twig index 318d2631e9d..cfde6cd2cd3 100644 --- a/src/Eccube/Resource/template/admin/Order/shipping.twig +++ b/src/Eccube/Resource/template/admin/Order/shipping.twig @@ -335,10 +335,12 @@ file that was distributed with this source code.
diff --git a/src/Eccube/Resource/template/default/Shopping/index.twig b/src/Eccube/Resource/template/default/Shopping/index.twig index fcc1b4d9160..35ec833adcc 100644 --- a/src/Eccube/Resource/template/default/Shopping/index.twig +++ b/src/Eccube/Resource/template/default/Shopping/index.twig @@ -187,7 +187,7 @@ file that was distributed with this source code.
- {{ 'common.required'|trans }} + {{ BaseInfo.option_require_kana ? 'common.required'|trans }}