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

注文時に支払い方法が非表示に変更された場合エラーが発生するよう修正 #5558

Merged
merged 4 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions app/config/eccube/packages/purchaseflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ services:
arguments:
- #
- '@Eccube\Service\PurchaseFlow\Processor\AddPointProcessor' # 加算ポイントの計算
- '@Eccube\Service\PurchaseFlow\Processor\PaymentValidator'
- '@Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator'
- '@Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator'
- '@Eccube\Service\PurchaseFlow\Processor\PaymentChargeChangeValidator' # 手数料の変更検知
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 @@ -387,6 +387,7 @@ front.shopping.price_changed: 'The selling price of %product% has been changed.'
front.shopping.payment_total_invalid: The total amount is invalid.
front.shopping.different_payment_methods: Sorry, your order includes items with different purchase methods, which are unable to be processed in one order.
front.shopping.payment_method_unselected: Please select the payment method.
front.shopping.not_available_payment_method: The payment method you have selected is not available.
front.shopping.payment_method_not_fount: Sorry, you have no payment options. If you have selected multiple delivery methods, you can only select the same payment option for them all.
front.under_maintenance: The site is currently under maintenance.

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 @@ -387,6 +387,7 @@ front.shopping.price_changed: '「%product%」の販売価格が変更されま
front.shopping.payment_total_invalid: 合計金額が不正です。
front.shopping.different_payment_methods: 支払い方法が異なる商品が含まれているため、同時に購入することはできません。
front.shopping.payment_method_unselected: お支払い方法を選択してください。
front.shopping.not_available_payment_method: 選択したお支払い方法はご利用できません。
front.shopping.payment_method_not_fount: 選択できるお支払い方法がありません。配送方法が異なる場合は同じ配送方法を選んでください。
front.under_maintenance: メンテナンスモードが有効になっています。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Eccube\Entity\Delivery;
use Eccube\Entity\ItemHolderInterface;
use Eccube\Entity\Master\SaleType;
use Eccube\Entity\Order;
use Eccube\Entity\Payment;
use Eccube\Repository\DeliveryRepository;
use Eccube\Service\PurchaseFlow\ItemHolderValidator;
Expand Down Expand Up @@ -76,6 +77,13 @@ protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $co
if (empty($paymentIds)) {
$this->throwInvalidItemException('front.shopping.different_payment_methods');
}

if ($itemHolder instanceof Order) {
// 支払い方法が非表示の場合はエラー
if (false === $itemHolder->getPayment()->isVisible()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurozumi
一部の決済プラグインや特定の条件によってはgetPayment()がnullを返すことがありますので、getPaymentのnullチェックをお願いできればありがたいです。

$this->throwInvalidItemException('front.shopping.not_available_payment_method');
}
}
}

private function getDeliveries(SaleType $SaleType)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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\Tests\Service\PurchaseFlow\Processor;

use Eccube\Entity\Delivery;
use Eccube\Service\PurchaseFlow\Processor\PaymentValidator;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Tests\EccubeTestCase;

class PaymentValidatorTest extends EccubeTestCase
{
/**
* @var PaymentValidator
*/
private $validator;

/**
* @var $Order
*/
private $Order;

protected function setUp(): void
{
parent::setUp();

$deliveryRepository = $this->entityManager->getRepository(Delivery::class);
$this->validator = new PaymentValidator($deliveryRepository);

$Customer = $this->createCustomer();
$this->Order = $this->createOrder($Customer);
}

public function testInstance()
{
self::assertInstanceOf(PaymentValidator::class, $this->validator);
}

public function testValidatePaymentVisibleFalse()
{
$this->Order->getPayment()->setVisible(false);

$result = $this->validator->execute($this->Order, new PurchaseContext());

self::assertTrue($result->isError());
}
}