Skip to content

Commit

Permalink
注文画面 配送方法を選択した際の不具合修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuishi authored and dk-umebius committed Jan 19, 2025
1 parent 2014e89 commit d7cad72
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Eccube/Form/Type/Shopping/OrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
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 @@ -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
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\Service\PurchaseFlow\Processor;

use Eccube\Entity\ItemHolderInterface;
use Eccube\Entity\Order;
use Eccube\Service\PurchaseFlow\ItemHolderPostValidator;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* 配送方法変更により支払方法が変更されたかどうかを検知するバリデータ.
*/
class PaymentChangePostValidator extends ItemHolderPostValidator
{
/**
* @var RequestStack
*/
protected $requestStack;

/**
* PaymentChangePostValidator constructor.
*
* @param RequestStack $requestStack
*/
public function __construct(RequestStack $requestStack)
{
$this->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);
}
}
}
}
}

0 comments on commit d7cad72

Please sign in to comment.