Skip to content

Commit

Permalink
Merge pull request #5951 from dotani1111/features/feat_serch_product_…
Browse files Browse the repository at this point in the history
…date

feat:管理画面>商品一覧画面の「登録日」「更新日」検索へのバリデーション
  • Loading branch information
dotani1111 authored Feb 7, 2024
2 parents dbf0f4e + 65c20db commit cc2ee13
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/Eccube/Form/Type/Admin/SearchCustomerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
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 SearchCustomerType extends AbstractType
Expand Down Expand Up @@ -401,6 +404,39 @@ 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();

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

# 更新日
$update_datetime_start = $form['update_datetime_start']->getData();
$update_datetime_end = $form['update_datetime_end']->getData();

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

# 最終購入日
$last_buy_start = $form['last_buy_start']->getData();
$last_buy_end = $form['last_buy_end']->getData();

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

Expand Down
49 changes: 48 additions & 1 deletion src/Eccube/Form/Type/Admin/SearchOrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

Expand Down Expand Up @@ -417,7 +420,51 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('sorttype', HiddenType::class, [
'label' => 'admin.list.sort.type',
'required' => false,
]);
])
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();

# 注文日
$order_datetime_start = $form['order_datetime_start']->getData();
$order_datetime_end = $form['order_datetime_end']->getData();

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

# 入金日
$payment_datetime_start = $form['payment_datetime_start']->getData();
$payment_datetime_end = $form['payment_datetime_end']->getData();

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

# 更新日
$update_datetime_start = $form['update_datetime_start']->getData();
$update_datetime_end = $form['update_datetime_end']->getData();

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

# お届け日
$shipping_delivery_datetime_start = $form['shipping_delivery_datetime_start']->getData();
$shipping_delivery_datetime_end = $form['shipping_delivery_datetime_end']->getData();

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

/**
Expand Down
26 changes: 26 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 @@ -269,6 +272,29 @@ 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();

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

# 更新日
$update_datetime_start = $form['update_datetime_start']->getData();
$update_datetime_end = $form['update_datetime_end']->getData();

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

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 @@ -416,6 +416,7 @@ admin.common.create_complete: Created
admin.common.system_error: System error occurred
admin.common.to_show_complete: '%name% is displayed'
admin.common.to_hide_complete: '%name% is hidden'
admin.common.date_range_error: End date is set after start date

# action labels
admin.common.save: Save
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 @@ -416,6 +416,7 @@ admin.common.create_complete: 作成しました
admin.common.system_error: システムエラーが発生しました
admin.common.to_show_complete: '「%name%」を表示にしました。'
admin.common.to_hide_complete: '「%name%」を非表示にしました。'
admin.common.date_range_error: 終了日時は、開始日時より大きく設定してください

# action系のラベル
admin.common.save: 保存
Expand Down

0 comments on commit cc2ee13

Please sign in to comment.