From d7cad72668333ae2951b09a135006276a6d777ef Mon Sep 17 00:00:00 2001 From: tatsuishi Date: Mon, 15 Apr 2024 16:10:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B3=A8=E6=96=87=E7=94=BB=E9=9D=A2=20?= =?UTF-8?q?=E9=85=8D=E9=80=81=E6=96=B9=E6=B3=95=E3=82=92=E9=81=B8=E6=8A=9E?= =?UTF-8?q?=E3=81=97=E3=81=9F=E9=9A=9B=E3=81=AE=E4=B8=8D=E5=85=B7=E5=90=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Form/Type/Shopping/OrderType.php | 11 ++++ src/Eccube/Resource/locale/messages.en.yaml | 1 + src/Eccube/Resource/locale/messages.ja.yaml | 1 + .../Processor/PaymentChangePostValidator.php | 63 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php diff --git a/src/Eccube/Form/Type/Shopping/OrderType.php b/src/Eccube/Form/Type/Shopping/OrderType.php index 7409d9bd2b9..44ac893866a 100644 --- a/src/Eccube/Form/Type/Shopping/OrderType.php +++ b/src/Eccube/Form/Type/Shopping/OrderType.php @@ -165,6 +165,17 @@ public function buildForm(FormBuilderInterface $builder, array $options) $charge = $Order->getPayment() ? $Order->getPayment()->getCharge() : 0; $Payments = $this->filterPayments($Payments, $Order->getPaymentTotal() - $charge); + // フォームから送信された支払方法が選択肢に存在するかどうか + // 選択肢に存在しなければ、選択肢の中で最初の支払方法を選択状態にする + $Payment = null; + if ($data['Payment']) { + $Payment = $this->paymentRepository->find($data['Payment']); + } + $Payment = !is_null($Payment) && in_array($Payment, $Payments, true) ? + $Payment : (current($Payments) ?: null); + $data['Payment'] = (string)$Payment->getId(); + $event->setData($data); + $form = $event->getForm(); $this->addPaymentForm($form, $Payments); }); diff --git a/src/Eccube/Resource/locale/messages.en.yaml b/src/Eccube/Resource/locale/messages.en.yaml index 01fa5bca2ce..07cf6118480 100644 --- a/src/Eccube/Resource/locale/messages.en.yaml +++ b/src/Eccube/Resource/locale/messages.en.yaml @@ -1861,6 +1861,7 @@ purchase_flow.tax_rate_update: Tax Rate has been updated. Please confirm the tot purchase_flow.over_customer_point: You are not able to use points more than your current points. purchase_flow.over_payment_total: The points are more than the total amount. purchase_flow.over_stock: "%name% does not have enough stock." +purchase_flow.payment_method_changed: "Payment method has been changed to %name% due to change in delivery method." #------------------------------------------------------------------------------------ # Command diff --git a/src/Eccube/Resource/locale/messages.ja.yaml b/src/Eccube/Resource/locale/messages.ja.yaml index 9cf4b99c635..3c28e98838f 100644 --- a/src/Eccube/Resource/locale/messages.ja.yaml +++ b/src/Eccube/Resource/locale/messages.ja.yaml @@ -1862,6 +1862,7 @@ purchase_flow.tax_rate_update: 税率が更新されました。金額をご確 purchase_flow.over_customer_point: 利用ポイントが所有ポイントを上回っています。 purchase_flow.over_payment_total: 利用ポイントがお支払い金額を上回っています。 purchase_flow.over_stock: "「%name%」の在庫が足りません。" +purchase_flow.payment_method_changed: "配送方法の変更により支払方法が「%name%」に変更されました。" #------------------------------------------------------------------------------------ # Command diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php new file mode 100644 index 00000000000..d97a197ef85 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php @@ -0,0 +1,63 @@ +requestStack = $requestStack; + } + + /** + * @param ItemHolderInterface $itemHolder + * @param PurchaseContext $context + */ + public function validate(ItemHolderInterface $itemHolder, PurchaseContext $context) + { + /* @var Order $Order */ + $Order = $itemHolder; + $request = $this->requestStack->getCurrentRequest(); + $requestData = $request->request->all(); + + // 配送方法の変更によって選択していた支払方法が使用できなくなった場合、OrderTypeで支払方法が変更されている + if (isset($requestData['_shopping_order']['Payment'])) { + + if (!is_null($Order->getPayment()) && $Order->getPayment()->getId() != $requestData['_shopping_order']['Payment']) { + if ($Order->getPayment()) { + $this->throwInvalidItemException(trans('purchase_flow.payment_method_changed', ['%name%' => $Order->getPayment()->getMethod()]), null, true); + } + } + } + } +} From c15761616813be9321acf504e5bdac25eb67799c Mon Sep 17 00:00:00 2001 From: tatsuishi Date: Mon, 15 Apr 2024 16:54:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B3=A8=E6=96=87=E7=94=BB=E9=9D=A2=20?= =?UTF-8?q?=E9=85=8D=E9=80=81=E6=96=B9=E6=B3=95=E3=82=92=E9=81=B8=E6=8A=9E?= =?UTF-8?q?=E3=81=97=E3=81=9F=E9=9A=9B=E3=81=AE=E4=B8=8D=E5=85=B7=E5=90=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Form/Type/Shopping/OrderType.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Eccube/Form/Type/Shopping/OrderType.php b/src/Eccube/Form/Type/Shopping/OrderType.php index 44ac893866a..51944be4451 100644 --- a/src/Eccube/Form/Type/Shopping/OrderType.php +++ b/src/Eccube/Form/Type/Shopping/OrderType.php @@ -173,8 +173,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) } $Payment = !is_null($Payment) && in_array($Payment, $Payments, true) ? $Payment : (current($Payments) ?: null); - $data['Payment'] = (string)$Payment->getId(); - $event->setData($data); + if ( !is_null($Payment)) { + $data['Payment'] = (string)$Payment->getId(); + $event->setData($data); + } $form = $event->getForm(); $this->addPaymentForm($form, $Payments); From 83db04c4ce9cc902f346c9e0531f6724fb1c685d Mon Sep 17 00:00:00 2001 From: Dakeyama Date: Sun, 19 Jan 2025 22:07:36 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E6=94=AF=E6=89=95=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=81=B8=E6=8A=9E=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0=E3=81=A7?= =?UTF-8?q?ID:1=E3=81=8C=E9=81=B8=E6=8A=9E=E3=81=95=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=81=8B=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Eccube/Tests/Web/ShoppingControllerTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Eccube/Tests/Web/ShoppingControllerTest.php b/tests/Eccube/Tests/Web/ShoppingControllerTest.php index c229becbfd3..82ca4b378e4 100644 --- a/tests/Eccube/Tests/Web/ShoppingControllerTest.php +++ b/tests/Eccube/Tests/Web/ShoppingControllerTest.php @@ -396,8 +396,10 @@ public function testPaymentWithError() ]); $this->assertTrue($this->client->getResponse()->isSuccessful()); - $this->expected = 'お支払い方法を選択してください。'; - $this->actual = $crawler->filter('p.ec-errorMessage')->text(); + + // 先頭の支払方法(郵便振替)が選択されていることを確認 + $this->expected = '1'; + $this->actual = $crawler->filter('input[name="_shopping_order[Payment]"]:checked')->attr('value'); $this->verify(); }