Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

注文画面 配送方法を選択した際の不具合修正 #6142

Draft
wants to merge 3 commits into
base: 4.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 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,19 @@ 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);
if ( !is_null($Payment)) {
$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)

Check warning on line 37 in src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php

View check run for this annotation

Codecov / codecov/patch

src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php#L37

Added line #L37 was not covered by tests
{
$this->requestStack = $requestStack;

Check warning on line 39 in src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php

View check run for this annotation

Codecov / codecov/patch

src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php#L39

Added line #L39 was not covered by tests
}

/**
* @param ItemHolderInterface $itemHolder
* @param PurchaseContext $context
*/
public function validate(ItemHolderInterface $itemHolder, PurchaseContext $context)

Check warning on line 46 in src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php

View check run for this annotation

Codecov / codecov/patch

src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php#L46

Added line #L46 was not covered by tests
{
/* @var Order $Order */
$Order = $itemHolder;
$request = $this->requestStack->getCurrentRequest();
$requestData = $request->request->all();

Check warning on line 51 in src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php

View check run for this annotation

Codecov / codecov/patch

src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php#L49-L51

Added lines #L49 - L51 were not covered by tests

// 配送方法の変更によって選択していた支払方法が使用できなくなった場合、OrderTypeで支払方法が変更されている
if (isset($requestData['_shopping_order']['Payment'])) {

Check warning on line 54 in src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php

View check run for this annotation

Codecov / codecov/patch

src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php#L54

Added line #L54 was not covered by tests

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);

Check warning on line 58 in src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php

View check run for this annotation

Codecov / codecov/patch

src/Eccube/Service/PurchaseFlow/Processor/PaymentChangePostValidator.php#L56-L58

Added lines #L56 - L58 were not covered by tests
}
}
}
}
}
6 changes: 4 additions & 2 deletions tests/Eccube/Tests/Web/ShoppingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Loading