Skip to content

Commit

Permalink
feat:管理画面>商品一覧画面の「登録日」「更新日」検索へのバリデーション
Browse files Browse the repository at this point in the history
  • Loading branch information
dotani1111 committed Mar 3, 2023
1 parent 7ca2c2c commit c36f469
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Eccube/Form/Type/Admin/SearchProductType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Validator\Constraints as Assert;

class SearchProductType extends AbstractType
Expand Down Expand Up @@ -265,6 +268,28 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => 'admin.list.sort.type',
'required' => false,
])
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
$create_datetime_start = $form['create_datetime_start']->getData();
$create_datetime_end = $form['create_datetime_end']->getData();

$update_datetime_start = $form['update_datetime_start']->getData();
$update_datetime_end = $form['update_datetime_end']->getData();

if (!empty($create_datetime_start) && !empty($create_datetime_end)) {
if ($create_datetime_start > $create_datetime_end) {
$form['create_datetime_start']->addError(new FormError(trans('admin.product.date_range_error')));
$form['create_datetime_end']->addError(new FormError(''));
}
}

if (!empty($update_datetime_start) && !empty($update_datetime_end)) {
if ($update_datetime_start > $update_datetime_end) {
$form['update_datetime_start']->addError(new FormError(trans('admin.product.date_range_error')));
$form['update_datetime_end']->addError(new FormError(''));
}
}
})
;
}

Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ admin.product.delete_flag: Product Deletion Flag
admin.product.search_category: Category Search
admin.product.save_tag: Tags
admin.product.create_date__card_title: Update
admin.product.date_range_error: End date is set after start date
admin.product.move_to_category: Add / Edit a Category
admin.product.move_to_tag: Add / Edit a Tag
admin.product.move_to_product_class: Edit an Option
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ admin.product.delete_flag: 商品削除フラグ
admin.product.search_category: カテゴリ検索
admin.product.save_tag: タグ登録
admin.product.create_date__card_title: 登録日・更新日
admin.product.date_range_error: 終了日時は、開始日時より大きく設定してください
admin.product.move_to_category: カテゴリの追加・編集
admin.product.move_to_tag: タグの追加・編集
admin.product.move_to_product_class: 商品規格の編集
Expand Down

0 comments on commit c36f469

Please sign in to comment.